class Login(unittest.TestCase): @classmethod def setUpClass(cls): cls.driver = webdriver.Chrome('Conf/chromedriver.exe') @classmethod def tearDownClass(cls): cls.driver.quit() def add_img(self): self.imgs.append(self.driver.get_screenshot_as_base64()) return True def setUp(self): self.driver.implicitly_wait(2) self.driver.maximize_window() # 在是python3.x 中,如果在这里初始化driver ,因为3.x版本 unittest 运行机制不同,会导致用力失败时截图失败 self.imgs = [] self.addCleanup(self.cleanup) def cleanup(self): pass #------------------------------------------------------------------------- @data(*Read_csv.get_data(r'Data\\login_test.csv')) @unpack def test_login(self, code, name, pwd): login.login_test(self, self.driver, code, name, pwd) def test_login_01(self): data = Read_csv.get_data(r'Data\\login_test.csv') print(data[0][0]) login.login_test(self, self.driver, data[0][0], data[0][1], data[0][2]) #跳过测试用例 @unittest.skip('跳过') def test_login02(self): login.login_test(self, self.driver, "hjhy ", "lizhenghong", "111111")
class Login(unittest.TestCase): def add_img(self): self.imgs.append(self.driver.get_screenshot_as_base64()) return True def setUp(self): info_url = "E://auto_data/test.csv" info_data = input_csv.input_data(info_url) #读取文件中保存的网页信息 info = info_data[0] executor_url = info[0] session_id = info[1] # 使用ReuseChrome()复用上次的session self.driver = ReuseChrome(command_executor=executor_url, session_id=session_id) self.imgs = [] self.addCleanup(self.cleanup) def cleanup(self): pass @data(*Read_csv.get_data( 'D:\\idea-workspace\\untitled\\Data\\login_test.csv')) @unpack def test_login(self, code, name, pwd): company_code = self.driver.find_element_by_id('j_companyCode') company_code.clear() company_code.send_keys(code) username = self.driver.find_element_by_id('j_username') username.clear() username.send_keys(name) password = self.driver.find_element_by_id('j_password') password.clear() password.send_keys(pwd) self.driver.find_element_by_xpath('//button[text()="登录"]').click() time.sleep(2) try: actual = self.driver.find_element_by_xpath( '//*[@id="show-shortcut"]/span') except: print("无法找到元素,可能原因:登录失败,页面为跳转") finally: self.assertEqual(actual.text, name.capitalize()) self.driver.find_element_by_xpath('//a[@title="登出"]').click() time.sleep(1) self.driver.find_element_by_xpath('//button[@id="bot2-Msg1"]').click() time.sleep(1)
def test_login_01(self): data = Read_csv.get_data( 'D:\\idea-workspace\\PythonTest\\DemoTest\\Data\\login_test.csv') print(data[0][0]) login.login_test(self, self.driver, data[0][0], data[0][1], data[0][2])
def test_login_01(self): data = Read_csv.get_data(r'Data\\login_test.csv') print(data[0][0]) login.login_test(self, self.driver, data[0][0], data[0][1], data[0][2])
def test_search_01(self): data = Read_csv.get_data('D:\Idea_coad\Demo_Test\Data\login_test.csv') print(data[0][0]) login.login_test(self, self.driver, "C0006", "lvliwen", "111111") test_agent_user_search.test_agent_user_search(self, self.driver)
class Login(unittest.TestCase): @classmethod def setUpClass(cls): cls.driver = webdriver.Chrome() @classmethod def tearDownClass(cls): cls.driver.quit() def add_img(self): self.imgs.append(self.driver.get_screenshot_as_base64()) return True def setUp(self): self.driver.implicitly_wait(2) self.driver.maximize_window() self.driver.get("https://tkzhushou.mylianzhi.com/eldf-sso/login.htm") # 在是python3.x 中,如果在这里初始化driver ,因为3.x版本 unittest 运行机制不同,会导致用力失败时截图失败 self.imgs = [] self.addCleanup(self.cleanup) def cleanup(self): pass @data(*Read_csv.get_data( 'D:\\idea-workspace\\PythonTest\\DemoTest\\Data\\login_test.csv')) @unpack def test_login(self, code, name, pwd): company_code = self.driver.find_element_by_id('j_companyCode') company_code.clear() company_code.send_keys(code) username = self.driver.find_element_by_id('j_username') username.clear() username.send_keys(name) password = self.driver.find_element_by_id('j_password') password.clear() password.send_keys(pwd) self.driver.find_element_by_xpath('//button[text()="登录"]').click() time.sleep(2) try: actual = self.driver.find_element_by_xpath( '//*[@id="show-shortcut"]/span') except: print("无法找到元素,可能原因:登录失败,页面为跳转") finally: self.assertEqual(actual.text, name.capitalize()) @unittest.skip('跳过') def test_login01(self): company_code = self.driver.find_element_by_id('j_companyCode') company_code.clear() company_code.send_keys(" ") username = self.driver.find_element_by_id('j_username') username.clear() username.send_keys(" ") password = self.driver.find_element_by_id('j_password') password.clear() password.send_keys(" ") self.driver.find_element_by_xpath('//button[text()="登录"]').click() time.sleep(2) try: actual = self.driver.find_element_by_xpath( '//*[@id="show-shortcut"]/span') except: print("无法找到元素,可能原因:登录失败,页面为跳转") finally: self.assertEqual(actual.text, " ")
def test_search_01(self): data = Read_csv.get_data( 'D:\\idea-workspace\\PythonTest\\DemoTest\\Data\\login_test.csv') print(data[0][0]) login.login_test(self, self.driver, "C0006", "lvliwen", "111111") test_agent_user_search.test_agent_user_search(self, self.driver)