class TestLogin(unittest.TestCase): def setUp(self): # 打开谷歌浏览器,访问课堂派网址 warnings.simplefilter('ignore', ResourceWarning) self.driver = webdriver.Chrome() self.driver.maximize_window() self.driver.get(cd.login_url) self.lp = LoginPage(self.driver) pass def tearDown(self): # self 指的是实例名 # 退出浏览器会话 self.driver.quit() pass def test_01_login_success(self): # 登陆页面-输入用户名 # 登陆页面-输入密码 # 登陆页面-点击登陆按钮 self.lp.login(ld.normal_data["user"], ld.normal_data["passwd"]) # 断言 # 首页-获取元素,确认是否存在 self.assertTrue(IndexPage(self.driver).if_user_is_exist()) @ddt.data(*ld.incorrect_datas) def test_02_login_abnormal(self, data): self.lp.login(data["user"], data["passwd"]) self.assertEqual(data["check"], self.lp.get_error_msg())
def setUp(self): # 打开谷歌浏览器,访问课堂派网址 warnings.simplefilter('ignore', ResourceWarning) self.driver = webdriver.Chrome() self.driver.maximize_window() self.driver.get(cd.login_url) self.lp = LoginPage(self.driver) pass
def setUp(self) -> None: # #利用缓存跳过登录 # option=webdriver.ChromeOptions() # option.add_argument("--user-data-dir=C:\\Users\\Administrator\\AppData\\Local\\Google\\Chrome\\User Data") # self.driver = webdriver.Chrome(options=option) self.logger = Logger() self.driver=browser_type("chr") self.lp = LoginPage(self.driver, LoginPage.url) self.lp.login("13800138006", "123456", "1111") # 使用实例变量self才能调用别的方法内的属性 self.sp = SearchPage(self.driver, SearchPage.url)
def test_login_success(self): logger.info("************登录成功用例****************") lp = LoginPage(self.driver) lp.login(*LoginData.success_data) # 进行断言 try: self.assertTrue(HomePage(self.driver).get_quit_ele_exists()) logger.info("断言成功") except AssertionError as e: logger.exception("断言失败") raise e
def setup(self): # #利用缓存跳过登录 # option=webdriver.ChromeOptions() # option.add_argument("--user-data-dir=C:\\Users\\Administrator\\AppData\\Local\\Google\\Chrome\\User Data") # self.driver = webdriver.Chrome(options=option) self.logger = Logger() self.driver = browser_type("chr") self.driver.maximize_window() self.lp = LoginPage(self.driver, LoginPage.url) self.sp = SearchPage(self.driver, SearchPage.url) self.cp = OrderList(self.driver, OrderList.url) self.lp.login(13800138006, 123456, 1111)
def test_login_failed_layui(self, data_info): logger.info("*************登录失败场景2用例***************") lp = LoginPage(self.driver) lp.login(data_info["phone"], data_info["pwd"]) msg_text = lp.get_msg_from_login_layui() # 进行断言 try: self.assertEquals(msg_text, data_info["check"]) logger.info("断言成功") except AssertionError as e: logger.exception("断言失败") raise e
def init_loginEnv(): #启动浏览器静默模式 option = webdriver.ChromeOptions() option.add_argument('headless') driver = webdriver.Chrome(chrome_options=option) #driver=webdriver.Chrome() driver.get(login_url) #窗口最大化 driver.maximize_window() LoginP=LoginPage(driver) LoginP.wait_iframe_and_switch_to_it(LoginP.account_iframe,model_name='切换到登录iframe') #调用wait_windows_and_switch_to_it方法,切换窗口,# 在测试用例中调用BasePage里的方法,是由页面对象去调用,该页面对象继承了BasePage类 yield [driver,LoginP] driver.quit()
def test_login_failed_form(self, data_info): logger.info("*************登录失败场景1用例*************") # 进行登录操作 lp = LoginPage(self.driver) # 输入空的账号/密码/错误的手机号 lp.login(data_info["phone"], data_info["pwd"]) # 进行断言 try: self.assertEqual(lp.get_msg_from_login_form(), data_info["check"]) logger.info("断言成功") except AssertionError as e: logger.exception("断言失败") raise e
def setUpClass(cls): print("setUpClass") cls.driver = browser() cls.loginPage = LoginPage(cls.driver)
def init_login(init_driver): try: LoginPage(init_driver).login(*LoginData.success_data) except Exception as e: logger.info("登录前程贷失败") raise e yield init_driver
def as1(self): driver = webdriver.Chrome(service_log_path=r"D:\ChromeLog\log.log") driver.maximize_window() driver.get(cd.login_url) from PageObject.login_page import LoginPage LoginPage(driver).Login(ld.success_data['username'], ld.success_data['pwd'], ld.success_data['code']) return driver
def login_web(): global driver driver = webdriver.Chrome() driver.maximize_window() driver.get(CD.web_login_url) LoginPage(driver).login(LD.success_data["user"], LD.success_data["password"]) IndexPage(driver).click_invest_btn() yield driver driver.quit()
def setUpClass(cls) -> None: warnings.simplefilter('ignore', ResourceWarning) c = CourseOper(*cd.teacher_user) cls.course_id, cls.course_code = c.add_courser(cod.course_name, cod.course_name) cls.driver = webdriver.Chrome() cls.driver.maximize_window() cls.driver.get(cd.login_url) cls.lp = LoginPage(cls.driver) cls.lp.login(*cd.student_user)
def global_login(): global driver # 前置条件 driver = webdriver.Chrome(service_log_path=r"D:\ChromeLog\log.log") driver.maximize_window() driver.get(cd.login_url) LoginPage(driver).Login(ld.success_data['username'], ld.success_data['pwd'], ld.success_data['code']) yield driver # 分隔符 # 后置条件 driver.quit()
def test_add_success(self, prepara_env): LoginPage(prepara_env).Login(ld.success_data['username'], ld.success_data['pwd'], ld.success_data['code']) OrgManagemnet(prepara_env).loginPage() OrgManagemnet(prepara_env).new_org(pcnumber='BJ1234', pcname='日月天地警务室', areas='东城区', pltype='普通类型') text = OrgManagemnet(prepara_env).success_message() assert '添加成功!' == text
def setUpClass(cls): logging.info("======用例前置:初始化浏览器会话,登录前程贷系统======") cls.driver = webdriver.Chrome() cls.driver.maximize_window() cls.driver.get(CD.web_login_url) # LoginPage(cls.driver).login(LD.success_data["user"], LD.success_data["password"]) LoginPage(cls.driver).login(LD.success_data["user"], LD.success_data["password"]) # 调用首页的一个函数,实现从首页任意选择一个标,点击抢投标按钮 IndexPage(cls.driver).click_invest_btn() cls.bid_page = BidPage(cls.driver)
def alarm_conf(): global driver # 前置条件 driver = webdriver.Chrome(service_log_path=r"D:\ChromeLog\log.log") driver.maximize_window() driver.get(cd.login_url) LoginPage(driver).Login(ld.success_data['username'], ld.success_data['pwd'], ld.success_data['code']) MoreFunctionMenu(driver=driver).click_menu(locator=Menu.Alarm_menu) yield driver # 分隔符 # 后置条件 driver.quit()
class TestCase(unittest.TestCase): index = 1 def setUp(self) -> None: # #利用缓存跳过登录 # option=webdriver.ChromeOptions() # option.add_argument("--user-data-dir=C:\\Users\\Administrator\\AppData\\Local\\Google\\Chrome\\User Data") # self.driver = webdriver.Chrome(options=option) self.logger = Logger() self.driver=browser_type("chr") self.lp = LoginPage(self.driver, LoginPage.url) self.lp.login("13800138006", "123456", "1111") # 使用实例变量self才能调用别的方法内的属性 self.sp = SearchPage(self.driver, SearchPage.url) def tearDown(self) -> None: self.sp.quit_browser() # # 登录模块 # @data(*test_data) # @unpack # def test_1_login(self, **test_data): # username = test_data['username'] # password = test_data['password'] # vercode = test_data['vercode'] # self.lp.login(username, password, vercode) # sleep(5) # self.assertEqual(self.lp.get_username(), test_data["veridate"], msg="登录失败") # self.logger.log().info("第{0}个用例,参数username:{1},password:{2},vercode:{3}".format(TestCase.index, username, password, vercode)) # TestCase.index+=1 #搜索模块 @file_data('../config/data.yaml') def test_2_search(self, **kwargs): searchtext = kwargs['search']["text"] varidata = kwargs["varidata"] sleep(5) self.sp.search_shop(searchtext) self.assertEqual(self.sp.get_search_text(), varidata, msg="搜索失败") self.logger.log().info("搜索内容为{},验证内容为{},实际结果为{}".format(searchtext, varidata,self.sp.get_search_text()))
class TestCase: index = 1 def setup(self): # #利用缓存跳过登录 # option=webdriver.ChromeOptions() # option.add_argument("--user-data-dir=C:\\Users\\Administrator\\AppData\\Local\\Google\\Chrome\\User Data") # self.driver = webdriver.Chrome(options=option) self.logger = Logger() self.driver = browser_type("chr") self.driver.maximize_window() self.lp = LoginPage(self.driver, LoginPage.url) self.sp = SearchPage(self.driver, SearchPage.url) self.cp = OrderList(self.driver, OrderList.url) self.lp.login(13800138006, 123456, 1111) def teardown(self): self.driver.quit() #登录模块 @data(*test_data) @unpack def test_1_login(self, **test_data): username = test_data['username'] password = test_data['password'] vercode = test_data['vercode'] self.lp.login(username, password, vercode) sleep(3) self.logger.log().info( "第{0}个用例,参数username:{1},password:{2},vercode:{3}".format( TestCase.index, username, password, vercode)) TestCase.index += 1 assert self.lp.assert_text() == test_data["veridate"] #搜索模块 @file_data('../config/search.yaml') def test_2_search(self, **kwargs): self.lp.login("13800138006", "123456", "1111") # 使用实例变量self才能调用别的方法内的属性 searchtext = kwargs["text"] varidata = kwargs["varidata"] sleep(3) self.sp.search_shop(searchtext) self.logger.log().info("搜索内容为{},验证内容为{},实际结果为{}".format( searchtext, varidata, self.sp.assert_text())) assert self.sp.assert_text() == varidata #订单号查询 @pytest.mark.parametrize("order, expect", excel_data2) def test_03_check(self, order, expect): self.cp.check_shop(order) assert expect == self.cp.assert_text()
class LoginTest(unittest.TestCase): def setUp(self): self.driver = brower("chrome") self.driver.maximize_window() time.sleep(2) self.p = LoginPage(self.driver) @ddt.data(*test_err) def test_login(self, data): log.info( u"--------------------登录用例-------------------------------------------" ) self.p.login_action(data['username'], data['password']) try: self.assertEqual(self.p.login_asser(data['method'], data['loc']), data['result']) log.info(u"用例:test_login---NO.:%s ,断言通过" % (data['NO.'])) except Exception as e: log.info(u"用例:test_login---NO.:%s ,断言失败的原因:%s" % (data['NO.'], e)) func.getscreen(self.driver) def tearDown(self): self.driver.quit()
def setUpClass(cls) -> None: # 老师通过接口创建课程 warnings.simplefilter('ignore', ResourceWarning) c = CourseOper(*cd.teacher_user) cls.course_id, cls.course_code = c.add_courser(cod.course_name, cod.course_name) cls.driver = webdriver.Chrome() cls.driver.maximize_window() cls.driver.get(cd.login_url) # 学生登录系统 cls.lp = LoginPage(cls.driver) cls.lp.login(*cd.student_user) # 学生添加课程 cls.ip = IndexPage(cls.driver) cls.ip.add_in_course(cls.course_code) # 学生进入课程 cls.ip.enter_in_class(cls.course_id)
def init_loginedEnv(): #启动浏览器静默模式 option = webdriver.ChromeOptions() option.add_argument('headless') driver = webdriver.Chrome(chrome_options=option) #driver=webdriver.Chrome() driver.get(login_url) #窗口最大化 driver.maximize_window() LoginP=LoginPage(driver) LoginP.wait_iframe_and_switch_to_it(LoginP.account_iframe) LoginP.login(login_data['username'],login_data['passwd']) yield driver driver.quit()
def setUp(self): self.driver = driver self.loginPage = LoginPage(self.driver)
def test_login_success(self, prepara_env): LoginPage(prepara_env).Login(ld.success_data['username'], ld.success_data['pwd'], ld.success_data['code']) assert (IndexPage(prepara_env).isExist_quitEle())
def test_login_2_success(self): LoginPage(self.driver).login(ld.success_data["user"], ld.success_data["password"]) self.assertTrue(IndexPage(self.driver).check_nick_name_exists()) # url跳转,比对当前的url结果和实际结果 self.assertEqual(self.driver.current_url, ld.success_data["check"])
def test_login_1_failed_by_fail_datas(self, data): LoginPage(self.driver).login(data["user"], data["password"]) self.assertEqual( data["check"], LoginPage(self.driver).get_error_msg_from_pageCenter())
def test_login_0_failed_by_wrong_datas(self, data): # 手机号为空 LoginPage(self.driver).login(data["user"], data["password"]) self.assertEqual(data["check"], LoginPage(self.driver).get_error_msg_from_loginForm())
def click_searchbt(self): self.loc(self.searchbt).click() def assert_text(self): return self.loc(self.searchtext).text def search_shop(self,searchtext): self.input_search(searchtext) self.click_searchbt() sleep(1) if __name__ == '__main__': #同一个driver完整执行登录后搜索流程 searchtext = "华为" username = 13800138006 password = 123456 vercode = 1111 driver = webdriver.Chrome() lp = LoginPage(driver,LoginPage.url) lp.login(username, password, vercode) sp = SearchPage(driver,SearchPage.url) sleep(2) sp.input_search(searchtext)
def setUp(self): self.driver = brower("chrome") self.driver.maximize_window() time.sleep(2) self.p = LoginPage(self.driver)
class LoginTest(unittest.TestCase): u'''登录测试的case''' # @classmethod # def setUpClass(cls): # # print("setUpClass") # cls.driver = browser() # cls.loginPage = LoginPage(cls.driver) # cls.loginPage.open(login_url,title=u"用户登录 - 博客园") # @classmethod # def tearDownClass(cls): # cls.driver.quit() # print("tearDownClass") global driver driver = browser() def setUp(self): self.driver = driver self.loginPage = LoginPage(self.driver) def tearDown(self): self.driver.quit() def login_case(self, username, password): self.loginPage.open(login_url, title=u"用户登录 - 博客园") self.loginPage.type_username(username) self.loginPage.type_password(password) self.loginPage.click_submit() # self.loginPage.login(username,password) @Screen(driver) def test_login_001(self): '''sucess''' self.login_case('sieyc', 'Yangchao@520') result = self.loginPage.is_text_in_element(("id", "lnk_current_user1"), u"老杨-tester") self.assertTrue(result) self.loginPage.click_loginOut() self.loginPage.click_accept()