51Testing软件测试论坛
标题:
请问一下运行 UI 自动化的时候,登陆之后的操作该怎么进行,登录之后,后面的操作...
[打印本页]
作者:
测试积点老人
时间:
2022-2-28 13:05
标题:
请问一下运行 UI 自动化的时候,登陆之后的操作该怎么进行,登录之后,后面的操作...
请问一下运行 UI 自动化的时候,登陆之后的操作该怎么进行,登录之后,后面的操作无法进行,是要重新打开浏览器吗
class WebKey(object):
def __init__(self, txt, timeout=30):
# 构造函数,创造必要的实例变量
if txt == 'gg':
self.driver = webdriver.Chrome()
self.driver.maximize_window()
self.driver.implicitly_wait(timeout)
elif txt == 'ff':
self.driver = webdriver.Firefox()
self.driver.maximize_window()
self.driver.implicitly_wait(timeout)
elif txt == 'ie':
self.driver = webdriver.Ie()
self.driver.maximize_window()
self.driver.implicitly_wait(timeout)
else:
print("浏览器暂不支持")
pass
def load_url(self, url=None):
"""
打开网站
:param url: 网站地址
:return:
"""
self.driver.get(url)
复制代码
# 登录业务
def login_busin(user, passwd):
br = WebKey()
br.open_br(br="gg")
br.open_url(URL)
br.sleep(tm=1)
br.send_key(section='LoginAccountElements', option='username', data=user)
br.send_key(section='LoginAccountElements', option='password', data=passwd)
picture_address = br.screenshot(os.path.join(img_address, str(int(time.time())) + ".png"))
text = read_image.ocr(picture_address)
br.send_key(section='LoginAccountElements', option='Verification', data=text)
br.click(section='LoginAccountElements', option='Login')
br.sleep(tm=1)
br.sleep(5)
# br.close()
if __name__ == '__main__':
pass
复制代码
# 添加业务
class add_actual_pop(WebKey):
def add_actual_population(self, name, phone, id_card):
self.click(section="HomePageElements", option="Basic_database")
self.click(section="Basic_database_main", option="add_Basic_population")
self.send_key(section="add_Basic_population_jump", option="name", data=name)
self.click(section="add_Basic_population_jump", option="date_birth")
self.send_key(section="add_Basic_population_jump", option="date_birth_input", data="2011-01-11")
pyautogui.typewrite(['enter'])
self.click(section="add_Basic_population_jump", option="Current_address")
self.send_key(section="add_Basic_population_jump", option="Current_address_search", data='舟山市岱山县驸马宫前西南约150米')
self.click(section="add_Basic_population_jump", option="Current_address_query")
self.click(section="add_Basic_population_jump", option="Current_address_click")
self.click(section="add_Basic_population_jump", option="Current_address_confirm")
self.click(section="add_Basic_population_jump", option="House_registration")
self.click(section="add_Basic_population_jump", option="House_registration_register")
self.click(section="add_Basic_population_jump", option="gender")
self.click(section="add_Basic_population_jump", option="male")
self.send_key(section="add_Basic_population_jump", option="phone_num", data=phone)
self.send_key(section="add_Basic_population_jump", option="id_card", data=id_card)
self.click(section="add_Basic_population_jump", option="entry_status")
self.click(section="add_Basic_population_jump", option="entry_status_atypism")
self.click(section="add_Basic_population_jump", option="confirm")
self.sleep(tm=10)
self.close()
if __name__ == '__main__':
pass
复制代码
# 用例
@pytest.fixture()
def test_login(): #登录用例
login_busin(user="ctz", passwd="admin123456?")
def test_add_actual_pop(test_login): # 添加用例
add_actual_pop().add_actual_population(name="原始人", phone="15255225552", id_card="420101199706214387")
if __name__ == '__main__':
pass
复制代码
作者:
qqq911
时间:
2022-3-1 10:06
要先调用登录,再执行业务
作者:
kallinr
时间:
2022-3-1 11:38
调用登陆,在执行业务
作者:
jingzizx
时间:
2022-3-1 14:51
打开浏览器,进行页面操作,进行抓取元素
欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/)
Powered by Discuz! X3.2