def before_func(self): DriverUtil.get_driver() # 获取驱动对象 self.factory = PageFactory() yield # 结束操作 time.sleep(3) DriverUtil.quit_driver() # 退出驱动对象
def setUpClass(cls) -> None: cls.driver = DriverUtil.get_driver() # 浏览器对象 cls.index_proxy = IndexProxy() # 首页业务执行对象 cls.my_cart_proxy = MyCartProxy() # 我的购物车业务执行对象 cls.order_check_proxy = OrderCheckProxy() # 订单确认业务执行对象 cls.order_list_proxy = OrderListProxy() # 订单列表业务执行对象 cls.order_pay_proxy = OrderPayProxy() # 订单支付业务执行对象
def setUpClass(cls) -> None: cls.driver = DriverUtil.get_driver() # 获取浏览器对象 cls.index_proxy = IndexProxy() # 首页业务执行对象 cls.goods_cart_proxy = GoodsCartProxy() # 购物车业务执行对象 cls.order_check_proxy = OrderCheckProxy() # 订单确认业务执行对象 cls.my_order_proxy = MyOrderProxy() # 我的订单业务执行对象 cls.order_pay_proxy = OrderPayProxy() # 订单支付业务执行对象
def setUpClass(cls): # 获取浏览器驱动对象 cls.driver = DriverUtil.get_driver() # 首页业务层对象 cls.index_proxy = IndexProxy() # 登录页业务层对象 cls.login_proxy = LoginProxy()
def setUpClass(cls): # 获取浏览器驱动对象 cls.driver = DriverUtil.get_driver() cls.indexproxy = IndexProxy() cls.goodssearchproxy = GoodsSearchProxy() cls.proxy = GoodsDetailProxy() cls.driver.get("http://localhost")
def setUpClass(cls): cls.driver = DriverUtil.get_driver() # 获取浏览器对象 cls.index_proxy = IndexProxy() # 首页页面业务执行对象 cls.login_proxy = LoginProxy() cls.search_list_proxy = SearchListProxy() # 搜索列表页面业务执行对象 cls.goods_detail_proxy = GoodsDetailProxy() # 商品详情页面业务执行对象 cls.my_count_proxy = MyCountProxy()
def __init__(self): super().__init__() self.driver = DriverUtil.get_driver() # 首页 self.home_button = (By.ID, "homepage") # 转文字/翻译 self.translate = (By.CLASS_NAME, 'menu-add') # 智能硬件 self.intelligent_hardware = (By.CLASS_NAME, "head-menu-hardware") # 会员/充值 self.membership_recharge = (By.ID, "czksc1") # 帮助中心 self.help_center = (By.CLASS_NAME, "head-menu-server") # 企业服务 self.enterprise_service = (By.CLASS_NAME, "head-menu-enterprise-server") # 下载客户端 self.download_client = (By.LINK_TEXT, "下载客户端") # 立即抢购弹窗关闭按钮 self.snap_the_popover_close_button = ( By.XPATH, "/ html / body / div[11] / div / span") # 用户协议确认按钮 self.user_agreement_confirmation_button = ( By.XPATH, "//*[@id='p-save']/font/font") # 关于我们 self.about_us = (By.LINK_TEXT, "关于我们")
def setUpClass(cls): # 浏览器驱动 cls.driver = DriverUtil.get_driver() cls.index_page = IndexProxy() cls.login_page = LoginProxy() logger.info("获取浏览器驱动对象:{}".format(cls.driver)) logger.info("获取页面对象:{}".format((cls.index_page, cls.login_page)))
def get_join_cart_result(self): """获取加入购物结果方法""" # 切换 frame driver = DriverUtil.get_driver() # 获取浏览器对象 # 注意: 切换 frame 操作也可以使用定位到的 iframe 元素对象 driver.switch_to.frame(driver.find_element_by_tag_name('iframe')) return self.goods_detail_page.find_join_cart_result().text
def setUpClass(cls) -> None: cls.driver = DriverUtil.get_driver() # 获取浏览器对象 cls.index_proxy = IndexProxy() # 首页业务操作对象 cls.cart_proxy = CartProxy() # 购物车业务操作对象 cls.my_order_proxy = MyOrderProxy() # 订单提交操作对象 cls.my_order_list_proxy = MyOrderListProxy() # 我的订单业务执行对象 cls.order_pay_proxy = OrderPayProxy() # 订单支付业务执行对象
def setUpClass(cls): # 初始化浏览器 cls.driver = DriverUtil.get_driver() cls.index_page = IndexProxy() cls.cart_page = CartProxy() cls.cart_order_page = CartOrderProxy() cls.order_list_page = OrderListProxy() cls.order_pay_page = OrderPayProxy()
def get_add_cart_result(self, expect): """获取添加购物车结果方法""" # 切换 frame 获取弹窗结果 driver = DriverUtil.get_driver() driver.switch_to.frame(driver.find_element_by_css_selector('iframe')) result = self.goods_detail_handle.get_join_cart_result() return expect == result
def setUpClass(cls): # 获取浏览器驱动对象 cls.driver = DriverUtil.get_driver() # 获取用例页面 cls.index_proxy = IndexProxy() cls.cart_proxy = CartProxy() cls.order_proxy = OrderProxy() cls.myorder_proxy = MyOrderProxy() cls.orderpay_proxy = OrderPayProxy()
def setUpClass(cls): # 获取浏览器驱动对象 cls.driver = DriverUtil.get_driver() # 首页的业务层对象 cls.index_proxy = IndexProxy() # 商品列表的业务层对象 cls.goods_search_proxy = GoodsSearchProxy() # 商品详情页的业务层对象 cls.goods_detail_proxy = GoodsDetailProxy()
def setUpClass(cls) -> None: cls.driver = DriverUtil.get_driver() cls.index_proxy = IndexProxy() # 首页 cls.login_proxy = LoginProxy() # 登录页面 cls.my_account_proxy = MyAccountProxy() # 我的账户 cls.cart_paroxy = CartProxy() # 购物车 cls.check_roder_proxy = CheckOrderProxy() # 核对订单 cls.payment_proxy = PaymentProxy() # 订单支付页面 cls.my_order_proxy = MyOrderProxy() # 我的订单 cls.payment_proxy = PaymentProxy() # 订单支付
def setUpClass(cls): cls.driver = DriverUtil.get_driver() # 获取浏览器对象 cls.index_proxy = IndexProxy() # 首页页面业务执行对象 cls.login_proxy = LoginProxy() cls.cart_proxy = CartProxy() # 购物车页面业务执行对象 cls.check_order_proxy = CheckOrderProxy() # 订单确认页面业务执行对象 cls.order_payment_proxy = OrderPaymentProxy() # 订单支付页面执行对象 cls.my_count_proxy = MyCountProxy() cls.my_order_proxy = MyOrderProxy() # 我的订单页面业务执行对象 cls.payment_success_proxy = PaymentSuccessProxy()
def get_join_cart_result(self): """获取添加购物车结果的方法""" # 切换 frame driver = DriverUtil.get_driver() # 注意: 除了可以使用能够代表唯一性的某一个属性的属性值及索引值以外, # 还可以直接获取 iframe 元素对象,完成 frame 的切换! driver.switch_to.frame(driver.find_element_by_css_selector('iframe')) return self.goods_detail_page.find_join_cart_result().text
def setUpClass(cls): # 获取浏览器驱动对象 cls.driver = DriverUtil.get_driver() # 页面对象 -- 业务层 首页 购物车 提交订单页 cls.index_proxy = IndexProxy() cls.cart_proxy = CartProxy() cls.order_submit_proxy = OrderSubmitProxy() cls.my_order_proxy = MyOrderProxy() cls.order_pay_proxy = OrderPayProxy()
def exist_text(text): """ 判断页面中是否存在指定的文本内容 :param text: 文本内容 :return: True:存在; False:不存在 """ try: xpath = "//*[contains(text(), '{}')]".format(text) element = DriverUtil.get_driver().find_element_by_xpath(xpath) return element is not None except Exception as e: print("current page_tpshop not contains [{}]".format(text)) logging.exception(e) return False
def test_write_note(self, title, content, toast): print("test_write_note title={} content={} toast={}".format( title, content, toast)) allure.attach( "用例参数:", "title={} content={} toast={}".format(title, content, toast)) # 进入‘写日记’页面 self.home_proxy.to_write_note_page() # 写日记 self.write_note_proxy.write_note(title, content) # 截图 png = DriverUtil.get_driver().get_screenshot_as_png() allure.attach("截图", png, allure.attach_type.PNG) assert utils.is_exist_toast(toast)
def setUpClass(cls) -> None: cls.driver = DriverUtil.get_driver() # 获取浏览器对象 cls.index_proxy = IndexProxy() # 首页页面业务执行对象 cls.search_list_proxy = SearchListProxy() # 搜索列表页面业务执行对象 cls.goods_detail_proxy = GoodsDetailProxy() # 商品详情页面业务执行对象
def __init__(self): self.driver = DriverUtil.get_driver()
def setUpClass(cls) -> None: cls.driver = DriverUtil.get_driver() cls.index_proxy = IndexProxy() # 首页业务层 cls.search_list_proxy = SearchListProxy() # 搜索列表业务层 cls.good_detail_proxy = GoodDetailProxy() # 商品详情页面业务层
def setUpClass(cls): cls.driver = DriverUtil.get_driver() # 获取浏览器对象 cls.good_detail_proxy = GoodsDeatilProxy() #获取商品详情页面业务执行对象 cls.search_list_proxy = SearchListProxy() # 获取搜索列表界面业务执行对象 cls.index_proxy = IndexProxy() # 获取首页页面业务执行对象
# 点击购物车 def click_join_cart(self): self.gdp.find_join_cart().click() # 业务层 class GoodsDetailProxy: # 操作层对象获取 def __init__(self): self.gdh = GoodsDetailHandle() # 加入购物车 def join_to_cart(self): self.gdh.click_join_cart() if __name__ == '__main__': # 打开浏览器 driver = DriverUtil.get_driver() # 打开商品详情业 driver.get("http://localhost/Home/Goods/goodsInfo/id/104.html") # 点击点击加入购物车 gdp = GoodsDetailProxy() gdp.join_to_cart() # 查看退出浏览器 time.sleep(5) DriverUtil.quit_driver()
def __init__(self): super().__init__() self.driver = DriverUtil.get_driver() self.home_page = HomePage()
def setUpClass(cls): cls.driver = DriverUtil.get_driver()
def base_find(self, loc): ele = self.driver.find_element(loc[0], loc[1]) ele = WebDriverWait( DriverUtil.get_driver(), 10, 0.5).until(lambda x: x.find_element(loc[0], loc[1])) return ele
def setUpClass(cls): cls.driver = DriverUtil.get_driver() cls.enterprise_service_proxy = EnterpriseServiceProxy() cls.home_proxy = HomeProxy()
def to_index_page(self): DriverUtil.get_driver().get(config.INDEX_URL)