def skip_guide(driver, x1=0.8, x2=0.1, outtime=5): """ 跳过引导页 :param driver: :param x1: :param x2: :param outtime: :return: """ try: element = Operation(driver).isElementExist( By.ID, "com.tianyancha.skyeye:id/launch_vp", outtime=outtime ) win = driver.get_window_size() if element: for i in range(3): TouchAction(driver).press( x=win["width"] * x1, y=win["height"] * 0.5 ).move_to( x=win["width"] * x2, y=win["height"] * 0.5 ).release().perform() driver.find_element_by_id("com.tianyancha.skyeye:id/launch_btn").click() # 是否存在 “显示在其他应用的上层” bar_title = Operation(driver).isElementExist( By.ID, "android:id/title", outtime=3 ) if bar_title: driver.keyevent(4) except Exception as e: log.error(e)
def agree_license(driver, outtime=5): try: element = Operation(driver).isElementExist( By.ID, "com.tianyancha.skyeye:id/btn_agreement_next", outtime=outtime ) if element: Operation(driver).new_find_element( By.ID, "com.tianyancha.skyeye:id/btn_agreement_next" ).click() log.info("点击同意用户协议和隐私政策!") else: log.info("点击同意用户协议失败!!!") except Exception as e: log.error(e)
def cancel_update(driver): """ 旧版本关闭更新弹窗 :param driver: :return: """ try: ele = Operation(driver).isElementExist( By.ID, "com.tianyancha.skyeye:id/btn_finish") if ele: Operation(driver).new_find_element( By.ID, "com.tianyancha.skyeye:id/btn_finish").click() except Exception as e: log.error(error_format(e))
def _get_operation(add=False): arg1 = None arg2 = None inputs = "\n".join([e.value for e in FunctionMethod]) method = raw_input("Input possible:\n"+inputs+"\nPlease enter the operation: ") while method not in set(e.value for e in FunctionMethod): print("Error the operation is not permitted") method = raw_input("Input possible:\n" + inputs + "\nPlease enter the operation: ") if not add: arg1 = raw_input("Please enter the first argument: ") try: arg1 = int(arg1) except ValueError: pass arg2 = raw_input("Please enter the second argument: ") try: arg2 = int(arg2) except ValueError: pass return Operation(method, arg1, arg2)
def start(self): data = self.communicator.read_transmit() while data[0] != STOP: operation_data = data[1] task_data = data[2] task = Task(task_data["code"]) operation = Operation( operation_data["id"], operation_data["params"], operation_data["credits"], operation_data["cron"], operation_data["times_per_minute"], operation_data["stop_time"], operation_data["binary"]) print("Got finished task: ", task.code, " for operation: ", operation.id) def ack(operation_id): # If operation was successfully saved in the server if operation_id == operation.id: print("Successfully sent task: ", task.code, " for operation: ", operation.id) self.communicator.sent_task(operation, task) # Send operation to server self.send_results(operation, task, ack) data = self.communicator.read_transmit() print("Transmit manager ending its work...")
def setUpClass(cls): super().setUpClass() cls.operation = Operation(cls.driver) cls.company = CompanyFunc(cls.driver, cls.ELEMENT) cls.account = Account() cls.company_name = '四川同辉实业有限公司' cls.rand_str = RandomStr()
def setUpClass(cls): super().setUpClass() cls.operation = Operation(cls.driver) cls.company = CompanyFunc(cls.driver, cls.ELEMENT) cls.account = Account() cls.user = cls.account.get_account() cls.company_name = '四川同辉实业有限公司'
def traceroute(self, op_id, params, credits_): # Params must be a dict with params actual_credits = self.communicator.get_current_credits() print("Credit cost: ", credits_) print("Credits in use: ", actual_credits, "/", self.max_credits) if actual_credits + credits_ > self.max_credits: print("No available credits for this operation") return sub_cmd = self.parser.parse_traceroute(params) print("Sub cmd: ", sub_cmd) operation = Operation( op_id, sub_cmd, credits_, params["cron"], params["times_per_minute"], params["stop_time"], SCAMPER_BINARY ) data_to_send = { "credits": credits_ } self.sender.emit( "new_operation", data_to_send ) self.operations_manager.add_operation(operation)
def run(self): self.vizgraph = VizGraph() with open(self.get_workflow_path()) as f: json_data = json.load(f) for s in json_data["setup"]: self.vizgraph.add_viz(s) for s in json_data["setup"]: self.vizgraph.apply_interaction(Operation(s)) self.workflow_interactions = json_data["interactions"] self.operation_results = OrderedDict({ "args": vars(self.options), "results": OrderedDict() }) self.current_interaction_index = 0 self.current_vizrequest_index = 0 self.benchmark_start_time = util.get_current_ms_time() try: logger.info("calling \"workflow_start\" on driver") self.driver.workflow_start() except AttributeError: pass global do_poll do_poll = True def poll_results(slf, queue): global count while do_poll: try: process_result = queue.get(timeout=1) except Empty: logger.info("result queue empty... trying again") continue if process_result is None: continue slf.deliver_viz_request([process_result]) logger.info("stopped polling results") try: while queue.get(timeout=0.01): pass except Empty: logger.info("result queue cleard") if not self.options.groundtruth: thread = Thread(target = poll_results, args = (self, IDEBench.result_queue)) thread.start() interaction_index = 0 while interaction_index < len(self.workflow_interactions): self.process_interaction(interaction_index) interaction_index +=1 do_poll = False if not self.options.groundtruth: thread.join() self.end_run()
def process_interaction(self, interaction_index): print("processing!") if interaction_index < 0 or interaction_index >= len( self.workflow_interactions): print("reached end of interactions") self.end_run() return print("thinking...") time.sleep(self.options.settings_thinktime / 1000) interaction = self.workflow_interactions[interaction_index] vizs_to_request = self.vizgraph.apply_interaction( Operation(interaction)) viz_requests = [] for viz in vizs_to_request: viz_requests.append( VizRequest(self.current_vizrequest_index, self.current_interaction_index, viz)) self.current_vizrequest_index += 1 #if interaction_index == 0: # self.result_queue = multiprocessing.Queue() # TODO: document this feature try: self.driver.before_requests(self.options, self.schema, IDEBench.result_queue) except AttributeError: pass procs = [] nprocs = len(viz_requests) if hasattr(self.driver, "use_single_process") and self.driver.use_single_process: for viz_request in viz_requests: self.driver.process_request(viz_request, self.options, self.schema, IDEBench.result_queue) else: for viz_request in viz_requests: proc = multiprocessing.Process( target=self.driver.process_request, args=(viz_request, self.options, self.schema, IDEBench.result_queue)) procs.append(proc) proc.start() resultlist = [] for i in range(nprocs): resultlist.append(IDEBench.result_queue.get()) for proc in procs: proc.join() self.deliver_viz_request(resultlist) self.current_interaction_index += 1 self.process_interaction(self.current_interaction_index)
def get_states(self): num_bins = self.pick(self.config["numBinDimensionsPerViz"]["values"], self.config["numBinDimensionsPerViz"]["pd"]) bins = [] picks = [] while len(bins) < num_bins: dimensions_p = [dim["p"] for dim in self.config["dimensions"]] dimensions_p = [p / sum(dimensions_p) for p in dimensions_p] dimension = self.pick(self.config["dimensions"], dimensions_p) if dimension in picks: continue picks.append(dimension) sql_statement = "SELECT * FROM df " df = self.df df = pandasql.sqldf(sql_statement, locals()) d_bin = {"dimension": dimension["name"]} if self.dim_to_type[dimension["name"]] == "quantitative": dim_max_val = df[dimension["name"]].max() dim_min_val = df[dimension["name"]].min() #d_bin["width"] = round(random.uniform(0.025, 0.1) * (dim_max_val - dim_min_val)) d_bin["width"] = round( random.uniform(0.025, 0.1) * (dim_max_val - dim_min_val)) elif self.dim_to_type[dimension["name"]] == "categorical": try: pd.to_numeric(df[dimension["name"]]) d_bin["width"] = 1 except: pass bins.append(d_bin) per_bin_aggregate_type = self.pick( self.config["perBinAggregates"]["values"], self.config["perBinAggregates"]["pd"]) per_bin_aggregate = {"type": per_bin_aggregate_type} if per_bin_aggregate_type == "avg": avg_dimension = self.pick([ d for d in self.sample_json["tables"]["fact"]["fields"] if (d["type"] == "quantitative") ]) per_bin_aggregate["dimension"] = avg_dimension["field"] VizAction.VIZ_COUNTER += 1 self.viz_name = "viz_%s" % VizAction.VIZ_COUNTER self.binning = bins self.perBinAggregates = [per_bin_aggregate] return Operation( OrderedDict({ "name": self.viz_name, "binning": self.binning, "perBinAggregates": self.perBinAggregates }))
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)
def process_interaction(self, interaction_index): logger.info("interaction %i" % interaction_index) interaction = self.workflow_interactions[interaction_index] next_interaction = self.workflow_interactions[interaction_index + 1] if interaction_index +1 < len(self.workflow_interactions) else None vizs_to_request = self.vizgraph.apply_interaction(Operation(interaction)) expected_start_time = interaction["time"] viz_requests = [] for viz in vizs_to_request: viz_requests.append(VizRequest(self.current_vizrequest_index, self.current_interaction_index, expected_start_time, viz)) self.current_vizrequest_index += 1 # TODO: document this feature try: self.driver.before_requests(self.options, self.schema, IDEBench.result_queue) except AttributeError: pass procs = [] nprocs = len(viz_requests) if self.options.groundtruth or (hasattr(self.driver, "use_single_process") and self.driver.use_single_process): for viz_request in viz_requests: op_id = str(viz_request.operation_id) if op_id in self.gt_for_result["results"] and self.gt_for_result["results"][op_id]["output"]: self.driver.process_request(viz_request, self.options, self.schema, IDEBench.result_queue) self.deliver_viz_request([IDEBench.result_queue.get()]) self.counter += 1 else: for viz_request in viz_requests: thread = Thread(target = self.driver.process_request, args = (viz_request, self.options, self.schema, IDEBench.result_queue )) procs.append(thread) thread.start() time.sleep(0.002) # so the request threads do not overwhelm some of the drivers (particularly verdictdb) resultlist = [] delay = 0 think_time = 0 if "time" in interaction and next_interaction: original_think_time = next_interaction["time"] - interaction["time"] delay = min(0, next_interaction["time"] - (util.get_current_ms_time() - self.benchmark_start_time)) think_time = max(0, delay + original_think_time) else: think_time = self.options.settings_thinktime if not self.options.groundtruth: time.sleep(think_time / 1000) self.current_interaction_index += 1
def receive_data(self, conn): operation_data_str = conn.recv() operation_data = json.loads(operation_data_str) operation = Operation(operation_data["id"], operation_data["params"], operation_data["credits"], operation_data["cron"], operation_data["times_per_minute"], operation_data["stop_time"], operation_data["binary"]) self.communicator.finish_operation(operation) conn.close()
def end_run(self): logger.info("done processing interactions") try: logger.info("calling \"workflow_end\" on driver") self.driver.workflow_end() except AttributeError: pass # adding un-answered queries, if necessary non_delivered_count = 0 delivered_count = 0 operation_id = 0 event_id = 0 if not self.options.groundtruth: for interaction in self.workflow_interactions: vizs_to_request = self.vizgraph.apply_interaction(Operation(interaction)) expected_start_time = interaction["time"] for viz in vizs_to_request: if not operation_id in self.operation_results["results"]: non_delivered_count += 1 self.deliver_viz_request([VizRequest(operation_id, event_id, expected_start_time, viz, True)]) else: delivered_count += 1 expected_start_time = interaction["time"] operation_id += 1 event_id += 1 if non_delivered_count > 0: logger.info("added %s non-delivered results to final result" % non_delivered_count) path = "results/%s.json" % (self.get_config_hash()) if not self.options.groundtruth: logger.info("saving results to %s" % path) with open(path, "w") as fp: json.dump(self.operation_results, fp, indent=4) if self.options.groundtruth: logger.info("saving groundtruth to %s" % self.get_groundtruth_path()) assure_path_exists(self.get_groundtruth_path()) with open(self.get_groundtruth_path(), "w") as fp: json.dump(self.operation_results, fp, indent=4)
def receive_data(self, conn): finished_task_data_str = conn.recv() finished_task_data = json.loads(finished_task_data_str) operation = Operation( finished_task_data["operation"]["id"], finished_task_data["operation"]["params"], finished_task_data["operation"]["credits"], finished_task_data["operation"]["cron"], finished_task_data["operation"]["times_per_minute"], finished_task_data["operation"]["stop_time"], finished_task_data["operation"]["binary"]) task = Task(finished_task_data["task"]["code"]) self.communicator.finish_task(operation, task) conn.close()
def __init__(self, driver, element): self.driver = driver self.ELEMENT = element self.operation = Operation(self.driver) self.extend = Extend(self.driver)
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()
def __init__(self, driver, element): self.driver = driver self.operation = Operation(driver) self.element = element self.log = Logger("sift_tools").getlog()
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
def __init__(self, driver, element): self.driver = driver self.opera = Operation(driver) self.ELEMENT = element
def get_states(self): if VizAction.VIZ_COUNTER < 1: return None pick_from = -1 pick_to = -1 link_type = None while (pick_from == -1 or pick_to == -1): from_candidate = random.randint(0, VizAction.VIZ_COUNTER) to_candidate = random.randint(0, VizAction.VIZ_COUNTER) link_type_names = [l["name"] for l in self.config["linkType"]] link_type_pds = [l["p"] for l in self.config["linkType"]] link_type = self.pick(link_type_names, link_type_pds) print(link_type) if link_type == "sequential" and LinkAction.LATEST_LINK: from_candidate = LinkAction.LATEST_LINK[1] elif link_type == "1n" and LinkAction.LATEST_LINK: from_candidate = LinkAction.LATEST_LINK[0] elif link_type == "n1" and LinkAction.FIRST_LINK: to_candidate = LinkAction.FIRST_LINK[1] num_tries = 10 giveup = False g = {} for i in range(num_tries + 1): g = {} for l in LinkAction.LINKS: if l[0] not in g: g[l[0]] = [] g[l[0]].append(l[1]) if from_candidate not in g: g[from_candidate] = [] g[from_candidate].append(to_candidate) if self.cyclic(g): if link_type == "n1" and LinkAction.FIRST_LINK: to_candidate = LinkAction.FIRST_LINK[1] else: to_candidate = random.randint(0, VizAction.VIZ_COUNTER) if i == num_tries: giveup = True else: break if giveup: print("giving up!") break if from_candidate != to_candidate and ( (to_candidate, from_candidate) not in LinkAction.LINKS) and ( (from_candidate, to_candidate) not in LinkAction.LINKS): pick_from = from_candidate pick_to = to_candidate if not LinkAction.FIRST_LINK: LinkAction.FIRST_LINK = (pick_from, pick_to) LinkAction.LATEST_LINK = (pick_from, pick_to) LinkAction.LINKS.add(LinkAction.LATEST_LINK) break if len(LinkAction.LINKS) >= VizAction.VIZ_COUNTER - 1: break #print("a") if (pick_from == -1 or pick_to == -1): # print("b") return None #print("c") incoming_links = [ "viz_" + str(l[0]) for l in filter(lambda x: x[1] == pick_to, LinkAction.LINKS) ] combined_filters = Operation( OrderedDict({ "name": "viz_" + str(pick_to), "source": (" and ".join(incoming_links)) })) return combined_filters
def get_states(self): if len(LinkAction.LINKS) == 0: return rand_link = self.pick(list(LinkAction.LINKS)) rand_link_src = rand_link[0] nodes_dict = self.vizgraph.get_nodes_dict() src_viz = nodes_dict["viz_" + str(rand_link_src)] computed_filter = src_viz.get_computed_filter() df = self.df sql_statement = "SELECT * FROM df " if len(computed_filter) > 0: sql_statement += "WHERE " + computed_filter df_result = pandasql.sqldf(sql_statement, locals()) if df_result.empty: return None filter_per_dim = [] for bin_dim in range(len(src_viz.binning)): filters = [] dim = src_viz.binning[bin_dim]["dimension"] field = list( filter(lambda x: x["field"] == dim, self.sample_json["tables"]["fact"]["fields"]))[0] if field["type"] == "quantitative": bin_width = float(src_viz.binning[bin_dim]["width"]) min_val = df_result[dim].min() max_val = df_result[dim].max() min_index = math.floor(min_val / bin_width) max_index = math.floor(max_val / bin_width) num_bins = 0 if np.random.rand() < 0.4: num_bins = 1 else: num_bins = random.randint( 1, max_index - min_index) if max_index > min_index else 1 selected_bins = np.random.choice(np.arange( min_index, max_index + 1), size=num_bins, replace=False) for selected_bin in selected_bins: range_min = selected_bin * bin_width range_max = (selected_bin + 1) * bin_width filt = "(%s >= %s and %s < %s)" % (dim, '{:.1f}'.format( range_min), dim, '{:.1f}'.format(range_max)) filters.append(filt) else: all_bins = df_result[dim].unique().tolist() num_bins = random.randint(1, len(all_bins)) selected_bins = np.random.choice(all_bins, size=num_bins, replace=False) for selected_bin in list(selected_bins): filt = "(%s = '%s')" % (dim, selected_bin) filters.append(filt) filter_per_dim.append(" or ".join(filters)) filter_per_dim = ["(%s)" % f for f in filter_per_dim] return Operation( OrderedDict({ "name": ("viz_%s" % rand_link_src), "selection": " and ".join(filter_per_dim) }))
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)
def run(self): print("Running with: ", self.current_ops) data = self.communicator.read_operations() while data[0] != STOP: status = data[1] if status == CREDITS: self.communicator.notify_current_credits(self.actual_credits()) else: operation_data = data[2] op_id = operation_data["id"] if status == IN_PROCESS: print("New operation event received") operation = Operation( operation_data["id"], operation_data["params"], operation_data["credits"], operation_data["cron"], operation_data["times_per_minute"], operation_data["stop_time"], operation_data["binary"]) self.current_ops[op_id] = operation self.schedule_operation(operation) elif status == TASK_FINISHED: print("New task finished event received") task_data = data[3] task = Task(task_data["code"]) try: self.current_ops[op_id].add_task(task) self.storage.mark_task_finished(task) self.communicator.notify_end_task( self.current_ops[op_id], task) except: # Operation has been stopped # Clean tmp file print("Removing pending task of finished operation") self.storage.remove_tmp_file(task) pass elif status == FINISHED: print("Operation finished") self.current_ops[op_id].status = FINISHED self.check_operation_finished(self.current_ops[op_id]) elif status == TASK_SENT: print("Task sent event received") task_data = data[3] task = Task(task_data["code"]) self.current_ops[op_id].update_task(task, TASK_SENT) # Save so that a sent task doesn't re-send in case of crash self.save_current_status() self.storage.remove_task(task) self.check_operation_finished(self.current_ops[op_id]) self.save_current_status() print("Current ops after: ", self.current_ops) data = self.communicator.read_operations() print("Operation manager ending its work...")
class RelationOperation: def __init__(self, driver, element): self.driver = driver self.opera = Operation(driver) self.ELEMENT = element def home_page(self): """回到首页""" while not self.opera.isElementExist(By.ID, self.ELEMENT["search_relation"]): self.driver.keyevent(4) def hot_relation(self): """进入热搜关系""" self.opera.new_find_element(By.ID, self.ELEMENT["search_relation"]).click() relation_tab_tag = self.opera.new_find_element(By.ID, self.ELEMENT["search_box"]).text self.opera.new_find_element(By.XPATH, self.ELEMENT["hot_relation"]).click() self.opera.new_find_element(By.ID, self.ELEMENT["discover_btn"]).click() hot_relation_point_tag = self.opera.isElementExist(By.XPATH, self.ELEMENT["relation_point"]) self.opera.new_find_element(By.ID, self.ELEMENT["app_title_logo"]).click() home_page_tag = self.opera.isElementExist(By.ID, self.ELEMENT["search_relation"]) return relation_tab_tag, hot_relation_point_tag, home_page_tag def search_relation_point(self, index): """ 查关系未登陆、非vip、vip三种状态断言 :param index: 1:未登录;2:非vip;其他:vip :return: """ self.opera.new_find_element(By.ID, self.ELEMENT["search_relation"]).click() self.opera.new_find_element(By.ID, self.ELEMENT["search_box"]).click() self.opera.new_find_element(By.ID, self.ELEMENT["from_input_textview"]).click() self.opera.new_find_element(By.ID, self.ELEMENT["search_input_edit"]).send_keys("北京金堤科技有限公司") self.opera.new_find_element(By.XPATH, self.ELEMENT["from_target_item_1"]).click() self.opera.new_find_element(By.ID, self.ELEMENT["to_input_textview"]).click() self.opera.new_find_element(By.ID, self.ELEMENT["search_input_edit"]).send_keys("盐城金堤科技有限公司") self.opera.new_find_element(By.XPATH, self.ELEMENT["from_target_item_1"]).click() self.opera.new_find_element(By.ID, self.ELEMENT["discover_btn"]).click() if index == 1: result = self.opera.new_find_element(By.XPATH, self.ELEMENT['passwd_login']).text self.home_page() elif index == 2: time.sleep(3) self.opera.new_find_element(By.ID, "com.tianyancha.skyeye:id/explore_must_vip_open_btn").click() result = self.opera.new_find_element(By.ID, self.ELEMENT['tv_top_title']).text self.home_page() else: result = self.opera.new_find_element(By.XPATH, self.ELEMENT['relation_point']).text return result def check_relation(self): """校验查关系结果""" self.opera.new_find_element(By.ID, self.ELEMENT["to_input_textview"]).click() self.opera.new_find_element(By.XPATH, self.ELEMENT["to_target_human"]).click() human_tag = self.opera.new_find_element(By.ID, self.ELEMENT["to_input_textview"]).text self.opera.new_find_element(By.ID, self.ELEMENT["discover_btn"]).click() relation_point_tag = self.opera.new_find_element(By.XPATH, self.ELEMENT["relation_point"]).text return human_tag, relation_point_tag def exam_relation(self): """示例关系""" self.opera.new_find_element(By.ID, self.ELEMENT["search_relation"]).click() self.opera.new_find_element(By.XPATH, self.ELEMENT["hot_relation"]).click() def all_screen(self): """关系图全屏""" self.opera.new_find_element(By.ID, self.ELEMENT["full_screen"]).click() discover_btn_tag = self.opera.isElementExist(By.ID, self.ELEMENT["discover_btn"]) exit_fullscreen_tag = self.opera.isElementExist(By.ID, self.ELEMENT["exit_fullscreen"]) relation_point_tag = self.opera.isElementExist(By.XPATH, self.ELEMENT["relation_point"]) return discover_btn_tag, exit_fullscreen_tag, relation_point_tag def exit_screen(self): """退出全屏""" self.opera.new_find_element(By.ID, self.ELEMENT["exit_fullscreen"]).click() exit_fullscreen_tag = self.opera.isElementExist(By.ID, self.ELEMENT["exit_fullscreen"]) discover_btn_tag = self.opera.isElementExist(By.ID, self.ELEMENT["discover_btn"]) return exit_fullscreen_tag, discover_btn_tag def confirm(self): """确认清空关系图""" self.opera.new_find_element(By.ID, self.ELEMENT["clear_all"]).click() delte_tag = self.opera.isElementExist(By.ID, self.ELEMENT["delte_cancel"]) self.opera.new_find_element(By.ID, self.ELEMENT["delte_cancel"]).click() confirm_tag = self.opera.isElementExist(By.ID, self.ELEMENT["delete_confirm"]) point_tag = self.opera.isElementExist(By.XPATH, self.ELEMENT["relation_point"]) self.opera.new_find_element(By.ID, self.ELEMENT["clear_all"]).click() self.opera.new_find_element(By.ID, self.ELEMENT["delete_confirm"]).click() cancel_tag = self.opera.isElementExist(By.ID, self.ELEMENT["delte_cancel"]) empty_tag = self.opera.isElementExist(By.ID, self.ELEMENT["relation_empty"]) return delte_tag, confirm_tag, point_tag, cancel_tag, empty_tag
def __init__(self, driver, excel): self.driver = driver self.operation = Operation(driver) self.excel = excel
def setUpClass(cls): super().setUpClass() cls.dishone = Dishonest(cls.driver, cls.ELEMENT) cls.operation = Operation(cls.driver)