def get_screen_shot(self, moudle):
     '''
     截图后,打印日志
     :param moudle: 具体截图的模块
     '''
     now_time = self.get_time()  #获取当前时间
     BasePage._now_time = now_time  #改变类数据的时间变量
     image_file = os.path.dirname(os.path.dirname(
         __file__)) + '/screenshots/%s_%s.png' % (moudle, now_time)  #定义图片路径
     logger.info(f'开始截图:{moudle}')  #打印日志
     self._driver.get_screenshot_as_file(image_file)  #截图
Esempio n. 2
0
 def find_element(self, locator):
     '''
     定位一个元素
     :param locator: 传的元素,元祖类型,key定位类型,value元素值
     :return:返回元素对象/False
     '''
     try:
         ele = WebDriverWait(self._driver,timeout=TIMEOUT,poll_frequency=POLL_FREQUENCY).\
             until(EC.presence_of_element_located(locator))
         return ele
     except:
         logger.info('未找到元素》》》》》》》》》》》》》》》》》》,返回False')
         return False
Esempio n. 3
0
 def find_elements(self, locator):
     '''
     定位一组元素
     :param locator: 传的元素,元祖类型,key定位类型,value元素值
     :return:返回元素对象/None
     '''
     try:
         eles = WebDriverWait(self._driver,timeout=TIMEOUT,poll_frequency=POLL_FREQUENCY).\
             until(lambda x: x.find_elements(*locator))
         return eles
     except:
         logger.info('未找到元素》》》》》》》》》》》》》》》》》》,返回False')
         return False
Esempio n. 4
0
 def get_screen_shot(self, moudle, msg):
     '''
     截图后,打印日志
     :param moudle: 具体截图的模块
     '''
     now_time = self.get_time()  #获取当前时间
     BasePage._now_time = now_time  #改变类数据的时间变量
     image_file = os.path.dirname(
         os.path.dirname(__file__)) + '/screenshots/%s_%s.png' % (
             moudle, BasePage._now_time)  #定义图片路径
     logger.info(f'开始截图:{moudle}')  #打印日志
     self._driver.get_screenshot_as_file(image_file)  #截图
     allure.attach.file(f'../screenshots/{moudle}_{BasePage._now_time}.png',
                        msg,
                        attachment_type=allure.attachment_type.PNG
                        )  #将截图写入allure,生成报告的时候,非生成报告无效
Esempio n. 5
0
 def steps(self, path, options):
     '''封装数据驱动,通过关键字驱动操作'''
     values = []
     with open(path, encoding='utf-8') as f:
         step_yaml: list[dict] = yaml.safe_load(f)
         step_yaml_value = step_yaml[options]
         for step in step_yaml_value:
             locator = step['locator']
             if step['action'] == 'click':  #点击
                 self.click_new(locator)
                 logger.info(f"【操作:{step['name']}】【值:{locator}】")
             if step['action'] == 'sleep_click':  #延时点击
                 time.sleep(step['sleep_time'])
                 self.click_new(locator)
                 logger.info(f"【操作:{step['name']}】【值:{locator}】")
             if step['action'] == 'send':  #输入
                 content: str = step['content']
                 for param in self._params:
                     content = content.replace('{%s}' % param,
                                               self._params[param])
                 self.send(locator, content)
                 logger.info(
                     f"【操作:{step['name']}】【值:{locator}】【内容:{content}】")
             if step['action'] == 'sleep_send':  #延时输入
                 content: str = step['content']
                 for param in self._params:
                     content = content.replace('{%s}' % param,
                                               self._params[param])
                 self.send(locator, content)
                 logger.info(
                     f"【操作:{step['name']}】【值:{locator}】【内容:{content}】")
                 time.sleep(step['sleep_time'])
             if step['action'] == 'text':  #获取文本信息,复数查询到后塞入列表['a','b']
                 ele_name_list = self.get_texts(locator)
                 logger.info(f"【操作:{step['name']}】【值:{locator}】")
                 values.append(ele_name_list)
             if 'screen' in step.keys():  #截图
                 time.sleep(self._sleep)
                 self.get_screen_shot(moudle=step['screen'],
                                      msg=step['screen'])
         self._params.clear()
         return values
Esempio n. 6
0
 def steps(self, path, options):
     '''封装数据驱动,通过关键字驱动操作'''
     values = []
     with open(path, encoding='utf-8') as f:
         step_yaml: list[dict] = yaml.safe_load(f)
         step_yaml_value = step_yaml[options]
         print(f'yaml数据:{step_yaml}')
         for step in step_yaml_value:
             locator = step['locator']
             if step['action'] == 'click':
                 self.click_new(locator)
                 logger.info(f"【操作:{step['name']}】【值:{locator}】")
             if step['action'] == 'send':
                 content: str = step['content']
                 for param in self._params:
                     content = content.replace('{%s}' % param,
                                               self._params[param])
                 self.send(locator, content)
                 logger.info(
                     f"【操作:{step['name']}】【值:{locator}】【内容:{content}】")
                 self._params.clear()
             if step['action'] == 'text':
                 ele_name_list = self.get_texts(locator)
                 logger.info(f"【操作:{step['name']}】【值:{locator}】")
                 values.append(ele_name_list)
             if 'screen' in step.keys():
                 time.sleep(self._sleep)
                 self.get_screen_shot(step['screen'])
         return values
Esempio n. 7
0
 def check_alert_click(self, locator):
     '''检测是否有alter,有关闭'''
     logger.info('========== check account alert ==========')
     try:
         ele = self.find_element(locator)
     except TimeoutException:
         logger.info('no account alert ')
     else:
         logger.info('close account alert ')
         ele.click()
Esempio n. 8
0
 def test_app1(self):
     logger.info('test_app1')
Esempio n. 9
0
 def test_api3(self):
     res = self.api.send(self.req).json()
     pytest.assume(res['highStock_moreThan'] == 6)
     logger.info('test_api3')
Esempio n. 10
0
 def test_web4(self):
     logger.info('test_web4')
Esempio n. 11
0
 def test_web3(self):
     logger.info('test_web3')
Esempio n. 12
0
 def test_web2(self):
     logger.info('test_web2')
Esempio n. 13
0
 def test_web1(self):
     logger.info('test_web1')
Esempio n. 14
0
 def test_app4(self):
     logger.info('test_app4')
Esempio n. 15
0
 def test_web8(self):
     logger.info('test_web8')
Esempio n. 16
0
 def test_web7(self):
     logger.info('test_web7')
Esempio n. 17
0
 def test_web6(self):
     logger.info('test_web6')
Esempio n. 18
0
 def test_web5(self):
     logger.info('test_web5')
Esempio n. 19
0
 def test_app2(self):
     logger.info('test_app2')
Esempio n. 20
0
 def test_app3(self):
     logger.info('test_app3')