Exemplo n.º 1
0
 def test_search(self):
     try:
         self.sub_setUp()  # 调用sub_setUp方法
         p = LoGin(self.driver)
         p.test_search()
         print(10)
         # LoGin()
         # print(11)
         time.sleep(2)
         self.driver.find_element(*self.member_centre).click()
         test = self.driver.find_element(*self.prompt).text
         links = test[3:7]
         print(links)
         if links == Config().get('links'):
             self.sub_tearDown()
             logger.info('会员中心登录成功')
     except Exception as msg:
         # 代码执行错误时,打印图片
         script = os.path.basename(__file__)[:-3]  #获取用例名,去除.py
         nowTime = time.strftime(
             "%Y.%m.%d.%H.%M.%S") + "." + script  # 图片名称格式
         self.driver.get_screenshot_as_file(
             (LOG_PATH + '//%s.png') % nowTime)  # 截屏图片
         logger.info(script + ".%s" % msg)
         self.sub_tearDown()  # 调用退出方法
Exemplo n.º 2
0
 def test_search(self):
     try:
         self.sub_setUp()  # 调用sub_setUp方法
         p = LoGin(self.driver)  #调用登录类,并定位driver
         p.test_search()  #调用登录方法
         # datas = ExcelReader(self.excel).data
         print(2)
         time.sleep(3)
         WebDriverWait(self.driver,
                       10).until(lambda driver:  #定位设置框
                                 self.driver.find_element(*self.Username))
         WebDriverWait(self.driver,
                       10).until(lambda driver:  # 定位设置框
                                 self.driver.find_element(*self.order))
         print(4)
         self.driver.find_element(*self.new_order).click()
         # self.driver.find_element(*self.uesr_search).send_keys(datas[Test_Login.digital]["user"])
         logger.info('登录成功')  # 登录成功日志
         self.sub_tearDown()  # 调用退出方法
     except Exception as msg:
         # 代码执行错误时,打印图片
         nowTime = time.strftime(
             "%Y.%m.%d.%H.%M.%S") + ".test_001_login"  # 图片名称格式
         self.driver.get_screenshot_as_file(
             (LOG_PATH + '//%s.png') % nowTime)  # 截屏图片
         print(LOG_PATH)
         logger.info("test_001_login.%s" % msg)
         self.sub_tearDown()  # 调用退出方法
Exemplo n.º 3
0
 def test_search(self):
     try:
         self.sub_setUp()  # 调用sub_setUp方法
         p = LoGin(self.driver)  #调用登录类,并定位driver
         p.test_search()  #调用登录方法
         datas = ExcelReader(self.excel).data
         print(2)
         WebDriverWait(self.driver,
                       10).until(lambda driver:  #定位设置框
                                 self.driver.find_element(*self.Username))
         print(3)
         WebDriverWait(self.driver,
                       10).until(lambda driver:  # 定位订单框
                                 self.driver.find_element(*self.order))
         print(4.1)
         above = self.driver.find_element(*self.order)  #定位加入订单位置
         ActionChains(self.driver).move_to_element(
             above).click().perform()  #待元素显示,点击元素
         print(4)
         self.driver.find_element(*self.new_order).click()
         self.driver.find_element(*self.uesr_search).send_keys(
             datas[Test_Login.digital]["user"])
         logger.info('登录成功')  # 登录成功日志
         self.sub_tearDown()  # 调用退出方法
     except Exception as msg:
         # 代码执行错误时,打印图片
         script = os.path.basename(__file__)[:-3]  #获取用例名,去除.py
         nowTime = time.strftime(
             "%Y.%m.%d.%H.%M.%S") + "." + script  # 图片名称格式
         self.driver.get_screenshot_as_file(
             (LOG_PATH + '//%s.png') % nowTime)  # 截屏图片
         logger.info(script + ".%s" % msg)
         self.sub_tearDown()  # 调用退出方法
Exemplo n.º 4
0
 def test_search(self):
     try:
         self.sub_setUp()  # 调用sub_setUp方法
         # self.driver.maximize_window()
         # self.driver.get(Test_Login.URL)
         self.driver.find_element(*self.locator_button).click()  # 点击首页登录按钮
         datas = ExcelReader(self.excel).data  # 获取excell表格中字符串
         # 循环导入username、password
         for index, d in enumerate(datas):
             time.sleep(3)
             self.driver.find_element(*self.phone).clear()  # 清空用户名输入框
             self.driver.find_element(*self.password).clear()  # 清空密码输入框
             self.driver.find_element(*self.phone).send_keys(d['username'])  # 输入用户名(读取表格)
             self.driver.find_element(*self.password).send_keys(d['password'])  # 输入密码(读取表格)
             self.driver.find_element(*self.login_button).click()  # 登录页,点击登录按钮
             if index == 0:
                 #  意思就是在10秒内等待某个按钮被定位到。每隔0.5秒内调用一下until里面的表达式或者方法函数,
                 # 要么10秒内表达式执行成功,要么10秒后抛出超时异常
                 WebDriverWait(self.driver, 10).until(lambda driver:
                                                      self.driver.find_element(*self.login_account))
             elif index == 1:
                 WebDriverWait(self.driver, 10).until(lambda driver:
                                                      self.driver.find_element(*self.login_password))
             elif index == (2, 3):
                 WebDriverWait(self.driver, 10).until(lambda driver:
                                                      self.driver.find_element(*self.Information))
             # elif index == (2, 3):
             #     WebDriverWait(self.driver, 10).until(lambda driver:
             #                                          self.driver.find_element(*self.Username))
             #  判断元素是否消失,是返回Ture,否返回False
             # is_disappeared = WebDriverWait(self.driver, 30, 1,).\
             #     until_not(lambda driver: self.driver.find_element(*self.Information).is_displayed())
             # print(is_disappeared)
         WebDriverWait(self.driver, 10).until(lambda driver:
                                              self.driver.find_element(*self.Username))
         links = self.driver.find_element(*self.Username).text  # 通过ID,获得用户名
         if links == Config().get('links'):  # 验证获得的用户名与配置文件中是否一致
             self.driver.find_element(*self.quit_button).click()  # 首页(已登录),退出按钮
             logger.info('登录成功')  # 登录成功日志
             self.sub_tearDown()  # 调用退出方法
     except Exception as msg:
         # 代码执行错误时,打印图片
         nowTime = time.strftime("%Y.%m.%d.%H.%M.%S") + ".test_001_login"  # 图片名称格式
         self.driver.get_screenshot_as_file(
             "D:\\TestCase\\Hypweb.Frame\\Test_framework\\log\\%s.png" % nowTime)  # 截屏图片
         logger.info("test_001_login.%s" % msg)
         self.sub_tearDown()  # 调用退出方法
Exemplo n.º 5
0
 def test_search(self):
     try:
         self.sub_setUp()  # 调用sub_setUp方法
         p = LoGin(self.driver)
         p.test_search()
         time.sleep(2)
         self.driver.find_element(*self.search).clear()  # 清空搜索栏
         self.driver.find_element(*self.search).send_keys(
             Test_Order.search_goods)  #输入文字
         self.driver.find_element(*self.search_button).click()  #点击搜索按钮
         WebDriverWait(
             self.driver,
             10).until(lambda driver:  #查询加入购物车按钮
                       self.driver.find_element(*self.add_shop_cat))
         above = self.driver.find_element(*self.add_shop_cat)  #定位加入购物车元素位置
         ActionChains(self.driver).move_to_element(
             above).click().perform()  #待元素显示,点击元素
         WebDriverWait(
             self.driver,
             10).until(lambda driver:  # 查询加入购物车按钮
                       self.driver.find_element(*self.purchase_quantity))
         p = self.driver.find_element(*self.purchase_quantity)
         value = int(p.get_attribute("value"))
         print(type(value))
         f = random.randint(1, 10)
         print(type(f))
         for i in range(f):
             if f > value:
                 self.driver.find_element(*self.increase).click()
         print(3)
         time.sleep(3)
         logger.info('搜索成功')  # 登录成功日志
         self.sub_tearDown()  # 调用退出方法
     except Exception as msg:
         # 代码执行错误时,打印图片
         nowTime = time.strftime(
             "%Y.%m.%d.%H.%M.%S") + ".test_003_order"  # 图片名称格式
         # print(type(nowTime))
         self.driver.get_screenshot_as_file(
             "D:\\TestCase\\Hypweb.Frame\\Test_framework\\log\\%s.png" %
             nowTime)  # 截屏图片
         # print(type(msg))
         age = "test_003_login:"******"%s:%s" % (age, msg))
         self.sub_tearDown()  # 调用退出方法
Exemplo n.º 6
0
 def test_search(self):
     try:
         self.sub_setUp()  # 调用sub_setUp方法
         p = LoGin(self.driver)
         p.test_search()
         time.sleep(2)
         self.driver.find_element(*self.search).clear()  # 清空搜索栏
         self.driver.find_element(*self.search).send_keys(
             Test_Order.search_goods)  #输入文字
         self.driver.find_element(*self.search_button).click()  #点击搜索按钮
         WebDriverWait(
             self.driver,
             10).until(lambda driver:  #查询加入购物车按钮
                       self.driver.find_element(*self.add_shop_cat))
         above = self.driver.find_element(*self.add_shop_cat)  #定位加入购物车元素位置
         ActionChains(self.driver).move_to_element(
             above).click().perform()  #待元素显示,点击元素
         WebDriverWait(
             self.driver,
             10).until(lambda driver:  # 查询加入购物车按钮
                       self.driver.find_element(*self.purchase_quantity))
         p = self.driver.find_element(*self.purchase_quantity)
         value = int(p.get_attribute("value"))
         print(type(value))
         f = random.randint(1, 10)
         print(type(f))
         for i in range(f):
             if f > value:
                 self.driver.find_element(*self.increase).click()
         print(3)
         time.sleep(3)
         logger.info('搜索成功')  # 登录成功日志
         self.sub_tearDown()  # 调用退出方法
     except Exception as msg:
         # 代码执行错误时,打印图片
         script = os.path.basename(__file__)[:-3]  #获取用例名,去除.py
         nowTime = time.strftime(
             "%Y.%m.%d.%H.%M.%S") + "." + script  # 图片名称格式
         self.driver.get_screenshot_as_file(
             (LOG_PATH + '//%s.png') % nowTime)  # 截屏图片
         logger.info(script + ".%s" % msg)
         self.sub_tearDown()  # 调用退出方法
Exemplo n.º 7
0
 def test_search(self):
     try:
         self.sub_setUp()  # 调用sub_setUp方法
         p = LoGin(self.driver)
         p.test_search()
         print(10)
         # LoGin()
         # print(11)
         time.sleep(2)
         self.driver.find_element(*self.member_centre).click()
         test = self.driver.find_element(*self.prompt).text
         links = test[3:7]
         print(links)
         if links == Config().get('links'):
             self.sub_tearDown()
             logger.info('会员中心登录成功')
     except Exception as msg:
         # 代码执行错误时,打印图片
         nowTime = time.strftime("%Y.%m.%d.%H.%M.%S") + ".test_001_member"  # 图片名称格式
         self.driver.get_screenshot_as_file(
             "D:\\TestCase\\Hypweb.Yili\\Test_framework\\log\\%s.png" % nowTime)  # 截屏图片
         logger.info("test_001_login.%s" % msg)
         self.sub_tearDown()  # 调用退出方法