Esempio n. 1
0
 def collection_stock_prices(self, stock_name, filepath=file_path):
     """
     收集股票信息
     :param stock_name:股票代码
     :param filepath:excel文件路径
     :return:
     """
     new_data = {}
     prices = {}
     t = time.strftime("%Y-%m-%d", time.localtime())
     prices['当前'] = self.dr.get_ele_content(stock_new_prices)
     prices['今开'] = self.dr.get_ele_content(stock_opentoday_prices)
     prices['最高'] = self.dr.get_ele_content(stock_highest_prices)
     prices['昨收'] = self.dr.get_ele_content(stock_closeyes_prices)
     prices['最低'] = self.dr.get_ele_content(stock_lowest_prices)
     prices['涨跌幅度'] = self.dr.get_ele_content(stock_increase)
     self.stock_police(stock_name, prices)
     new_data[t] = prices
     excel = operateExcel(filepath, stock_name)
     old_data = excel.get_excel_dict()
     if old_data:
         all_data = {**old_data, **new_data}
     else:
         all_data = new_data
     excel.input_excel(all_data)
     print('采集成功,在{0}中查看'.format(filepath))
     self.dr.get_page_screenshot(case_name=stock_name + '股票_详情')
     BeautifulReport.add_test_img3(stock_name + '股票_详情')
Esempio n. 2
0
 def check_case(self, name='进入众测价值'):
     """检查是否成功"""
     url = self.dr.get_page_url()
     if url == zc_value_url:
         print('{0}用例成功!'.format(name))
         log.info('{0}用例成功!'.format(name))
         self.dr.get_page_screenshot(file_path=self.img_path, case_name=name + '_成功')
         BeautifulReport.add_test_img3(name + '_成功')
     else:
         print('{0}用例失败'.format(name))
         log.info('{0}用例失败!'.format(name))
         self.dr.get_page_screenshot(file_path=self.img_path, case_name=name + '_失败')
         BeautifulReport.add_test_img3(name + '_失败')
Esempio n. 3
0
 def check_filtertask_result1(self, name='筛选可参与任务'):
     """判断用例是否成功"""
     flag, ele = self.dr.judge_element(zc_cantask_result)  # 判断是否有可参与任务
     if flag:
         text = self.dr.get_ele_content(zc_cantask_result)
         print('用例成功,目前无任务,提示文案为:'.format(text))
         log.info('Success filter task case, result:"{0}"'.format(text))
         self.dr.get_page_screenshot(file_path=self.img_path,
                                     case_name=name + '_无结果时')
         BeautifulReport.add_test_img3(name + '_无结果时')
     else:
         print('用例成功,{0}完成!'.format(name))
         log.info('用例成功,{0}完成!'.format(name))
         self.dr.get_page_screenshot(file_path=self.img_path,
                                     case_name=name + '_有结果时')
         BeautifulReport.add_test_img3(name + '_有结果时')
Esempio n. 4
0
 def open_url(self, url):
     t1 = time.time()
     try:
         self.driver.get(url)
         log.info('{0} Open url: {1}, spend {2} seconds'.format(
             success, url,
             time.time() - t1))
     except Exception as e:
         log.info('Open link {0}: {1}, spend {2} seconds'.format(
             fail, url,
             time.time() - t1))
         log.error(e)
         self.get_page_screenshot(file_path=screenshot_path,
                                  case_name=url + '_打开url失败')
         BeautifulReport.add_test_img3(url + '_打开url失败')
         raise
Esempio n. 5
0
 def get_page_url(self, source='web'):
     """获取当前页面链接"""
     t1 = time.time()
     try:
         current_url = self.driver.current_url
         log.info(
             '{0} Get current page link:"{1}" , spend {2} seconds'.format(
                 success, current_url,
                 time.time() - t1))
     except Exception as e:
         log.error('Fail get current page link, spend "{1}" seconds'.format(
             fail,
             time.time() - t1))
         log.error(e)
         title = self.get_page_title()
         self.get_page_screenshot(case_name=title + '_获取页面链接失败',
                                  source=source)
         BeautifulReport.add_test_img3(title + '_获取页面链接失败')
         raise
     return current_url
Esempio n. 6
0
 def max_window(self, source='web'):
     """
     最大化窗口
     :return:
     """
     t1 = time.time()
     try:
         self.driver.maximize_window()
         log.info('{0} Maximize window, spend {1} seconds'.format(
             success,
             time.time() - t1))
     except Exception as e:
         log.info('{0} Maximize window, spend {1} seconds'.format(
             fail,
             time.time() - t1))
         log.error(e)
         url = self.get_page_url()
         self.get_page_screenshot(case_name=url + '_最大化窗口失败', source=source)
         BeautifulReport.add_test_img3(url + '_最大化窗口失败')
         raise
Esempio n. 7
0
 def click(self, css, secs=8, source='web'):
     """
     重写click方法
     :param css:
     :param secs:
     :return:
     """
     t1 = time.time()
     try:
         ele = self.find_element(css, secs)
         ele.click()
         log.info('{0} Click element:"{1}", spend {2} seconds'.format(
             success, css,
             time.time() - t1))
     except Exception as e:
         log.info(
             '{0} Unable to the element:"{1}", spend {2} seconds'.format(
                 fail, css,
                 time.time() - t1))
         log.error(e)
         self.get_page_screenshot(case_name=css + '_点击失败', source=source)
         BeautifulReport.add_test_img3(css + '_点击失败')
         raise
Esempio n. 8
0
 def chick_zc_honor(self, name='最新一期'):
     """
     检查是否成功获取到荣誉榜单
     param:name, 输入需要检查的榜单期数
     """
     try:
         honor_list = {}
         eles = self.dr.finds_element(zc_honor_tablename)
         for num in range(1, len(eles) + 1):
             text = self.dr.get_ele_content(eles[num - 1])
             honor_list[num] = text
         print('用例成功,"{0}荣誉榜单"为:\n{1}'.format(name, honor_list))
         log.info('Success case!')
         self.dr.get_page_screenshot(file_path=self.img_path,
                                     case_name=name + '荣誉榜单_成功')
         BeautifulReport.add_test_img3(name + '荣誉榜单_成功')
     except Exception as e:
         print('查看"{0}荣誉榜单"用例失败!'.format(name))
         log.error('Fail view newhonor case!')
         log.error(e)
         self.dr.get_page_screenshot(file_path=self.img_path,
                                     case_name=name + '荣誉榜单_失败')
         BeautifulReport.add_test_img3(name + '荣誉榜单_失败')
         raise
Esempio n. 9
0
 def wait_activity(self, activity, timeout=8, interval=1):
     """
     等待activity出现
     :param activity:需要等待的activity
     :param timeout: 超时时间
     :param interval: 轮询查找activity时间
     :return:
     """
     t1 = time.time()
     try:
         self.driver.wait_activity(activity, timeout, interval)
         log.info('{0} Find the activity:{1}, spend {2} seconds'.format(
             success, activity,
             time.time() - t1))
     except Exception as e:
         log.info('{0} Not find the activity:{1}, spend {2} seconds'.format(
             fail, activity,
             time.time() - t1))
         log.error(e)
         self.get_page_screenshot(file_path=screenshot_path,
                                  case_name=activity + '_等待activity',
                                  source='app')
         BeautifulReport.add_test_img3(activity + '_等待activity')
         raise
Esempio n. 10
0
 def check_filtertask_result(self, source='can'):
     """判断用例是否成功"""
     flag, ele = self.dr.judge_element(zc_cantask_result)  # 判断是否有可参与任务
     if flag:
         text = self.dr.get_ele_content(zc_cantask_result)
         print('用例成功,目前无任务,提示文案为:'.format(text))
         log.info('Success filter task case, result:"{0}"'.format(text))
         if source == 'can':
             self.dr.get_page_screenshot(file_path=self.img_path,
                                         case_name='筛选可参与任务_无结果时',
                                         source='other')
             BeautifulReport.add_test_img3('筛选可参与任务_无结果时')
         elif source == 'pro':
             self.dr.get_page_screenshot(file_path=self.img_path,
                                         case_name='筛选进行中任务_无结果时',
                                         source='other')
             BeautifulReport.add_test_img3('筛选进行中任务_无结果时')
         elif source == 'end':
             self.dr.get_page_screenshot(file_path=self.img_path,
                                         case_name='筛选已结束任务_无结果时',
                                         source='other')
             BeautifulReport.add_test_img3('筛选已结束任务_无结果时')
     else:
         if source == 'can':
             print('用例成功,成功筛选出可参与任务!')
             log.info('Success filter canjoin task case,')
             self.dr.get_page_screenshot(file_path=self.img_path,
                                         case_name='筛选可参与任务_有结果时',
                                         source='other')
             BeautifulReport.add_test_img3('筛选可参与任务_有结果时')
         elif source == 'pro':
             print('用例成功,成功筛选出进行中任务!')
             log.info('Success filter processing task case,')
             self.dr.get_page_screenshot(file_path=self.img_path,
                                         case_name='筛选进行中任务_有结果时',
                                         source='other')
             BeautifulReport.add_test_img3('筛选进行中任务_有结果时')
         elif source == 'end':
             print('用例成功,成功筛选出已结束任务!')
             log.info('Success filter end task case,')
             self.dr.get_page_screenshot(file_path=self.img_path,
                                         case_name='筛选已结束任务_有结果时',
                                         source='other')
             BeautifulReport.add_test_img3('筛选已结束任务_有结果时')
         else:
             print('用例失败,判断来源不详,source:"{0}"'.format(source))
             log.info('Fali filter task case,unknown source:"{0}"'.format(
                 source))
             self.dr.get_page_screenshot(file_path=self.img_path,
                                         case_name='筛选任务_来源未知',
                                         source='other')
             BeautifulReport.add_test_img3('筛选任务_来源未知')
             assert flag