Ejemplo n.º 1
0
 def __get_firefox_driver(self):
     firefox_driver_path = os.path.join(self.__driver_path,
                                        'geckodriver.exe')
     # driver = webdriver.firefox(executable_path=firefox_driver_path)
     driver = webdriver.Firefox(executable_path=firefox_driver_path)
     logger.info('初始化Firefox浏览器并启动')
     return driver
Ejemplo n.º 2
0
 def project_search_way01(self, ProjectName):
     try:
         self.project_search_action(ProjectName)
         self.common_page.Click_project()
         logger.info('搜索:[%s] 项目' % ProjectName)
     except Exception as e:
         print(e)
Ejemplo n.º 3
0
 def log_request(self, code='-', size='-'):
     """Selectively log an accepted request."""
     if self.server.logRequests:
         if isinstance(code, HTTPStatus):
             code = code.value
         logger.info('"%s" %s %s from %s', self.requestline, str(code),
                     str(size), self.client_address[0])
Ejemplo n.º 4
0
 def Pass_field_2(self, description_info):
     self.common_page.Pass_button()
     self.common_page.PdPvType_1_button()
     # self.common_page.PdPvType_2_button()
     self.common_page.description_input(description_info)
     self.common_page.save_button()
     logger.info('通过字段_说明: %s' % description_info)
Ejemplo n.º 5
0
def unpickle_params_core(args, kw) -> (list, dict):
    '''
    参数反序列化核心
        (如果类型是Binary的情况下才反序列化,因此如果参数类型不是Binary,这个装饰器将不起作用)

    :param args:
    :param kw:
    :return: new_args,new_kw
    '''
    new_args = []
    new_kw = {}
    # 转args
    for index, arg in enumerate(args):
        try:
            if isinstance(arg, Binary):
                new_args.append(pickle.loads(arg))
            else:
                new_args.append(arg)
        except TypeError:
            logger.info(traceback.format_exc())
            new_args.append(arg)
    new_args = tuple(new_args)
    # 转 kw
    for k, v in kw.items():
        try:
            if isinstance(v, Binary):
                new_kw[k] = pickle.loads(v)
            else:
                new_kw[k] = v
        except TypeError:
            logger.info(traceback.format_exc())
            new_kw[k] = v
    return new_args, new_kw
Ejemplo n.º 6
0
 def Patient_search(self, patient_info):
     time.sleep(3)
     self.common_page.patient_search_button()
     self.common_page.patient_search1(patient_info)
     self.common_page.patient_search_button()
     time.sleep(3)
     logger.info('搜索: %s 患者' % patient_info)
Ejemplo n.º 7
0
 def MissVisit_other(self, text_info):
     time.sleep(3)
     self.common_page.Operation_button()
     self.common_page.Miss_visit()
     self.common_page.defaul_select()
     self.common_page.other_reason(text_info)
     self.common_page.confirm_button()
     logger.info('访视缺失_其他#%s' % text_info)
Ejemplo n.º 8
0
 def cannel_miss_picture(self, cannel_reason_info):
     time.sleep(3)
     self.common_page.Cancel_button()
     time.sleep(3)
     self.common_page.Cannel_miss_pic_input(cannel_reason_info)
     time.sleep(3)
     self.common_page.Determine_button()
     logger.info('取消缺图提醒')
Ejemplo n.º 9
0
 def miss_picture_success(self, reason_info):
     time.sleep(3)
     self.common_page.miss_pic_remind_button()
     time.sleep(3)
     self.common_page.Miss_pic_input(reason_info)
     time.sleep(3)
     self.common_page.Determine_button()
     logger.info('缺图提醒')
Ejemplo n.º 10
0
 def delete_picture(self):
     time.sleep(3)
     self.common_page.click_first_pict()
     time.sleep(3)
     self.common_page.delete_pic_button()
     time.sleep(3)
     self.common_page.Determine_button()
     logger.info('删除图片')
Ejemplo n.º 11
0
 def Visit_Back(self, reason_info):
     time.sleep(3)
     self.common_page.visit_back_button()
     time.sleep(3)
     self.common_page.visit_back_input(reason_info)
     time.sleep(3)
     self.common_page.confirm_button()
     logger.info('访视打回')
Ejemplo n.º 12
0
 def wrapper(*args, **kw):
     return_val = func(*args, **kw)
     try:
         if not isinstance(return_val, bytes):
             return pickle.dumps(return_val)
         return return_val
     except TypeError:
         logger.info(traceback.format_exc())
         return return_val
Ejemplo n.º 13
0
 def login_action(self, username, password):
     time.sleep(3)
     self.login_page.input_username(username)
     time.sleep(3)
     self.login_page.input_password(password)
     time.sleep(3)
     self.login_page.click_login()
     logger.info('输入的账号是:%s,  密码是:%s' % (username, password))
     return CommonPage(self.login_page.driver)
Ejemplo n.º 14
0
 def setUp(self):
     '''
      测试用例的初始化
     :return:
     '''
     logger.info('--------测试方法初始化---------------')
     self.base_page = BasePage(Browser().get_driver())
     self.base_page.set_browser_max()
     self.base_page.implicitly_Wait(10)
     self.base_page.open_url(local_config.url)
Ejemplo n.º 15
0
 def quit(self):
     try:
         time.sleep(3)
         self.common_page.click_username()
         time.sleep(3)
         self.common_page.click_loginout_button()
         time.sleep(3)
         logger.info('账号退出登录成功')
     except Exception as e:
         logger.debug(e)
     return LoginPage(self.common_page.driver)
Ejemplo n.º 16
0
 def tearDown(self):
     # 测试用例失败的截图
     errors = self._outcome.errors
     for test, exc_info in errors:  #断言失败,就会有错误的信息
         if exc_info:
             self.base_page.default_wait()
             # self.base_page.screenshot()  # 截图
     self.base_page.implicitly_Wait(10)
     CommonPageAction(self.base_page.driver).quit()
     self.base_page.exit_driver()
     logger.info('--------测试方法执行完毕---------------')
Ejemplo n.º 17
0
def run(method_with_params_list):
    '''
    代理方法,需要在全局维护一个registest_list
    :param method_with_params_list:
    :return:
    '''
    def do_chain(method, params_list, current_step):
        method_name = method.replace('()', '')
        # 判断有没有这属性
        if not hasattr(current_step, method_name):
            raise Exception('{0}没有属性{1}'.format(str(current_step),
                                                method_name))

        if re.findall(r'\(\)', method):  # 是方法
            this_params = params_list.pop(0)
            this_args = this_params['args']
            this_kwargs = this_params['kwargs']
            current_step = getattr(current_step, method_name)(*this_args,
                                                              **this_kwargs)
        else:
            current_step = getattr(current_step, method_name)
        return current_step

    method = method_with_params_list[0]
    params_list = method_with_params_list[1]
    try:
        current_step = None
        logger.info('-------------------处理 {0},参数:{1}'.format(
            method, params_list))
        first_method = method.split('.')[0]
        first_method_name = first_method.replace('()', '')
        # 判断是否已经注册该方法/类
        if not first_method_name in register_list:
            raise Exception('类/方法%s没有注册' % first_method_name)
        else:
            first_registed_method_or_obj = register_list[first_method_name]

        if re.findall(r'\(\)', first_method):  # 是方法
            this_params = params_list.pop(0)
            this_args = this_params['args']
            this_kwargs = this_params['kwargs']
            current_step = first_registed_method_or_obj(
                *this_args, **this_kwargs)
        else:  # 不是方法
            current_step = first_registed_method_or_obj

        for m in method.split('.')[1:]:
            current_step = do_chain(m, params_list, current_step)

        return current_step
    except Exception as e:
        logger.error('{0} -------------- {1}'.format(method,
                                                     traceback.format_exc()))
        raise e
Ejemplo n.º 18
0
 def question_success(self, reson_info):
     time.sleep(3)
     self.common_page.field_question_button()
     time.sleep(3)
     self.common_page.questionType_button()
     time.sleep(3)
     self.common_page.questionType_3_button()  #数据不符合规则
     time.sleep(3)
     self.common_page.description_input(reson_info)
     time.sleep(3)
     self.common_page.save_button()
     logger.info('质疑字段:数据不符合规则')
Ejemplo n.º 19
0
 def test_useful_fanqiang(self, ip_dict):
     '''
     测试该代理能否翻墙(socks5代理)
     :return:
     '''
     try:
         proxy_type = ip_dict['proxy_type']
         ip_with_port = ip_dict['ip_with_port']
         logger.debug("开始测试" + ip_with_port)
         resp = requests.get(
             'https://www.youtube.com/',
             headers=scribe_utils.headers,
             proxies={
                 'http':
                 proxy_type + ('h' if proxy_type == 'socks5' else '') +
                 '://' + ip_with_port,
                 'https':
                 proxy_type + ('h' if proxy_type == 'socks5' else '') +
                 '://' + ip_with_port
             },
             timeout=2)
         logger.debug(ip_with_port + "------------------可用")
         use_time = resp.elapsed.microseconds / math.pow(10, 6)
         ip_dict['time'] = use_time
         db_client.run(Transformer().Fanqiang().update(
             ip_dict, {
                 '_id': ip_dict['_id']
             }).done())
         self.__disable_minus_1(ip_dict)
         return True
     except (scribe_utils.RobotException, \
             requests.exceptions.ConnectionError, requests.ReadTimeout, requests.exceptions.SSLError) as e:
         try:
             # if ip_dict['disable_times']>10:
             #     db_client.run(Transformer().Fanqiang().delete({'_id': ip_dict['_id']}).done())
             # else:
             self.__disable_plus_1(ip_dict)
         except Exception as e:
             logger.info(e)
         finally:
             return False
     except Exception as e:
         try:
             # if ip_dict['disable_times']>10:
             #     db_client.run(Transformer().Fanqiang().delete({'_id': ip_dict['_id']}).done())
             # else:
             self.__disable_plus_1(ip_dict)
         except Exception as e:
             logger.info(e)
         finally:
             return False
Ejemplo n.º 20
0
 def __get_chrome_driver(self):
     chrome_options = Options()
     chrome_options.add_argument('--disable-gpu')  # 谷歌文档提到需要加上这个属性来规避bug
     chrome_options.add_argument('lang=zh_CN.UTF-8')  # 设置默认编码为utf-8
     chrome_options.add_experimental_option('useAutomationExtension',
                                            False)  # 取消chrome受自动控制提示
     chrome_options.add_experimental_option(
         "excludeSwitches", ['enable-automation'])  # 取消chrome受自动控制提示
     chrome_driver_path = os.path.join(self.__driver_path,
                                       'chromedriver.exe')
     driver = webdriver.Chrome(options=chrome_options,
                               executable_path=chrome_driver_path)
     logger.info('初始化Google浏览器并启动')
     return driver
Ejemplo n.º 21
0
        def save(ip_with_port, proxy_type):
            try:
                elite = FanqiangService.test_elite(ip_with_port, proxy_type)
            except Exception as e:
                logger.info(str(e))
                return

            try:
                lock.acquire()
                if elite:
                    db_client.run(Transformer().Fanqiang().save({
                        'proxy_type':
                        proxy_type,
                        'ip_with_port':
                        ip_with_port,
                        'time':
                        0.00,
                        'location':
                        FanqiangService.get_location(
                            ip_with_port.split(':')[0]),
                        'Elite':
                        elite
                    }).done())
                else:
                    db_client.run(Transformer().Fanqiang().save({
                        'proxy_type':
                        proxy_type,
                        'ip_with_port':
                        ip_with_port,
                        'time':
                        0.00,
                        'location':
                        FanqiangService.get_location(
                            ip_with_port.split(':')[0])
                    }).done())
            except Exception as e:
                logger.error(e)
            finally:
                lock.release()
Ejemplo n.º 22
0
 def birthday_button(self,birthday_info):
     self.delete_element_attribute(self.birthday,'maxlength')
     self.input(self.birthday,birthday_info)
     BasePage(self.driver).press_enter_key(self.birthday)
     logger.info('点击[出生日期]元素')
Ejemplo n.º 23
0
 def Non_hepatic_penetration_button(self):
     self.click(self.Non_hepatic_penetration)
     logger.info('点击[非肝穿]元素')
Ejemplo n.º 24
0
 def Liver_puncture_button(self):
     self.click(self.Liver_puncture)
     logger.info('点击[肝穿]元素')
Ejemplo n.º 25
0
 def randomNumber_button(self,random_info):
     self.input(self.randomNumber,random_info)
     logger.info('输入随机号名:%s'%random_info)
Ejemplo n.º 26
0
 def patient_name_button(self,name_info):
     self.input(self.patient_name,name_info)
     logger.info('输入患者姓名: %s'%name_info)
Ejemplo n.º 27
0
 def visit_date_input(self,data_info):
     self.delete_element_attribute(self.visit_date,'maxlength')
     self.input(self.visit_date,data_info)
     BasePage(self.driver).press_enter_key(self.visit_date)
     logger.info('输入访视日期:%s'%data_info)
Ejemplo n.º 28
0
    def __get_useful_fanqiang_ip_gatherproxy_worker(self, q):
        while not q.empty():
            driver = None
            try:
                ip_dict = q.get()
                proxy_type = ip_dict['proxy_type']
                ip_with_port = ip_dict['ip_with_port']
                logger.debug("开始测试" + ip_with_port)
                resp = requests.get(
                    'https://www.google.com/',
                    headers=scribe_utils.headers,
                    proxies={
                        'http':
                        proxy_type + ('h' if proxy_type == 'socks5' else '') +
                        '://' + ip_with_port,
                        'https':
                        proxy_type + ('h' if proxy_type == 'socks5' else '') +
                        '://' + ip_with_port
                    },
                    timeout=10)
                # if not re.findall(r'input value=\"Google',resp.text):
                #     raise scribe_utils.RobotException()
                use_time = resp.elapsed.microseconds / math.pow(10, 6)

                logger.debug(ip_with_port + "可用")
                elite = FanqiangService.test_elite(ip_dict['ip_with_port'],
                                                   ip_dict['proxy_type'])
                try:
                    lock.acquire()
                    if elite:
                        db_client.run(Transformer().Fanqiang().save({
                            'proxy_type':
                            proxy_type,
                            'ip_with_port':
                            ip_with_port,
                            'time':
                            use_time,
                            'location':
                            FanqiangService.get_location(
                                ip_with_port.split(':')[0]),
                            'Elite':
                            elite
                        }).done())
                    else:
                        db_client.run(Transformer().Fanqiang().save({
                            'proxy_type':
                            proxy_type,
                            'ip_with_port':
                            ip_with_port,
                            'time':
                            use_time,
                            'location':
                            FanqiangService.get_location(
                                ip_with_port.split(':')[0])
                        }).done())
                except Exception as e:
                    logger.info(e)
                finally:
                    lock.release()
                    # 更新pac
                    # self.modify_chrome_pac_file_and_push(ip_with_port)

            except (requests.exceptions.ConnectionError, requests.ReadTimeout \
                            , requests.exceptions.SSLError, scribe_utils.RobotException) as e:
                continue
            # except exceptions.TimeoutException as e:  # 浏览器访问超时
            #     driver.quit()
            #     continue
            except Exception as e:
                if driver:
                    driver.quit()
                if re.findall(r'NoneType', str(e)):
                    continue
                if not isinstance(e, ValueError):
                    logger.warning(traceback.format_exc())
                continue
            finally:
                q.task_done()
Ejemplo n.º 29
0
    def __get_useful_fanqiang_ip_mongo_worker(self, q):
        while not q.empty():
            driver = None

            try:
                ip_dict = q.get()
                proxy_type = ip_dict['proxy_type']
                ip_with_port = ip_dict['ip_with_port']
                logger.debug("开始测试" + ip_with_port)
                resp = requests.get(
                    'https://www.google.com/',
                    headers=scribe_utils.headers,
                    proxies={
                        'http':
                        proxy_type + ('h' if proxy_type == 'socks5' else '') +
                        '://' + ip_with_port,
                        'https':
                        proxy_type + ('h' if proxy_type == 'socks5' else '') +
                        '://' + ip_with_port
                    },
                    timeout=10)
                try:
                    lock.acquire()
                    useful_proxy_in_mongo.append(ip_dict)
                finally:
                    lock.release()

                # if not re.findall(r'input value=\"Google',resp.text):
                #     raise scribe_utils.RobotException()

                # try:
                #     elite = FanqiangService.test_elite(ip_dict['ip_with_port'], ip_dict['proxy_type'])
                #     if elite:
                #         Fanqiang.update({'Elite': elite}, {'ip_with_port': ip_dict['ip_with_port']})
                # except Exception as e:
                #     logger.warning(traceback.format_exc())

                logger.debug(ip_with_port + "可用")
                self.modify_chrome_pac_file_and_push(ip_with_port)

            except (scribe_utils.RobotException, \
                    requests.exceptions.ConnectionError, requests.ReadTimeout, requests.exceptions.SSLError) as e:
                try:
                    lock.acquire()
                    new_disable_times = ip_dict['disable_times'] + 1
                    db_client.run(Transformer().Fanqiang().update(
                        {
                            'disable_times': new_disable_times
                        }, {
                            '_id': ip_dict['_id']
                        }).done())
                except Exception as e:
                    logger.info(e)
                finally:
                    lock.release()
                continue
            except Exception as e:
                try:
                    lock.acquire()
                    new_disable_times = ip_dict['disable_times'] + 1
                    db_client.run(Transformer().Fanqiang().update(
                        {
                            'disable_times': new_disable_times
                        }, {
                            '_id': ip_dict['_id']
                        }).done())
                except Exception as e:
                    logger.info(e)
                finally:
                    lock.release()
                if driver:
                    driver.quit()
                if re.findall(r'NoneType', str(e)):
                    continue
                if not isinstance(e, ValueError):
                    logger.warning(traceback.format_exc())
                continue
            finally:
                q.task_done()
Ejemplo n.º 30
0
 def default_login(self):
     self.login_action(local_config.username, local_config.password)
     logger.info('默认的账号,密码登录成功!')
     return CommonPage(self.login_page.driver)