def page_order_front(self): log.info('清空购物车并添加花生到购物车') self.cart = PageCart(self.driver) self.cart.page_cart_click_cart_link() if self.cart.page_cart_if_empty(): pass else: print('清空购物车,并返回首页') self.cart.page_cart_clear_all() handle1 = self.driver.current_window_handle print('handle1的值是:', handle1) self.cart.page_cart_go_zhubao() while True: handles = self.driver.window_handles print('handles', handles) if len(handles) == 1: print('继续等待窗口完全打开') sleep(1) else: break for h in handles: if h != handle1: handle2 = h print('handle2的值是:', handle2) self.driver.switch_to.window(handle2) print('切换后handle的值是:', self.driver.current_window_handle) self.cart.page_cart_huasheng_commit() self.cart.page_cart_huasheng_go_to_cart() self.cart.page_cart_go_to_pay()
def setUp(self): # 获取driver self.driver = GetDriver.get_dirver() # 实例化 PageCart self.cart = PageCart(self.driver) # 调用成功登陆 依赖 PageBusinessLogin(self.driver).page_login_success()
def setUp(self): # 获取driver self.driver = GetDriver().get_driver() # 实例化 PageCart页面 self.cart = PageCart(self.driver) # 调用成功登录 依赖 PageLogin(self.driver).page_login_success() # 跳转到首页 self.cart.page_open_index()
def setUp(self): # 获取driver self.driver = GetDriver().get_driver() # 实例化PageLogin并调用登录方法 PageLogin(self.driver).page_login_success() # 获取PageCart对象 self.cart = PageCart(self.driver) # 回到首页 self.cart.base_click_index()
class TestCart(unittest.TestCase): # 初始化方法 def setUp(self): # 获取driver self.driver = GetDriver().get_driver() # 实例化PageLogin并调用登录方法 PageLogin(self.driver).page_login_success() # 获取PageCart对象 self.cart = PageCart(self.driver) # 回到首页 self.cart.base_click_index() # 结束方法 def tearDown(self): # 关闭driver GetDriver().quit_driver() # 购物测试方法 def test_cart(self, goods="小米手机", expect="添加成功"): try: # 调用 购物车组合业务方法 self.cart.page_cart(goods) # 断言 self.assertIn(expect, self.cart.page_get_success_info()) # 关闭 self.cart.page_close_window() except Exception as e: # 日志、截图 log.error(e) self.cart.base_get_image()
def setUpClass(cls) -> None: cls.driver = GetDriver().get_driver() # 调用登录成功方法 PageLogin(cls.driver).page_login_success() time.sleep(2) # 实例化购物车页面 cls.cart = PageCart(cls.driver)
def setup_class(cls): WinRM().run_bat_file() cls.driver = GetDriver.get_web_driver(page.URL) cls.cart = PageCart(cls.driver) cls.login = PageLogin(cls.driver) cls.login.page_login() cls.login.page_keep_return_FP()
def setUpClass(cls) -> None: cls.driver = GetDriver().get_driver('chrome') # 调用登录成功的方法 PageLogin(cls.driver).page_login_success() # 等待一会 time.sleep(3) # 实例化购物车页面 cls.cart = PageCart(cls.driver)
class TestCart(unittest.TestCase): # 定义 setup def setUp(self): # 获取driver self.driver = GetDriver().get_driver() # 实例化 PageCart页面 self.cart = PageCart(self.driver) # 调用成功登录 依赖 PageLogin(self.driver).page_login_success() # 跳转到首页 sleep(2) self.cart.page_open_index() # 定义 teardown def tearDown(self): # 关闭driver GetDriver().quit_driver() # 定义测试购物车方法 def test_add_cart(self): # 调用 组合添加购物车业务方法 self.cart.page_add_cart() # 断言是否添加成功 msg = self.cart.page_get_text() self.assertEqual(msg, "添加成功") # 关闭窗口 self.cart.page_close_window()
class TestCart(unittest.TestCase): # 定义setup def setUp(self): # 获取driver self.driver = GetDriver.get_dirver() # 实例化 PageCart self.cart = PageCart(self.driver) # 调用成功登陆 依赖 PageBusinessLogin(self.driver).page_login_success() # 跳转到首页 # self.cart.page_open_index() # 定义teardown def tearDown(self): # 关闭driver GetDriver().quit_driver() # 定义测试添加批次 def test_add_batch(self): batchName = time.strftime("%Y-%m-%d %H-%M-%S", time.localtime(time.time())) + 'WLT自动测试批次' total = random.randint(1, 5) # 调用 组合添加批次业务方法 self.cart.page_add_batch(batchName, total) time.sleep(1) msg = self.cart.page_batch_return_right_info() print(msg) try: assert_that(msg).is_equal_to('添加成功') print('test03测试通过') self.cart.base_get_info_image() except AssertionError as e: print('test03的报错信息为 %s' % e) self.cart.base_get_image() raise
def setUp(self): # 获取diver self.driver = GetDriver().get_driver() log.info("[TestCart]: 获取driver对象") # 获取PageCart对象 self.cart = PageCart(self.driver) log.info("[TestCart]: 获取购物车对象") # 获取PageLogin对象 self.login = PageLogin(self.driver) log.info("[TestCart]: 获取登录页面对象") # 点击登录连接 self.login.page_click_login_link() log.info("[TestCart]: 点击登录连接") # 登录 self.login.page_login_static() log.info("[TestCart]: 执行登录") sleep(3) # 回到首页 self.cart.base_get_index() log.info("[TestCart]: 回到首页")
class TestCart(unittest.TestCase): log.info("[TestCart]: 购物车用例开始执行") def setUp(self): # 获取diver self.driver = GetDriver().get_driver() log.info("[TestCart]: 获取driver对象") # 获取PageCart对象 self.cart = PageCart(self.driver) log.info("[TestCart]: 获取购物车对象") # 获取PageLogin对象 self.login = PageLogin(self.driver) log.info("[TestCart]: 获取登录页面对象") # 点击登录连接 self.login.page_click_login_link() log.info("[TestCart]: 点击登录连接") # 登录 self.login.page_login_static() log.info("[TestCart]: 执行登录") sleep(3) # 回到首页 self.cart.base_get_index() log.info("[TestCart]: 回到首页") def tearDown(self): # 关闭浏览器 GetDriver().quit_driver() log.info("[TestCart]: 关闭driver对象") def test_add_cart(self, key="小米手机", expect_result="添加成功"): try: # 调用添加购物车方法 self.cart.page_add_goods_cart(key) log.info("[TestCart]: 调用添加购物车操作方法") # 断言获取添加结果提示信息 result = self.cart.page_get_add_cart_info() log.info("[TestCart]: 添加购物车后提示信息:{}".format(result)) self.assertEqual(expect_result, result) # 回到默认页面 self.cart.base_default_frame() log.info("[TestCart]: 回到iframe默认页面") # 关闭提示信息框 self.cart.page_click_close_iframe() log.info("[TestCart]: 关闭提示添加成功后的信息框") except Exception as e: log.error(e)
def page_cart(self): return PageCart(self.driver)
def setUpClass(cls) -> None: logger.info("正在测试cart模块") cls.driver = GetDriver().get_driver() cls.login = PageLogin(cls.driver) cls.cart = PageCart(cls.driver)
def setUp(self) -> None: # 添加商品 PageCart(self.driver).page_add_cart('雪纺连衣裙') self.order.base_click_index()
def cart(self): return PageCart(self.driver)
class PageOrder(Base): def page_order_front(self): log.info('清空购物车并添加花生到购物车') self.cart = PageCart(self.driver) self.cart.page_cart_click_cart_link() if self.cart.page_cart_if_empty(): pass else: print('清空购物车,并返回首页') self.cart.page_cart_clear_all() handle1 = self.driver.current_window_handle print('handle1的值是:', handle1) self.cart.page_cart_go_zhubao() while True: handles = self.driver.window_handles print('handles', handles) if len(handles) == 1: print('继续等待窗口完全打开') sleep(1) else: break for h in handles: if h != handle1: handle2 = h print('handle2的值是:', handle2) self.driver.switch_to.window(handle2) print('切换后handle的值是:', self.driver.current_window_handle) self.cart.page_cart_huasheng_commit() self.cart.page_cart_huasheng_go_to_cart() self.cart.page_cart_go_to_pay() def page_order_click_submit_order(self): self.base_click_element(page.cart_order_btn) def page_order_if_submit_success(self): self.el = None try: self.el = self.base_find_element(page.order_pay_style) except Exception: print('生成订单失败') raise finally: if self.el: print('生成订单成功') return True else: return False def page_order_select_pay_style(self): self.base_click_element(page.order_pay_hdfk) self.base_click_element(page.order_pay_style) sleep(5) self.base_click_element(page.order_detail) def page_order_check_status(self): return self.base_get_text(page.order_status) def page_get_order_number(self): return self.base_get_text(page.order_number) def page_confirm_goods(self): self.base_click_element(page.order_confirm_goods) self.base_click_element(page.order_confirm_goods2) sleep(5) def page_order_ms_login(self, username='******', password='******', code='8888'): log.info(f'调用后台管理登录方法,用户名{username},密码{password},验证码{code}') self.base_input_text(page.ms_username, username) self.base_input_text(page.ms_password, password) self.base_input_text(page.ms_code, code) self.base_click_element(page.ms_login) def page_order_ms_go_to_order_list(self): self.base_click_element(page.ms_shop) sleep(3) self.base_click_element(page.ms_order) self.base_click_element(page.ms_order_list) sleep(5) def page_order_search_order_number(self, order_number): self.driver.switch_to.frame(self.base_find_element(page.ms_frame)) el = self.base_find_element(page.ms_search_key) Select(el).select_by_value(page.ms_search_key_order_number) self.base_input_text(page.ms_search, order_number) self.base_click_element(page.ms_search_btn) def page_order_get_order_statues(self): statues1 = self.base_get_text(page.ms_statues1) statues2 = self.base_get_text(page.ms_statues2) statues3 = self.base_get_text(page.ms_statues3) return statues1, statues2, statues3 def page_order_confirm(self, msg='订单已确认'): self.base_input_text(page.ms_input_note, msg) self.base_click_element(page.ms_confirm_btn) self.driver.switch_to.default_content() def page_order_go_express(self, msg='已经发货', num='123456789'): self.base_input_text(page.ms_input_note, msg) self.base_click_element(page.ms_express_btn) self.base_input_text(page.ms_input_express_num, num) self.base_click_element(page.ms_confirm_express_btn) self.driver.switch_to.default_content() def page_order_go_pay(self, msg='已经付款'): self.base_input_text(page.ms_input_note, msg) self.base_click_element(page.ms_pay) self.driver.switch_to.default_content() # 组合获取订单状态业务方法 def page_ms_statues(self, order_number): log.info("调用后台系统业务组合方法") sleep(3) self.page_order_ms_go_to_order_list() self.page_order_search_order_number(order_number) return self.page_order_get_order_statues() def page_ms_check(self): self.base_click_element(page.ms_check_order)