class LoginHandle: def __init__(self, driver, i): self.login_page = LoginPage(driver, i) self.index_page = IndexPage(driver, i) def click_traggle_button(self): # 首页侧边栏 self.index_page.get_traggle_button().click() def click_avatar_button(self): """ 点击头像 """ self.index_page.get_avatar_button().click() def click_login(self): """ 点击登录按钮 """ self.login_page.get_login_button_element().click() def send_token_val(self): """ 输入token """ # self.login_page.get_token_element().send_keys(token) time.sleep(5) print("element", self.login_page.get_token_element()) self.login_page.get_token_element().send_keys('abcdef')
class LoginHandle: def __init__(self, driver): self.login_page = LoginPage(driver) self.index_page = IndexPage(driver) def click_traggle_button(self): # 首页侧边栏 self.index_page.get_traggle_button().click() def click_avatar_button(self): """ 点击头像 """ self.index_page.get_avatar_button().click() def click_login(self): """ 点击登录按钮 """ self.login_page.get_login_button_element().click() def send_token_val(self): """ 输入token """ self.login_page.get_token_element()
def setup(self): self.driver = DriverUtils.get_driver() DriverUtils.set_switch(True) self.index_page = IndexPage(self.driver) self.goods_search_page = GoodsSearchPage(self.driver) self.goods_detail_page = GoodsDetailPage(self.driver) self.driver.get("http://localhost/")
class TestLogin: def setup(self): self.driver = DriverUtils.get_driver() DriverUtils.set_switch(True) self.index_page = IndexPage(self.driver) self.login_page = LoginPage(self.driver) self.driver.get("http://localhost/") def teardown(self): time.sleep(3) DriverUtils.quit_driver() @pytest.mark.parametrize("params", analyze_data("login_data.json")) def test_login(self, params): self.index_page.click_login_link() logging.info("login with {}--{}--{}".format(params["username"], params["password"], params["code"])) self.login_page.input_username(params["username"]) self.login_page.input_password(params["password"]) self.login_page.input_verify_code(params["code"]) self.login_page.click_login_btn() # 登录成功需要时间, 暂停几秒等页面跳转 logging.info("wait 5s for page display") time.sleep(5) assert params["msg"] in self.driver.title
def checkindex(self): self.index_page = IndexPage(self.driver) try: self.index_page.get_lowbannerstudy_element() return True except: return False
def jiekeyuwenselect(self): sleep(2) self.login_down = LoginDown(self.driver) self.login_down.unloginloginfirst() sleep(3) print('执行滑动屏幕开始') self.swipe = Swipe(self.driver) self.swipe.swipe_up() print('执行滑动屏幕结束') sleep(1) self.index_handle = IndexHandle(self.driver) self.index_handle.click_coursereadstatus() sleep(1) self.index_handle.click_jiekestatus() sleep(1) self.index_handle.click_coursesubject() sleep(1) self.index_handle.click_subject() sleep(1) self.index_page = IndexPage(self.driver) try: self.index_page.get_course_element() return True except: return False
class ClassdetailBusiness: def __init__(self, driver): self.driver = driver def getcourseelement(self): try: self.index_page = IndexPage(self.driver) sleep(3) self.index_page.get_course_element() print('查询到课程') return True except: print('未查询到课程') return False def classdetailselect(self): if self.getcourseelement(): self.index_handle = IndexHandle(self.driver) self.index_handle.click_course() print('执行完成点击课程') sleep(2) self.classdaylist_page = ClassdaylistPage(self.driver) #elements = self.classdaylist_page.get_classdayviewgroup_elements() classdaystatus = self.classdaylist_page.get_coursedaystatus_elements( )[0].text #if len(elements) == 11 and classdaystatus == "已下课": if classdaystatus == "已下课": return True else: return False
class TestLogin: def setup(self): # 浏览器驱动对象获取 self.driver = DriverUtil.get_driver() self.login_page = LoginPage(self.driver) self.index_page = IndexPage(self.driver) self.driver.get("http://192.168.2.133/") def teardown(self): # 浏览器驱动对象关闭 time.sleep(3) DriverUtil.close_driver() @pytest.mark.parametrize("params", analyze("login_data")) def test_login(self, params): self.index_page.click_login_link() self.login_page.input_username(params["username"]) self.login_page.input_password(params["password"]) self.login_page.input_verify_code(params["code"]) self.login_page.click_login_btn() logging.info("登录, 用户名为{}, 密码是{}, 验证码是{}".format( params["username"], params["password"], params["code"])) time.sleep(2) self.login_page.screen_shot("{}.png".format( self.login_page.get_error_msg())) assert params["msg"] == self.login_page.get_error_msg()
class CheckenterIndex: def __init__(self, driver): self.driver = driver #检查是否登录成功 def checkindex(self): self.index_page = IndexPage(self.driver) try: self.index_page.get_lowbannerstudy_element() return True except: return False def checkshengji(self): self.shengji_page = ShengjiPage(self.driver) try: self.shengji_page.get_update_element() return True except: return False def checkenterindex(self): if self.checkindex() is True: return True elif self.checkshengji() is True: self.shengji_handle = ShengjiHandle(self.driver) self.shengji_handle.click_cancel() return True else: return False
def setup(self): self.driver = DriverUtils.get_driver() DriverUtils.set_switch(True) self.index_page = IndexPage(self.driver) self.cart_page = CartPage(self.driver) self.order_page = OrderPage(self.driver) self.order_pay_page = OrderPayPage(self.driver) self.home_page = HomePage(self.driver) self.driver.get("http://localhost/")
def getcourseelement(self): try: self.index_page = IndexPage(self.driver) sleep(3) self.index_page.get_course_element() print('查询到课程') return True except: print('未查询到课程') return False
def setup(self): self.driver = webdriver.Chrome() self.Login_Page = LoginPage(driver=self.driver) self.Index_Page = IndexPage(driver=self.driver) self.driver.maximize_window() self.Login_Page.get(self.url + "login") pass
def login_case_fixture(): '''测试用例前置后置条件''' driver = webdriver.Chrome() login_page = LoginPage(driver) index_page = IndexPage(driver) yield login_page, index_page driver.quit()
def login_fixture(): # opt = webdriver.ChromeOptions() # opt.add_argument('--headless') # driver = webdriver.Chrome(options=opt) driver = webdriver.Chrome() driver.maximize_window() login_page = LoginPage(driver) index_page = IndexPage(driver) yield login_page, index_page driver.quit()
def invest_fixture(): # opt = webdriver.ChromeOptions() # opt.add_argument('--headless') # driver = webdriver.Chrome(options=opt) driver = webdriver.Chrome() driver.maximize_window() driver.implicitly_wait(30) login_page = LoginPage(driver) # 登录首页 login_page.login(conf.get('test_data', 'username'), conf.get('test_data', 'password')) index_page = IndexPage(driver) # 首页点击抢投标 index_page.click_element(index_loc.bid_btn_ele, '点击抢投标') invest_page = InvestPage(driver) # 滚动窗口到投资金额输入框 invest_page.window_move_amount_inout() user_page = UserInfo(driver) yield invest_page, user_page driver.quit()
class TestCart: def setup(self): self.driver = DriverUtils.get_driver() DriverUtils.set_switch(True) self.index_page = IndexPage(self.driver) self.goods_search_page = GoodsSearchPage(self.driver) self.goods_detail_page = GoodsDetailPage(self.driver) self.driver.get("http://localhost/") def teardown(self): time.sleep(3) DriverUtils.quit_driver() def test_cart(self): self.index_page.input_keywords("小米手机5") self.index_page.click_search_btn() logging.info("search with 小米手机5") self.goods_search_page.click_add_to_cart_btn() self.goods_detail_page.click_add_to_cart_btn() time.sleep(5) logging.info("wait 5s for page display") assert "添加成功" == self.goods_detail_page.get_result()
class TestLogin: def setup(self): self.driver = DriverUtil.get_driver() self.login_page = LoginPage(self.driver) self.index_page = IndexPage(self.driver) self.driver.get("http://localhost") def teardown(self): time.sleep(3) DriverUtil.quit_driver() @pytest.mark.parametrize("params", analyse("login_data.json")) def test_login(self, params): self.index_page.click_login_link() self.login_page.input_username(params["username"]) self.login_page.input_password(params["password"]) self.login_page.input_verify_code(params["code"]) self.login_page.click_login_btn() time.sleep(3) logging.info("用户名: {}---密码: {}---验证码: {}---预期结果: {}".format( params["username"], params["password"], params["code"], params["msg"])) assert params["msg"] == self.login_page.get_msg()
def setup_class(self): self.driver = webdriver.Chrome() self.Login_Page = LoginPage(self.driver) self.Index_Page = IndexPage(self.driver) self.driver.maximize_window() self.Login_Page.get(self.url + r"login") self.Login_Page.user_input = "test" self.Login_Page.password_input = "123456zxA" self.Login_Page.login_button.click() sleep(self.sleep_time) self.Login_Page.select_hospital.click() self.Login_Page.select_ensure.click() sleep(self.sleep_time) pass
class TestLogin: def setup(self): # 浏览器驱动对象获取 self.driver = DriverUtil.get_driver() self.login_page = LoginPage(self.driver) self.index_page = IndexPage(self.driver) self.driver.get("http://192.168.2.133/") def teardown(self): # 浏览器驱动对象关闭 time.sleep(3) DriverUtil.close_driver() @pytest.mark.parametrize("params", [{"username": "******", "password": "******", "code": "8888", "msg": "账号不存在!"}, {"username": "******", "password": "******", "code": "8888", "msg": "密码错误!"}]) def test_login(self, params): self.index_page.click_login_link() self.login_page.input_username(params["username"]) self.login_page.input_password(params["password"]) self.login_page.input_verify_code(params["code"]) self.login_page.click_login_btn() time.sleep(2) assert params["msg"] == self.login_page.get_error_msg()
class IndexHandle(object): def __init__(self, driver): self.index_page = IndexPage(driver) def click_ptsw(self): self.index_page.send_keys_index_element("ptsw_button", Keys.ENTER) def click_lwycl(self): self.index_page.click_index_element("lwycl_button") def click_cgx(self): self.index_page.click_index_element("cgx_button") def get_ele(self, ele): return self.index_page.get_index_element(ele)
def test_shopping_success(self): tel = '13981401921' password = '******' indexPage = IndexPage(self.driver) indexPage.open("http://172.18.0.50:9003/") sleep(3) indexPage.mine_button() #点击我的 minePage = MinePage(self.driver) minePage.login_button() loginPage = LoginPage(self.driver) loginPage.tel_input(tel) loginPage.pwd_input(password) loginPage.submit_button() sleep(3)
class TestOrder: def setup(self): self.driver = DriverUtils.get_driver() DriverUtils.set_switch(True) self.index_page = IndexPage(self.driver) self.cart_page = CartPage(self.driver) self.order_page = OrderPage(self.driver) self.order_pay_page = OrderPayPage(self.driver) self.home_page = HomePage(self.driver) self.driver.get("http://localhost/") def teardown(self): time.sleep(3) DriverUtils.quit_driver() # 运行于类的结束, 而不是测试方法的结束, 执行完全部测试脚本后, 关闭浏览器驱动 def teardown_class(self): DriverUtils.set_switch(False) DriverUtils.get_driver().get_screenshot_as_file("./screenshot/tpshop.png") DriverUtils.quit_driver() def test_submit_order(self): self.index_page.click_my_cart_link() self.cart_page.click_go_to_pay_btn() # 地址信息加载慢, 等一会 time.sleep(8) self.order_page.click_submit_btn() # 支付页面跳转慢, 也等一会 time.sleep(5) assert "订单提交成功,请您尽快付款!" == self.order_pay_page.get_tips_info() def test_pay(self): self.index_page.click_my_order_link() # 打开新窗口, 需要切换窗口 self.index_page.switch_window() # 使用其他page对象调用 switch_window() 方法也是可以的 self.home_page.click_to_be_pay_link() self.home_page.click_pay_btn() # 又打开了新窗口 self.home_page.switch_window() self.order_pay_page.click_arrived_pay() self.order_pay_page.click_pay_btn() # 等待支付结果 time.sleep(5) assert "订单提交成功,我们将在第一时间给你发货!" == self.order_pay_page.get_tips_info()
def index_page(self): return IndexPage(self.driver)
def index_page(self): # 2. 对应页面的文件名定义方法名 """设置首页""" return IndexPage(self.driver) # 3. 直接返回页面实例化的对象
def setup(self): # 浏览器驱动对象获取 self.driver = DriverUtil.get_driver() self.login_page = LoginPage(self.driver) self.index_page = IndexPage(self.driver) self.driver.get("http://192.168.2.133/")
def setup(self): self.driver = DriverUtil.get_driver() self.login_page = LoginPage(self.driver) self.index_page = IndexPage(self.driver) self.driver.get("http://localhost")
class IndexHandle: def __init__(self, driver): self.index_page = IndexPage(driver) # 操作底栏我的元素 def click_lowerbannerme(self): ''' 点击低栏我的 ''' self.index_page.get_lowbannerme_element().click() def click_coursereadstatus(self): ''' 点击在读状态 ''' self.index_page.get_coursereadstatus_element().click() def click_coursesubject(self): ''' 点击科目选项 ''' self.index_page.get_coursesubject_element().click() def click_coursereadstatus(self): ''' 点击在读状态选择框 ''' self.index_page.get_coursereadstatus_element().click() def click_coursesubject(self): ''' 点击科目选择框 ''' self.index_page.get_coursesubject_element().click() def click_jiekestatus(self): ''' 选择已结课 ''' self.index_page.get_jiekestatus_element().click() def click_subject(self): ''' 选择语文科目 ''' self.index_page.get_subject_element()[2].click() def click_course(self): ''' 点击课程1 ''' self.index_page.get_course_element()[0].click() def click_course1(self): ''' 点击课程3 ''' self.index_page.get_course1_element()[2].click()
def __init__(self, driver): self.index_page = IndexPage(driver)
def index_page(self): """首页页面""" return IndexPage(self.driver)
def index_page(self): # 2. 根据页面文件名写方法名 """首页页面""" return IndexPage(self.driver) # 3. 在方法内直接返回页面对象的实例化操作