Example #1
0
def preissue(driver):
    # 判断是否是测试包,是的话,切换环境
    scene = Operation(driver).isElementExist(By.ID, "android:id/button1")
    if scene:
        driver.find_element_by_id("android:id/button1").click()
        # 切换到 我的
        WebDriverWait(driver, 5, 0.5).until(
            EC.presence_of_element_located(
                (By.ID, "com.tianyancha.skyeye:id/tab_iv_5"))).click()
        # 下滑,寻找 设置
        switch = Operation(driver)
        switch.swipeUp()
        WebDriverWait(driver, 5, 0.5).until(
            EC.presence_of_element_located(
                (By.ID, "com.tianyancha.skyeye:id/tv_setting"))).click()
        # 判断是否需要切换环境
        try:
            # 是否为测试包
            presence = switch.isElementExist(By.ID,
                                             "com.tianyancha.skyeye:id/test")
            if presence:
                presence_text = WebDriverWait(driver, 5, 0.5).until(
                    EC.presence_of_element_located(
                        (By.ID, "com.tianyancha.skyeye:id/test")))
                if presence_text.text == "测试":
                    # 点击 切换环境 按钮
                    WebDriverWait(driver, 5, 0.5).until(
                        EC.presence_of_element_located(
                            (By.ID,
                             "com.tianyancha.skyeye:id/btn_change_environment"
                             ))).click()
                    WebDriverWait(driver, 3, 0.5).until(
                        EC.presence_of_element_located((
                            By.XPATH,
                            '//*[@resource-id="com.tianyancha.skyeye:id/tv_name" and @text="预发环境"]',
                        ))).click()
                    # time.sleep(1)
                    driver.close_app()
                    # time.sleep(1)
                    print("重启APP")
                    driver.launch_app()
                    # 点击同意用户协议
                    agree_license(driver)
                    # 跳过引导页
                    skip_guide(driver)
                    # 跳过更新提示
                    cancel_update(driver)
                    WebDriverWait(driver, 5, 0.5).until(
                        EC.presence_of_element_located(
                            (By.ID, "android:id/button1"))).click()
                    print("环境切换完毕")
                    return
            WebDriverWait(driver, 5, 0.5).until(
                EC.presence_of_element_located(
                    (By.ID, "com.tianyancha.skyeye:id/iv_back"))).click()
            WebDriverWait(driver, 5, 0.5).until(
                EC.presence_of_element_located(
                    (By.ID, "com.tianyancha.skyeye:id/tab_iv_1"))).click()
        except Exception as e:
            print(e)
Example #2
0
class CompanyFunc:
    def __init__(self, driver, excel):
        self.driver = driver
        self.operation = Operation(driver)
        self.excel = excel

    def search_company(self, company_name, device, company_num=1, max_num=5):
        """
        搜索公司,并进入
        @param company_name:  公司名字
        @param device:  设备名字
        @param company_num: 搜索结果第几个,从1 开始
        @param max_num:
        @return:
        """
        while True:
            if (self.operation.isElementExist(By.ID, self.excel["tab_1"])
                    or max_num <= 0):
                break
            self.driver.keyevent(4)
            max_num -= 1
        # 点击首页
        self.operation.new_find_element(By.ID, self.excel["tab_1"]).click()
        # 首页进入查公司
        self.operation.new_find_element(By.ID,
                                        self.excel["check_company"]).click()
        # 搜索公司名
        self.operation.adb_send_input(By.ID, self.excel["search_company"],
                                      company_name, device)
        # 进入公司
        counts = self.operation.new_find_elements(By.XPATH,
                                                  self.excel['search_num'])
        if len(counts) > 1:
            self.operation.new_find_element(
                By.XPATH,
                self.excel["entry_company"].format(company_num)).click()
        else:
            self.operation.new_find_element(
                By.XPATH, self.excel['entry_one_company']).click()

    def ask_banner(self):
        """
        是否有 问大家 条幅
        @return:
        """
        if self.operation.isElementExist(By.ID,
                                         self.excel['ask_banner'],
                                         outtime=10):
            self.operation.new_find_element(By.ID,
                                            self.excel['ask_banner']).click()

    def is_monitor(self):
        """
        公司是否被监控
        @return: status
        @rtype: bool
        """
        status = None
        monitor = self.operation.new_find_element(
            By.ID, self.excel["monitor_txt"]).text
        if monitor == "监控":
            status = False
        elif monitor == "已监控":
            status = True
        return status

    def is_group(self, group_name):
        """
        判断分组是否存在
        @param group_name:
        @return:
        """
        status = False
        groups = self.operation.new_find_elements(By.XPATH,
                                                  self.excel['group_count'])
        for i in range(1, len(groups) + 1):
            name = self.operation.new_find_element(
                By.XPATH, self.excel['group_name'].format(i)).text
            log.info("当前分组名字:{}, 传入的名字:{}".format(name, group_name))
            if group_name in name:
                status = True
                break
        return status

    def is_collect(self):
        """
        公司是否被收藏
        @return:
        """
        status = None
        collect_text = self.operation.new_find_element(
            By.ID, self.excel['collect_txt']).text
        if collect_text == "关注":
            status = False
        elif collect_text == "已关注":
            status = True
        return status

    def click_monitor(self, monitor_status=False, click_status=False):
        """
        点击监控
        @return:
        """
        # 点击监控按钮
        self.operation.new_find_element(By.ID,
                                        self.excel["click_monitor"]).click()
        if monitor_status:
            self.is_first_monitor()
            if click_status:
                # 点击「我在想想」
                self.operation.new_find_element(
                    By.ID, self.excel["email_neg"]).click()
            else:
                # 点击「确认」
                self.operation.new_find_element(
                    By.ID, self.excel["email_neg_pos"]).click()

    def click_collect(self, collect_status=False, click_status=False):
        """
        点击 关注 按钮
        @return:
        """
        # 点击监控按钮
        self.operation.new_find_element(By.ID,
                                        self.excel["click_collect"]).click()
        if collect_status:
            if click_status:
                # 点击「确认」
                self.operation.new_find_element(
                    By.ID, self.excel['email_neg_pos']).click()
                log.info("点击「确定」按钮")
            else:
                # 点击「取消」
                self.operation.new_find_element(
                    By.ID, self.excel['email_neg']).click()
                log.info("点击「取消」按钮")

    def is_first_monitor(self, outtime=1):
        """
        账号是否是第一次监控,是的话需要关闭填写邮箱
        @return:
        """
        status = self.operation.isElementExist(By.ID,
                                               self.excel['email_title'],
                                               outtime=outtime)
        if status:
            # 第一次监控,点击「取消」
            self.operation.new_find_element(By.ID,
                                            self.excel['email_neg'],
                                            outtime=0.5).click()

    def entry_monitor(self, back_max=5):
        """
        进入监控列表
        @param back_max:
        @return:
        """
        back_cnt = 0
        while True:
            if self.operation.isElementExist(By.ID,
                                             self.excel["tab_1"],
                                             outtime=1) or back_cnt > back_max:
                break
            else:
                self.driver.keyevent(4)
                back_cnt += 1
        # 点击「我的」
        self.operation.new_find_element(By.ID, self.excel["tab_5"]).click()
        # 点击「我的监控」
        self.operation.new_find_element(By.ID,
                                        self.excel["my_monitor"]).click()
        # 点击「监控列表」
        self.operation.new_find_element(By.XPATH, '//*[@text="监控列表"]').click()

    def entry_collect(self, back_max=5):
        """
        进入 我的-我的关注
        @param back_max:
        @return:
        """
        back_cnt = 0
        while True:
            if self.operation.isElementExist(By.ID,
                                             self.excel['tab_1'],
                                             outtime=1) or back_cnt > back_max:
                break
            else:
                self.driver.keyevent(4)
                back_cnt += 1
        # 点击「我的」
        self.operation.new_find_element(By.ID, self.excel['tab_5']).click()
        # 点击「我的监控」
        self.operation.new_find_element(By.ID,
                                        self.excel['my_collect']).click()

    def exists_monitor_list(self, company_name, monitor_count=5):
        """
        判断是否存在该公司
        @param company_name:
        @return:
        """
        # status = False
        # monitor_list = self.operation.new_find_elements(By.XPATH, self.excel['monitor_list'])
        # log.info(len(monitor_list))
        # for i in range(1, len(monitor_list) + 1):
        #     name = self.operation.new_find_element(By.XPATH, self.excel[
        #         'monitor_list'] + '[{}]/android.widget.LinearLayout[1]/android.widget.TextView'.format(i)).text
        #     log.info("获取当前监控列表公司名:{},待验证公司名:{}".format(name, company_name))
        #     if company_name == name:
        #         status = True
        #         break
        # return status
        # 是否存在列表中
        status = self.operation.isElementExist(
            By.XPATH, '//*[@text="{}"]'.format(company_name))
        # 当前页没找过,上拉查找
        while not status:
            if monitor_count <= 0:
                log.info('剩余查找次数:{}'.format(monitor_count))
                return False
            else:
                self.operation.swipeUp(y1=0.8, y2=0.5)
                # 是否存在列表中
                status = self.operation.isElementExist(
                    By.XPATH, '//*[@text="{}"]'.format(company_name))
                monitor_count -= 1
        log.info("当前页列表存在公司:{}".format(company_name))
        return status

    def monitor_list_info(self):
        """
        判断监控列表是否有监控信息
        @return:
        """
        monitor_list = self.operation.new_find_elements(
            By.XPATH, self.excel['monitor_list'])
        if monitor_list is None:
            return False
        return True

    def report_format(self, form):
        if form == 'pdf':
            self.operation.new_find_element(By.ID,
                                            self.excel['report_pdf']).click()
        elif form == 'pdf+word':
            self.operation.new_find_element(By.ID,
                                            self.excel['report_word']).click()

    def click_tab(self, more_local, x_proportion=108, y_proportion=200):
        """
        根据坐标点击, 默认是点击投诉
        纠错:y_proportion=50
        @return:
        """
        width = more_local['x'] + x_proportion
        height = more_local['y'] - y_proportion

        TouchAction(self.driver).tap(x=width, y=height).release().perform()

    def up_pic(self, num):
        """
        上传图片
        """
        self.operation.new_find_element(By.XPATH,
                                        self.excel['select_album']).click()
        pic_num = len(
            self.operation.new_find_elements(By.XPATH, self.excel['pic_num']))
        # 如果一屏图片多余15个,则只算15个,不然会造成点击不到的情况
        list_count = pic_num
        if list_count > 15:
            list_count = 15
        # 生成相册需要的下标列表,从1开始
        pic_list = [i for i in range(1, list_count + 1)]
        if pic_num > 0:
            if pic_num >= num:
                for i in range(1, num + 1):
                    # 随机一个相册列表下标
                    pop_random = random.randint(0, len(pic_list) - 1)
                    # 获取随机的相册列表对应的xpath下标
                    pop_num = pic_list.pop(pop_random)
                    self.operation.new_find_element(
                        By.XPATH,
                        self.excel['click_pic'].format(pop_num)).click()
                    log.info("第 {} 次随机选择第 {} 个图片".format(i, pop_num))
                self.operation.new_find_element(By.ID,
                                                self.excel['pic_btn']).click()
            else:
                raise Exception('相册数量小于要上传的数量')
        else:
            raise Exception('相册数量为0')

    def caption_info(self, check_num, report_list):
        report_count = self.operation.new_find_elements(
            By.XPATH, self.excel['report_caption'].format(check_num))
        for i in range(0, len(report_count)):
            report_caption = self.operation.new_find_element(
                By.XPATH,
                self.excel['report_caption_info'].format(check_num,
                                                         i + 1)).text
            log.info("待校验报告说明文案:{}".format(report_caption))
            assert report_list[i] == report_caption, "{}、{}不相等".format(
                report_list[i], report_caption)

    def check_caption_info(self, check_name, check_num):
        """
        校验 报告说明
        """
        if check_name == "企业信用报告-专业版":
            report_list = [
                "多维度评估企业信用,包含内容:", "1. 报告包含全部企业基本信息", "2. 股东出资信息、主要人员任职信息",
                "3. 法定代表人对外投资及任职信息", "4. 股权控制路径"
            ]
            self.caption_info(check_num=check_num, report_list=report_list)

        elif check_name == "企业信用报告-基础版":
            report_list = [
                "多维度评估企业信用,包含内容:", "1. 工商信息、股东、对外投资、司法风险",
                "2. 企业发展、知识产权、经营状况、企业年报"
            ]
            self.caption_info(check_num=check_num, report_list=report_list)

        elif check_name == "董监高对外投资及任职报告":
            report_list = [
                "多维度评估企业信用,包含内容:", "1. 基本信息", "2. 担任法定代表人的企业信息",
                "3. 对外投资的企业信息(含股比)", "4. 在外任职的企业信息", "5. 拥有疑似实际控制权的企业信息(含投资链)",
                "6. 曾经任职的企业信息", "7. 人脉圈分析"
            ]
            self.caption_info(check_num=check_num, report_list=report_list)

        elif check_name == "股权结构报告":
            report_list = [
                "多维度分析企业股权结构,包含内容:", "1. 工商基本信息", "2. 企业类型统计", "3. 各级股东信息",
                "4. 对外投资信息"
            ]
            self.caption_info(check_num=check_num, report_list=report_list)
Example #3
0
class Dishonest:
    def __init__(self, driver, element):
        self.driver = driver
        self.ELEMENT = element
        self.operation = Operation(self.driver)
        self.extend = Extend(self.driver)

    def into_dishonest_mid(self):
        search_input = self.operation.new_find_element(
            By.XPATH, self.ELEMENT["dishonest_search_input"])
        return search_input

    # 通过banner封装进入企业预核名方法
    def entrance(self):
        count = 0
        # 获取屏幕比例
        x = self.driver.get_window_size()["width"]
        y = self.driver.get_window_size()["height"]
        self.driver.swipe(0.8 * x, 0.52 * y, 0.2 * x, 0.52 * y, 300)
        base_path = os.path.abspath(
            os.path.join(os.path.dirname(__file__), os.pardir))
        banner_path = os.path.join(base_path, "Data/search_dishonest.png")
        while True:
            banner = self.operation.new_find_element(
                By.ID, "com.tianyancha.skyeye:id/sdv_banner")
            # 截取当前banner
            self.extend.get_screenshot_by_element(banner)
            # 进行图像比对
            result = self.extend.classify_hist_with_split(banner_path)
            # 判断图像对比结果和对比次数
            if count > 4:
                log.warning("查找banner超过4次上限!!!请检查!!!")
                break
            elif result > 0.7:  # 图像对比结果判断
                # 点击banner进入企业预核名页面
                self.operation.new_find_element(
                    By.ID, "com.tianyancha.skyeye:id/sdv_banner").click()
                break
            else:
                # 左滑切换下一张banner
                self.driver.swipe(0.8 * x, 0.52 * y, 0.2 * x, 0.52 * y, 300)
                count += 1

    def clean_search_history(self):
        """从「查老赖首页」开始,进入「搜索中间页」,删除「最近搜索记录」"""
        self.operation.new_find_element(
            By.XPATH, self.ELEMENT["dishonest_search_input"]).click()
        res = self.operation.isElementExist(
            By.ID, self.ELEMENT["dishonest_del_history"], outtime=3)
        # 如果「删除最近搜索按钮」存在:
        if res:
            self.operation.new_find_element(
                By.ID, self.ELEMENT["dishonest_del_history"]).click()
            self.operation.new_find_element(
                By.ID, self.ELEMENT["dishonest_del_submit"]).click()
        # 「删除最近搜索按钮」不存在,然后返回「查老赖」首页
        self.operation.new_find_element(
            By.ID, self.ELEMENT["dishonest_mid_cancel"]).click()
        log.info("清除查老赖搜索历史")

    def get_hotword_element_in_mid(self, idx=1):
        return self.operation.new_find_elements(
            By.ID, self.ELEMENT["dishonest_hot_words"])[idx]

    def click_hotword_in_mid(self, idx=1):
        hotword_element = self.get_hotword_element_in_mid(idx)
        text_value = hotword_element.text
        log.info("查看 {} 老赖信息".format(text_value))
        hotword_element.click()
        return text_value

    def broken_faith_enterprise(self):
        "进入 失信企业"
        enterprise = self.operation.new_find_element(
            By.XPATH, self.ELEMENT["broken_faith_enterprise_tab"])
        return enterprise

    def search_city(self,
                    province,
                    city,
                    pr_y1=0.7,
                    pr_y2=0.5,
                    ci_y1=0.7,
                    ci_y2=0.3):
        "按区域筛选"
        self.operation.new_find_element(
            By.XPATH,
            self.ELEMENT["dishonest_screen"].format(1)).click()  # 点击 1.全部区域
        # 滑动省份
        pr_count = 5
        while True:
            if (self.operation.isElementExist(
                    By.XPATH,
                    self.ELEMENT["dishonest_city"].format(province),
                    outtime=2) or pr_count <= 0):
                break
            self.operation.swipeUp(0.1, pr_y1, pr_y2)  # 滑动省份
            pr_count -= 1
        self.operation.new_find_element(
            By.XPATH, self.ELEMENT["dishonest_city"].format(province)).click()
        # 滑动城市
        city_count = 5
        while True:
            if (self.operation.isElementExist(
                    By.XPATH,
                    self.ELEMENT["dishonest_city"].format(city),
                    outtime=2) or city_count <= 0):
                break
            self.operation.swipeUp(0.5, ci_y1, ci_y2)  # 滑动城市
            city_count -= 1
        self.operation.new_find_element(
            By.XPATH, self.ELEMENT["dishonest_city"].format(city)).click()

    def search_year(self, year, y1=0.8, y2=0.6):
        "按年龄筛选"
        self.operation.new_find_element(
            By.XPATH,
            self.ELEMENT["dishonest_screen"].format(2)).click()  # 点击 出生年月
        self.operation.swipeUp(0.1, y1, y2)  # 滑动年份
        self.operation.new_find_element(
            By.XPATH, self.ELEMENT["dishonest_city"].format(year)).click()
        year_count = 10
        self.operation.new_find_element(
            By.XPATH,
            self.ELEMENT["dishonest_screen"].format(2)).click()  # 点击 出生年月
        while True:
            if (self.operation.isElementExist(
                    By.XPATH, self.ELEMENT["dishonest_screen"].format(2))
                    or year_count <= 0):
                break
            self.operation.swipeUp(0.1, y1, y2)  # 滑动年份
            year_count -= 1
        self.operation.new_find_element(
            By.XPATH, self.ELEMENT["dishonest_city"].format(year)).click()

    def search_sex(self, sex):
        "按性别筛选"
        self.operation.new_find_element(
            By.XPATH,
            self.ELEMENT["dishonest_screen"].format(3)).click()  # 点击 性别
        self.operation.new_find_element(
            By.XPATH, self.ELEMENT["dishonest_city"].format(sex)).click()

    def back_all_regions(self,
                         province="全部区域",
                         city="全部区域",
                         pr_y1=0.5,
                         pr_y2=0.7,
                         ci_y1=0.3,
                         ci_y2=0.7):
        self.operation.new_find_element(
            By.XPATH, self.ELEMENT["dishonest_screen"].format(1)).click()
        # 滑动省份
        pr_count = 5
        while True:
            if (self.operation.isElementExist(
                    By.XPATH,
                    self.ELEMENT["dishonest_city"].format(province),
                    outtime=2) or pr_count <= 0):
                break
            self.operation.swipeDown(0.1, pr_y1, pr_y2)  # 滑动省份
            pr_count -= 1
        self.operation.new_find_element(
            By.XPATH, self.ELEMENT["dishonest_city"].format(province)).click()
        # 滑动城市
        city_count = 5
        while True:
            if (self.operation.isElementExist(
                    By.XPATH,
                    self.ELEMENT["dishonest_city"].format(city),
                    outtime=2) or city_count <= 0):
                break
            self.operation.swipeDown(0.5, ci_y1, ci_y2)  # 滑动城市
            city_count -= 1
        if city == '全部区域':
            self.operation.new_find_element(
                By.ID, self.ELEMENT["dishonest_city_low"]).click()
        else:
            self.operation.new_find_element(
                By.XPATH, self.ELEMENT["dishonest_city"].format(city)).click()
Example #4
0
class SiftOperation:
    def __init__(self, driver, element):
        self.driver = driver
        self.operation = Operation(driver)
        self.element = element
        self.log = Logger("sift_tools").getlog()

    @getimage
    def get_key(self, key_, value, index):
        """
        获取高级筛选,选中项
        :param key_: 高级筛选项,键集合
        :param value: 高级筛选项,值集合
        :param index: 选择项索引
        :return:返回被选中项key
        """
        len_ = self.driver.get_window_size()
        x = len_["width"] * 0.5
        y1 = len_["height"] * 0.5
        y2 = len_["height"] * 0.15
        listKey = self.element[key_].split("###")
        listValue = self.element[value].split("###")
        origin = self.element[listKey[index - 1]]
        target = listValue[index - 1]
        if not self.operation.isElementExist(By.ID, self.element["bt_reset"]):
            self.operation.new_find_element(
                By.ID, self.element["select_more"]).click()
        all_icon = origin.split(
            "..")[0] + "following-sibling::android.widget.ImageView"
        for i in range(20):
            icon_tag = self.operation.isElementExist(By.XPATH, all_icon)
            origin_tag = self.operation.isElementExist(By.XPATH, origin)
            if len(listKey) > 2 and icon_tag:
                self.operation.new_find_element(By.XPATH, all_icon).click()
                break
            elif origin_tag:
                break
            else:
                self.driver.swipe(x, y1, x, y2, 2000)
                if i == 19:
                    self.log.info("获取「{}」失败".format(target))

        origin_text = self.operation.new_find_element(By.XPATH, origin).text
        self.operation.new_find_element(By.XPATH, origin).click()
        if self.operation.isElementExist(By.ID, self.element["more_commit"]):
            self.operation.new_find_element(
                By.ID, self.element["more_commit"]).click()

        return listKey[index - 1], origin_text

    @getimage
    def back2relation_search(self, inputTarget):
        """
        从公司详情页检验完成后,回到查关系
        :param inputTarget: 搜索关键词
        """
        for i in range(20):
            if self.operation.isElementExist(By.ID, self.element["clear_all"]):
                self.operation.new_find_element(
                    By.ID, self.element["clear_all"]).click()
                self.operation.new_find_element(
                    By.ID, self.element["delete_confirm"]).click()
                self.operation.new_find_element(
                    By.ID, self.element["from_input_textview"]).click()
                self.operation.new_find_element(
                    By.ID,
                    self.element["search_input_edit"]).send_keys(inputTarget)
                break
            else:
                self.driver.keyevent(4)

    @getimage
    def back2company_search(self):
        """
        从公司详情页检验完成后,回到查公司
        """
        for i in range(20):
            if self.operation.isElementExist(
                    By.ID, self.element["search_sort_or_cancel"]):
                break
            else:
                self.driver.keyevent(4)

    @getimage
    def reset(self, targetSelect):
        """
        重置高级筛选项
        :param targetSelect: 被选中筛选项
        """

        if self.operation.isElementExist(By.ID, self.element["bt_reset"]):
            if targetSelect is None:
                self.operation.new_find_element(
                    By.ID, self.element["bt_reset"]).click()
            else:
                self.operation.new_find_element(
                    By.XPATH, self.element[targetSelect]).click()
        else:
            if not self.operation.isElementExist(By.ID,
                                                 self.element["select_more"]):
                self.operation.swipeDown()
            self.operation.new_find_element(
                By.ID, self.element["select_more"]).click()
            if targetSelect is None:
                self.operation.new_find_element(
                    By.ID, self.element["bt_reset"]).click()
            else:
                self.operation.new_find_element(
                    By.XPATH, self.element[targetSelect]).click()

    @getimage
    def login_vip(self, phone_num_vip, phone_passwd):
        """
        登陆vip账号
        """
        if self.operation.is_login():
            self.operation.new_find_element(
                By.ID, "com.tianyancha.skyeye:id/tab_iv_5").click()
            login_text = self.operation.new_find_element(
                By.ID, "com.tianyancha.skyeye:id/tv_user_type").text
            if "到期时间" in login_text:
                self.operation.new_find_element(
                    By.ID, "com.tianyancha.skyeye:id/tab_iv_1").click()
            else:
                self.operation.logout()
                self.operation.login(phone_num_vip, phone_passwd)
        else:
            self.operation.login(phone_num_vip, phone_passwd)

    @getimage
    def login_normal(self, phone_num_normal, phone_passwd):
        """
        登陆普通账号
        """
        if self.operation.is_login():
            self.operation.new_find_element(
                By.ID, "com.tianyancha.skyeye:id/tab_iv_5").click()
            login_text = self.operation.new_find_element(
                By.ID, "com.tianyancha.skyeye:id/tv_user_type").text
            if "到期时间" in login_text:
                self.operation.logout()
                self.operation.login(phone_num_normal, phone_passwd)
            else:
                self.operation.new_find_element(
                    By.ID, "com.tianyancha.skyeye:id/tab_iv_1").click()
        else:
            self.operation.login(phone_num_normal, phone_passwd)

    @getimage
    def search_key(self, tag):
        """
        输入搜索关键词
        :param tag: 1:查公司;2:查关系
        :return: 返回输入的关键词
        """
        if tag == 1:
            self.operation.new_find_element(
                By.ID, self.element["search_company"]).click()
        else:
            self.operation.new_find_element(
                By.ID, self.element["search_relation"]).click()
        self.operation.new_find_element(By.ID,
                                        self.element["search_box"]).click()
        tarList = self.element["from_input_target"].split("###")
        inputTarget = tarList[random.randint(0, len(tarList) - 1)]
        if tag == 2:
            self.operation.new_find_element(
                By.ID, self.element["from_input_textview"]).click()
        self.operation.new_find_element(
            By.ID, self.element["search_input_edit"]).send_keys(inputTarget)
        self.log.info("搜索词:{}".format(inputTarget))
        return inputTarget

    @getimage
    def point2company(self, selectTarget):
        """
        从关系节点介入公司详情页
        :param selectTarget: 选中条件
        :return: 输入内容
        """
        selectText = self.operation.new_find_element(
            By.ID, self.element["tv_title"]).text
        if self.operation.isElementExist(By.ID,
                                         self.element["more_empty_view"]):
            self.log.info(selectText)
            self.reset(selectTarget)
        else:
            self.operation.new_find_element(
                By.XPATH, self.element["from_target_item_1"]).click()
            self.operation.new_find_element(
                By.XPATH, self.element["sky_canvas"]).click()
        return selectText

    @getimage
    def click2company(self, selectText, selectTarget):
        """
        用于查公司-更多筛选,点击搜索列表页中item
        :param selectText: 更多筛选-筛选项
        :param selectTarget: 搜索关键词
        :return: 返回被校验公司名
        """
        company_name = ''
        if self.operation.isElementExist(By.ID,
                                         self.element["more_empty_view"]):
            self.log.info("「{}」筛选无结果".format(selectText))
            self.reset(selectTarget)
        else:  # 查公司-「机构类型」筛选
            items = self.random_list()
            self.log.info("「{}」,搜索结果页-公司列表长度:{}".format(
                selectText, str(items)))
            # 防止item超出页面,无法获取元素
            if items > 2:
                items = items - 2
            t_item = "{}[{}]{}".format(self.element["company_list"],
                                       str(items),
                                       self.element["company_name_path"])
            company_name_ele = self.operation.new_find_element(
                By.XPATH, t_item)
            company_name = company_name_ele.text
            self.log.info("断言公司名称:{}".format(company_name))
            company_name_ele.click()
        return company_name

    @getimage
    def random_list(self):
        """
        搜索列表页,随机上滑
        :return: 返回搜索列表页,list长度
        """
        len_ = self.driver.get_window_size()
        x = len_["width"] * 0.5
        y1 = len_["height"] * 0.8
        y2 = len_["height"] * 0.3
        for i in range(random.randint(2, 6)):
            self.driver.swipe(x, y1, x, y2, 1000)
        return len(
            self.operation.new_find_elements(By.XPATH,
                                             self.element["company_list"]))

    @getimage
    def detail4relation(self,
                        detailText,
                        selectTarget,
                        inputTarget,
                        index=None):
        """
        获取公司:详情页维度
        :param detailText: 详情页维度名称
        :param selectTarget: 选中条件
        :param inputTarget: 输入内容
        :param index: 选中项索引
        """
        selectText = self.point2company(selectTarget)
        firm_name = self.operation.new_find_element(
            By.ID, self.element["firm_detail_name_tv"]).text
        self.log.info("高级筛选:{},断言公司名称:{}".format(selectText, firm_name))
        result = self.find_dim(detailText, selectText, index)
        self.back2relation_search(inputTarget)
        return result

    @getimage
    def detail4company(self, selectText, detailText, selectTarget, index=None):
        """
        获取公司:详情页维度
        :param selectText: 选中的筛选条件
        :param detailText: 详情页维度名称
        :param selectTarget: 选中条件
        :param index: 选中项索引
        """
        self.click2company(selectText, selectTarget)
        result = self.find_dim(detailText, selectText, index)
        self.back2company_search()
        self.reset(selectTarget)
        return result

    @getimage
    def erg_ew(self, selectText):
        """
        选中网址/邮箱
        :param selectText: 被选中项
        """
        _map = [
            {
                "tag": "邮箱",
                "ele": "tv_base_info_email"
            },
            {
                "tag": "网址",
                "ele": "tv_base_info_web"
            },
        ]
        result = "false"
        for i in _map:
            if i["tag"] in selectText:
                if self.operation.isElementExist(By.ID,
                                                 self.element[i["ele"]]):
                    result = self.driver.find_element_by_id(
                        self.element[i["ele"]]).get_attribute("enabled")
                if not self.operation.isElementExist(
                        By.ID, "com.tianyancha.skyeye:id/iv_claim_label"):
                    if result == "true":
                        self.log.info("===公司被认证,企业主上传了「{}信息」===".format(
                            i["tag"]))
                        result = "false"
        return result

    @getimage
    def basic4relation(self, selectTarget, inputTarget):
        """
        获取公司:基本信息(网址、邮箱)并断言
        :param selectTarget: 选中条件
        :param inputTarget: 输入内容
        """
        selectText = self.point2company(selectTarget)
        company_name = self.operation.new_find_element(
            By.ID, self.element["firm_detail_name_tv"]).text
        self.log.info("高级筛选:{},断言公司名称:{}".format(selectText, company_name))
        result = self.erg_ew(selectText)
        self.back2relation_search(inputTarget)
        return result, company_name

    @getimage
    def basic4company(self, selectText, selectTarget):
        """
        获取公司:基本信息(网址、邮箱)并断言
        :param selectText: 被选中的筛选项
        :param selectTarget: 选中条件
        """
        self.click2company(selectText, selectTarget)
        WebDriverWait(self.driver,
                      5).until(lambda driver: driver.find_element_by_id(
                          self.element["tv_base_info_email"]))
        result = self.erg_ew(selectText)
        self.back2company_search()
        self.reset(selectTarget)
        return result

    @getimage
    def into_company(self, company=None):
        """搜公司,并进入公司详情页"""
        if company is not None:
            self.operation.new_find_element(
                By.ID, self.element["search_company"]).click()
            self.operation.new_find_element(
                By.ID, self.element["search_box"]).click()
            self.operation.new_find_element(
                By.ID, self.element["search_input_edit"]).send_keys(company)
            company_ele = '//*[@class="android.widget.TextView" and @text="{}"]'.format(
                company)
            self.operation.new_find_element(By.XPATH, company_ele).click()
            WebDriverWait(self.driver,
                          5).until(lambda driver: driver.find_element_by_id(
                              self.element["tag_firm"]))
        else:
            self.search_key(1)
            WebDriverWait(self.driver,
                          5).until(lambda driver: driver.find_element_by_id(
                              self.element["btn_export_data"]))
            items = self.random_list()
            # 防止item超出页面,无法获取元素
            if items > 2:
                items = items - 2
            item_tag = "{}[{}]{}".format(self.element["company_list"],
                                         str(items),
                                         self.element["company_name_path"])
            company_item = self.operation.new_find_element(By.XPATH, item_tag)
            company_name = company_item.text
            self.log.info("断言公司名称:{}".format(company_name))
            company_item.click()
            return company_name

    @getimage
    def find_dim(self, detailText, selectText, index):
        """查找维度"""
        result = ''
        d_wd = '//*[@class="android.widget.TextView" and @text="{}"]'.format(
            detailText)
        d_count = '//*[@class="android.widget.TextView" and @text="{}"]/preceding-sibling::android.widget.TextView'.format(
            detailText)
        for i in range(20):
            if self.operation.isElementExist(By.XPATH, d_wd):
                detailCount = self.operation.isElementExist(By.XPATH, d_count)
                if detailText == "著作权":
                    if index == 2 and not detailCount:
                        # 断言-详情页「著作权」维度无数据时
                        result = detailCount
                    else:
                        self.operation.new_find_element(By.XPATH, d_wd).click()
                        targ = selectText[1:]  # 截取著作权类别
                        if targ == "软件著作权":
                            result = self.operation.count_num(
                                By.XPATH,
                                self.element["rjzzq_detail_tab_layout"])
                        elif targ == "作品著作权":
                            result = self.operation.count_num(
                                By.XPATH,
                                self.element["rjzzq_detail_tab_layout"])
                    break
                else:
                    result = detailCount
            else:
                self.operation.swipeUp(0.5, 0.7, 0.3, 2000)
                if i == 19:
                    self.log.info("断言失败-公司详情页未找到「{}」".format(detailText))
        return result

    @getimage
    def company_type(self, selectText, index, result=None):
        """进入工商信息,验证企业类型,相关操作"""
        _type_dict = {
            4: ["国有"],
            6: ["个体"],
            9: ["外"],
            10: ["港", "澳", "台"],
            11: ["联营"],
            12: ["一人有限责任公司"]
        }
        for i in range(20):
            if self.operation.isElementExist(
                    By.XPATH, self.element["more_gsxx_dimension"]):
                self.operation.new_find_element(
                    By.XPATH, self.element["more_gsxx_dimension"]).click()
                # 工商信息维度,查找企业类型字段
                for j in range(20):
                    if self.operation.isElementExist(
                            By.ID,
                            self.element["companyinfo_company_org_type_tv"]):
                        result_text = self.operation.new_find_element(
                            By.ID, self.
                            element["companyinfo_company_org_type_tv"]).text
                        self.log.info("企业类型筛选:{}".format(selectText))
                        result = None
                        for k in _type_dict.keys():
                            if index == k:
                                result = False
                                for l in _type_dict[k]:
                                    if l in result_text:
                                        result = True
                                        break
                                break
                            else:
                                result = selectText in result_text
                        break
                    else:
                        self.operation.swipeUp(0.5, 0.7, 0.3, 2000)
                        if j == 19:
                            result = "企业类型断言失败-工商信息详情页,企业类型未找到"
                break
            else:
                self.operation.swipeUp(0.5, 0.7, 0.3, 2000)
                if i == 19:
                    result = "企业类型断言失败-公司详情页未找到「工商信息」"
        return result