def test_minus_function(driver): first_arg = 10 second_arg = 2 index_page = IndexPage(driver) index_page.calculate_minus(str(first_arg), str(second_arg)) assert index_page.minus_result.text == str(first_arg - second_arg)
def invest_fixture(): """投资用例的前置条件""" driver = create_driver() # 最大化窗口 driver.maximize_window() # 设置隐式等待 driver.implicitly_wait(15) # 实例登录页面对象 login_page = LoginPage(driver) # 打开登录页面 login_page.open_login_page() # 进行登录 login_page.login(mobile_phone=conf.get('test_data', 'mobile'), pwd=conf.get('test_data', 'pwd')) # 实例首页对象 index_page = IndexPage(driver) # 首页点击投资 index_page.click_invest() # 实例投资页面对象 invest_page = InvestPage(driver) # 实例用户页面对象 user_page = UserPage(driver) yield invest_page, user_page driver.quit()
def test_check_sum_function(driver, logger): first_arg = 1 second_arg = 2 index_page = IndexPage(driver) print index_page.sum_button print index_page.sum_button.text logger.info("输入两个加数 %d 和 %d, 并点击求和按钮" % (first_arg, second_arg)) index_page.caculate_sum(str(first_arg), str(second_arg)) logger.info("获取求和结果, 检查结果是否为 %d" % (first_arg + second_arg)) assert index_page.sum_button print index_page.sum_button assert index_page.sum_result_label.text == str(first_arg + second_arg) # def test_check_sum_function_should_fail(driver, logger): # first_arg = 1 # second_arg = 2 # # # find elements # index_page = IndexPage(driver) # logger.info("输入两个加数 %d 和 %d, 并点击求和按钮" % (first_arg, second_arg)) # index_page.caculate_sum(str(first_arg), str(second_arg)) # logger.info("获取求和结果, 检查结果是否为 %d" % (first_arg + second_arg)) # index_page.caculate_sum(str(first_arg), str(second_arg)) # assert index_page.sum_result_label.text == str(first_arg + second_arg + 1)
class TestBid(unittest.TestCase): def setUp(self) -> None: """ 前置条件: 1, 登录 :return: """ self.driver = webdriver.Chrome() self.driver.implicitly_wait(20) # 初始化页面 self.login_page = LoginPage(self.driver) self.index_page = IndexPage(self.driver) # 登录 login_data = login_data_success[0] self.login_page.login(login_data['mobile'], login_data['pwd']) def tearDown(self) -> None: pass def test_bid_error(self): "测试投资失败" time.sleep(1) self.index_page.get() # 如果不等待新页面出现而直接定位元素,可能找到的是上一个页面当中的元素。 self.index_page.get_element_bid().click() print('hello')
def setUp(self) -> None: # 1, 打开浏览器; self.driver = webdriver.Chrome() # 设置隐式等待 self.driver.implicitly_wait(20) # 初始化要用到的页面 self.login_page = LoginPage(self.driver) self.index_page = IndexPage(self.driver)
def language_test(self): self.login_page = LoginPage(self.driver) self.login_page.login(user_name="QA_traininguser13", password="******") self.index_page = IndexPage(self.driver) self.index_page.switch_language(language="Japanese") self.index_page.switch_language(language="English") time.sleep(10)
def login(): index_page = IndexPage(driver) index_page.click_login_button() login_page = LoginPage(driver) login_page.login(correct_userInfo["account"], correct_userInfo["pwd"]) # 截至目前进入 main_page yield driver driver.close()
class FirstRequestTest(unittest.TestCase): def setUp(self): self.browser = Browser() self.driver = self.browser.start() self.tenth_request_page = IndexPage( self.driver).open_tenth_request_page() self.tenth_request_page.reset_data() def test_scroll_page(self): self.tenth_request_page.scroll_page()
def test_add_course_down_error(self, code): """测试加入课程失败:{}""" """ 1.进入首页 2.点击加入课程按钮 3.输入课程码 4.点击加入 """ IndexPage(self.driver).add_course_down(code['course_code']) actual = IndexPage(self.driver).get_toast().text self.assertEqual(actual, code['expected'])
class TestLogin(unittest.TestCase): def setUp(self) -> None: # 1, 打开浏览器; self.driver = webdriver.Chrome() # 设置隐式等待 self.driver.implicitly_wait(20) # 初始化要用到的页面 self.login_page = LoginPage(self.driver) self.index_page = IndexPage(self.driver) def tearDown(self) -> None: self.driver.quit() # @ddt.data(*login_data_error) # def test_login_error(self, test_info): # """手机号码为空""" # # 第一个:获取实际结果(封装以后执行的函数或者方法) res = request.visit() # self.login_page.login(test_info['mobile'], test_info['pwd']) # actual = self.login_page.get_error_msg() # # 第二个:获取预期结果 test_info【‘expected’】 # expected = test_info['expected'] # # 第三个:断言 # self.assertEqual(expected, actual) # 获取没有通过授权 # @ddt.data(*login_data_invalid) # def test_login_invalid(self, test_info): # # 登录 # self.login_page.login(test_info['mobile'], test_info['pwd']) # # 获取没有通过授权的实际结果 # actual = self.login_page.get_invalid_msg() # expected = test_info['expected'] # self.assertEqual(expected, actual) # 讲登录成功 @ddt.data(*login_data_success) def test_login_success(self, test_info): """登录成功""" # 执行登录操作, login_page.login() self.login_page.login(test_info['mobile'], test_info['pwd']) # 进入了??页面 我的帐户[python] # 定位我的账户 # 等待窗口被打开 time.sleep(1) self.index_page.get() actual = self.index_page.get_element_user() # 预期结果 expected = test_info['expected'] self.assertIn(expected, actual.text)
def test_order_submit(self): #下滑滚动条 #for i in (0,28): action = ActionChains(self.driver).move_to_element( self.driver.find_element_by_id("keyval")) action.send_keys(Keys.ARROW_DOWN) #点击键盘向下箭头 time.sleep(3) #获取当前窗口句柄 nowhandle = self.driver.current_window_handle #点击纪念币楼层第一行第4个商品 IndexPage().click_goods14_link().click() time.sleep(3) #获取所有handle allhandles = self.driver.window_handles #循环,当句柄不等于首页句柄时,转换为现在的窗口句柄 for handle in allhandles: if handle != nowhandle: self.driver.switch_to_window(handle) #点击立即购买 GoodsDetail().click_buy_id().click() time.sleep(1) #滑动滚动条 CommonDef().huadong_gundongtiao() #点击提交订单 OrderSubmitPage().click_order_submit().click() time.sleep(1)
def setUp(self) -> None: """ 前置条件: 1, 登录 :return: """ self.driver = webdriver.Chrome() self.driver.implicitly_wait(20) # 初始化页面 self.login_page = LoginPage(self.driver) self.index_page = IndexPage(self.driver) # 登录 login_data = login_data_success[0] self.login_page.login(login_data['mobile'], login_data['pwd'])
def manage_browser(): # 初始化浏览器 driver = webdriver.Chrome() login_page = LoginPage(driver) index_page = IndexPage(driver) yield driver, login_page, index_page driver.quit()
def setUp(self): self.driver = GetSeleniumDriver().driver url = ReadExcelData().returnExcelData('data.xlsx', 'index', 0, 1) self.driver.get(url) time.sleep(1) self.driver.maximize_window() time.sleep(1) #点击请登录 IndexPage().click_login_link().click() #输入用户名 username = ReadExcelData().returnExcelData('data.xlsx', 'index', 2, 1) LoginPage().click_username().send_keys(username) #输入密码 password = ReadExcelData().returnExcelData('data.xlsx', 'index', 3, 1) LoginPage().click_password().send_keys(password) #点击登录按钮 LoginPage().click_login_submit().click() #判断是否登录成功 ''' def is_login_sucess(cls): #判断是否获取到登录账户名称 try: text = cls.driver.find_element_by_id("lnk_current_user").text print text return True except: return False ''' #获取当前窗口句柄 nowhandle = self.driver.current_window_handle time.sleep(2) #点击首页-会员中心 IndexPage().click_member_center().click() mylogger.debug("点击首页-会员中心") self.driver.implicitly_wait(5) #获取所有handle allhandles = self.driver.window_handles #循环,当句柄不等于首页句柄时,转换为现在的窗口句柄 for handle in allhandles: if handle != nowhandle: self.driver.switch_to_window(handle) time.sleep(2) #点击会员中心-收货地址 MemberCenter().clink_address_link().click() mylogger.debug("点击会员中心-收货地址") self.driver.implicitly_wait(5)
def setUp(self): url = ReadExcelData().returnExcelData('data.xlsx', 'index', 0, 1) self.driver.get(url) time.sleep(1) self.driver.maximize_window() time.sleep(1) IndexPage().click_login_link().click() time.sleep(1)
def test_succs(self, test_info): # 获取预期结果 expected = test_info['expected'] # 获取实际结果 LoginPage(self.driver).login(test_info['mobile'], test_info['pwd']) succs_msg = IndexPage(self.driver).get_mem_info() # 断言 self.assertEqual(succs_msg, expected)
def test_invest_fail(self, test_info): # 1、登录之后进入首页,先在首页点击抢投标按钮 IndexPage(self.driver).get_invest_btn() # 2、投标 InvestPage(self.driver).bid(test_info['money']) # 3、获取实际结果 fail_text = InvestPage(self.driver).bid_fail() print(fail_text) self.assertTrue(test_info['expected'] in fail_text)
class TestIndex: """测试企业微信首页""" def setup_method(self): self.index_page = IndexPage() def test_register(self): """测试注册功能""" register_page = self.index_page.register.register('EMUYI') error_msg = register_page.get_error_msg() assert '请选择' in ':'.join(error_msg) def test_login(self): """从登录页面进行注册""" self.index_page.login.goto_register() def teardown_method(self): self.index_page.quit()
def test_login_success(self): LoginPage(self.selenium).login_with_username_and_password( self.dataDict['username'], self.dataDict['password']) # 校验登陆成功后首页用户昵称是否与登陆信息一致 nickname = IndexPage(self.selenium).get_user_name() try: self.assertIn(self.dataDict['indexname'], nickname) except AssertionError as e: self.logger.error(e)
def setUpClass(cls) -> None: """打开浏览器,""" cls.driver = webdriver.Chrome() # 设置隐式等待 cls.driver.implicitly_wait(20) # 初始化要用到的页面 cls.login_page = LoginPage(cls.driver) cls.index_page = IndexPage(cls.driver) cls.driver.get("http://120.78.128.25:8765/login")
def login_setup(): """前置方法 登录""" driver = create_driver() driver.implicitly_wait(10) driver.get(conf.get('env', 'base_url') + conf.get('url_path', 'login')) login_page = LoginPage(driver) index_page = IndexPage(driver) yield login_page, index_page # 登录的后置 退出driver driver.quit()
class Application: def __init__(self): self.driver = webdriver.Chrome() self.index_page = IndexPage(self.driver) self.product_page = ProductPage(self.driver) self.checkout_page = CheckoutPage(self.driver) def quit(self): self.driver.quit() def check_cart(self): self.index_page.open() self.index_page.open_product(self.index_page.product_element) self.product_page.check_size() self.product_page.add_to_cart() self.product_page.wait_cart() self.checkout_page.open() self.checkout_page.delete_by_one_item( self.checkout_page.quantity_count) self.quit()
def login(): """登录的夹具""" driver = webdriver.Chrome() login_page = LoginPage(driver) index_page = IndexPage(driver) # 家登陆的逻辑 login_page.login("186", 'python') yield driver, login_page, index_page driver.quit()
class TestLogin(unittest.TestCase): def setUp(self) -> None: # 1, 打开浏览器; self.driver = webdriver.Chrome() # 设置隐式等待 self.driver.implicitly_wait(20) # 初始化要用到的页面 self.login_page = LoginPage(self.driver) self.index_page = IndexPage(self.driver) def tearDown(self) -> None: self.driver.quit() # @ddt.data(*test_data) # def test_login_error(self, test_info): # """手机号码为空""" # # 第一个:获取实际结果(封装以后执行的函数或者方法) res = request.visit() # self.login_page.login(test_info['mobile'], test_info['pwd']) # actual = self.login_page.get_error_msg() # # 第二个:获取预期结果 test_info【‘expected’】 # expected = test_info['expected'] # # 第三个:断言 # self.assertEqual(expected, actual) # 讲登录成功 def test_login_success(self): """登录成功""" # 执行登录操作, login_page.login() self.login_page.login("18684720553", 'python') # 进入了??页面 我的帐户[python] # 定位我的账户 self.index_page.get() actual = self.index_page.get_element_user() print("打印实际结果:",actual) # 预期结果 expected = '我的帐户[python]' self.assertIn(expected , actual.text)
def manage_browser(): # 浏览器二进制路径配置 options = ChromeOptions() options.binary_location = r"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" # 初始化浏览器 driver = webdriver.Chrome(options=options) login_page = LoginPage(driver) index_page = IndexPage(driver) yield driver, login_page, index_page driver.quit()
def test_candel_notice(self): ''' 取消删除公告管理;CRM-ST-BG-021 :return: ''' # 登录 username = "******" password = "******" noticetitle = "公告" lp = LoginPage(self.driver) lp.open() lp.login(username, password) # 去到公告管理页面 sleep(3) ip = IndexPage(self.driver) ip.username_click() sleep(3) ip.notice_click() sleep(3) # 删除公告 np = NoticePage(self.driver) np.notice_del(noticetitle) np.notice_del_button_click() # 确认删除 sleep(3) confirm = Alert(self.driver) confirm.dismiss() # 断言 text = np.notice_title_get() logger.info(text) self.asserttIn(noticetitle, text)
def test_check_sum_function(driver, logger): first_arg = 1 second_arg = 2 index_page = IndexPage(driver) logger.info("输入两个加数 %d 和 %d, 并点击求和按钮" % (first_arg, second_arg)) index_page.caculate_sum(str(first_arg), str(second_arg)) logger.info("获取求和结果, 检查结果是否为 %d" % (first_arg + second_arg)) assert index_page.sum_result_label.text == str(first_arg + second_arg) # def test_check_sum_function_should_fail(driver, logger): # first_arg = 1 # second_arg = 2 # # # find elements # index_page = IndexPage(driver) # logger.info("输入两个加数 %d 和 %d, 并点击求和按钮" % (first_arg, second_arg)) # index_page.caculate_sum(str(first_arg), str(second_arg)) # logger.info("获取求和结果, 检查结果是否为 %d" % (first_arg + second_arg)) # index_page.caculate_sum(str(first_arg), str(second_arg)) # assert index_page.sum_result_label.text == str(first_arg + second_arg + 1)
def manage_browser(): # 初始化浏览器er # 浏览器二进制路径配置 options = ChromeOptions() options.binary_location = r"C:\Users\muji\AppData\Local\Google\Chrome\Application\chrome.exe" driver = webdriver.Chrome(options=options) login_page = LoginPage(driver) index_page = IndexPage(driver) yield driver, login_page, index_page driver.quit()
def test_invest_success(self, test_info): # 1、登录之后进入首页,先在首页点击抢投标按钮 IndexPage(self.driver).get_invest_btn() # 2、投标,并获取投标前的金额 invest_page = InvestPage(self.driver) money_before = invest_page.bid(test_info['money']) success_text = invest_page.bid_success() self.assertTrue(test_info['expected'] in success_text) # 3、点击查看并激活 invest_page.active_success() # 4、获取投标后的金额 money_after = UserPage(self.driver).get_money() # 5、断言 self.assertEqual(Decimal(money_before) - Decimal(str(test_info['money'])), Decimal(money_after))
class SecondRequestTest(unittest.TestCase): def setUp(self): self.browser = Browser() self.driver = self.browser.start() self.second_request_page = IndexPage( self.driver).open_second_request_page() def test_choose_category(self): categories_count = self.second_request_page.read_categories_count() for i in range(categories_count): category = self.second_request_page.choose_category(i) self.second_request_page.wait_for_results() category_is_valid = self.second_request_page.check_category( category) self.assertTrue(category_is_valid) def test_write_category_name(self): short_name = "usl" category_is_valid = self.write_category_name_in_field(short_name) self.assertTrue(category_is_valid) def test_write_category_name_with_polish_letter(self): short_name = u"usł" category_is_valid = self.write_category_name_in_field(short_name) self.assertTrue(category_is_valid) # def tearDown(self): # self.browser.stop() def write_category_name_in_field(self, short_name): category = self.second_request_page.write_categories_name(short_name) self.second_request_page.wait_for_results() category_is_valid = self.second_request_page.check_category(category) return category_is_valid
def setUp(self): self.driver = GetSeleniumDriver().driver self.driver.get("http://pftest.ecgci.com/index.html") time.sleep(1) self.driver.maximize_window() time.sleep(1) #点击请登录 IndexPage().click_login_link().click() time.sleep(1) #输入用户名 LoginPage().click_username().send_keys(u"test0135") time.sleep(1) #输入密码 LoginPage().click_password().send_keys("aaaaaa") time.sleep(3) #点击登录按钮 LoginPage().click_login_submit().click() time.sleep(3)
def test_open_account(self): '正常开户' LoginPage(self.selenium).login_with_username_and_password( self.dataDict['username'], self.dataDict['password']) IndexPage(self.selenium).page_navigation(self.dataDict['一级目录'], self.dataDict['二级目录']) pages = ACAccountPage(self.selenium).verify_current_page() self.assertEqual(pages, self.dataDict['二级目录']) time.sleep(3) ACAccountPage(self.selenium).new_AC( self.dataDict['稱謂'], self.dataDict['中文姓名'], self.dataDict['國籍'], self.dataDict['證明文件'], self.dataDict['簽發國家'], random.randint(10001, 999999999), self.dataDict['手提電話'], self.dataDict['電郵'], self.dataDict['國家'], self.dataDict['賬戶級別'], self.dataDict['帳號幣種'] + ' ') ACAccountPage(self.selenium).search_customer_info( self.dataDict['中文姓名']) # 根据中文姓名查询 time.sleep(2) ACinfo = ACAccountPage(self.selenium).return_openAC_info() # 返回表信息 self.assertEqual(ACinfo[0], '待批核') # 验证返回结果:提案状态 self.assertEqual(ACinfo[1], self.dataDict['中文姓名']) # 验证返回结果:中文姓名 sucessInfo = ACAccountPage( self.selenium).approval_AC_proposal() # 审批提案 self.assertIn('開戶成功', sucessInfo)