def match_friend(driver): if not elements.MatchHistoryButton(driver): elements.MatchHomeButton(driver).click() #start match elements.MatchHomeButton(driver).click() friends_list = [] ctime = time.time() while time.time() < (ctime + 600): match_popup_handle(driver) if elements.VideoingObjectUserName(driver): logger.info("match success.") logger.info("UserName: %s,UserFavoriteNumber: %s,UserLocation: %s"%(elements.VideoingObjectUserName(driver).text,\ elements.VideoingObjectFavoriteNumber(driver).text,\ elements.VideoingObjectLocation(driver).text)) friends_list.append(elements.VideoingObjectUserName(driver).text) time.sleep(10) # quit current match elements.VideoingQuit(driver).click() if len(friends_list) >= 10: break if not elements.MatchHistoryButton(driver): driver.back() elements.MatchStopEnsureButton(driver).click() ret = elements.MatchHistoryButton(driver) return ActionResult(ret, "match friends")
def new_user_popup_handle(driver): for _ in range(2): if elements.MatchHomeButton(driver): break if elements.NewUserGiftPopupPurchase(driver): elements.NewUserGiftPopupPurchaseClose(driver).click() elif elements.NewUserGiftPopupRatingBar(driver): elements.NewUserGiftPopupRatingBar(driver).click() elements.NewUserGiftPopupRatingCancel(driver).click() elif elements.GenderFilterPopupClose(driver): elements.GenderFilterPopupClose(driver).click() return ActionResult(elements.MatchHomeButton(driver), "new user popup handle")
def signup_with_email(driver, data): elements.MoreOptions(driver).click() time.sleep(1) elements.SignWithEmail(driver).click() elements.SignEmailInput(driver).input_text(data["email"]) pwdinput = elements.SignPasswdInput(driver) pwdinput.input_text(data["passwd"]) # driver.back() elements.SignWithEmailNextButton(driver).click() elements.SignNameSettingInput(driver).input_text(data["name"]) elements.SignBirthdayInput(driver).click() elements.SignBirthdayInputDone(driver).click() if data["gender"] == "male": elements.SignMaleCheckbox(driver).click() else: elements.SignFemaleCheckbox(driver).click() elements.SignConfirm(driver).click() ret = False if elements.MatchHomeButton(driver) or \ elements.GenderFilterPopupClose(driver) or \ elements.NewUserGiftPopupPurchase(driver) or \ elements.NewUserGiftPopupRatingBar(driver): ret = True return ActionResult(ret, "sign with email")
def new_user_popup_test(driver): # signup_with_email(driver,data) # new_user_guide_check(driver) popup_result = [] for i in range(1, 101): restart_app(driver) time.sleep(3) if elements.MatchHomeButton(driver): logger.info("no popup element") continue for _ in range(3): no_popup = False for ele_class in [ elements.NewUserGiftPopupPurchase, elements.NewUserGiftPopupRatingBar, elements.GenderFilterPopupClose ]: ele_instance = ele_class(driver) if ele_instance: logger.info("[%d] --> (%s)" % (i, ele_class(driver).ele_name)) popup_result.append((i, ele_class(driver).ele_name)) # close Popup if isinstance(ele_instance, elements.NewUserGiftPopupPurchase): elements.NewUserGiftPopupPurchaseClose(driver).click() elif isinstance(ele_instance, elements.NewUserGiftPopupRatingBar): elements.NewUserGiftPopupRatingBar(driver).click() elements.NewUserGiftPopupRatingCancel(driver).click() elif isinstance(ele_instance, elements.GenderFilterPopupClose): elements.GenderFilterPopupClose(driver).click() no_popup = elements.MatchHomeButton(driver) if no_popup: break if no_popup: break # logger.info("no popup element") logger.info(str(popup_result)) return ActionResult(True, "new user popup test")
def new_user_guide_check(driver): time.sleep(2) ret = False if elements.NewUserGuideClose(driver): elements.NewUserGuideClose(driver).click() elements.NewUserGuideMatchTips(driver).click() driver.back() elements.MatchStopEnsureButton(driver, 2, 0.2).click() ret = True else: ret = elements.MatchHomeButton(driver) time.sleep(3) return ActionResult(ret, "new user guide check")
def restart_app(driver): logger.info("restart app") driver.close_app() driver.launch_app() for _ in range(6): skipfirstbutton = elements.SkipFirstButton(driver) if skipfirstbutton: try: skipfirstbutton.click() except Exception as e: logger.warn("click element fail. reason: %s" % e) finally: break elif elements.MatchHomeButton(driver) or \ elements.NewUserGiftPopupPurchaseClose(driver) or \ elements.GenderFilterPopupClose(driver) or \ elements.NewUserGiftPopupRatingBar(driver) or\ elements.SignWithFacebook(driver): break
def login_with_email(driver, data): elements.MoreOptions(driver).click() elements.LoginWithEmail(driver).click() elements.SignEmailInput(driver).input_text(data["email"]) elements.SignPasswdInput(driver).input_text(data["passwd"]) # driver.back() elements.LoginWithEmailConfirm(driver).click() time.sleep(3) ret = False if elements.MatchHomeButton(driver) or \ elements.GenderFilterPopupClose(driver) or \ elements.NewUserGiftPopupPurchase(driver) or \ elements.NewUserGiftPopupRatingBar(driver)or\ elements.NewUserGuideClose(driver) or\ elements.PermissionAllowButton(driver): ret = True return ActionResult(ret, "login with email")
def pornographic_closure(driver, data): report = { "Account": data["report"]["Account"], "MatchedUserID": None, "UserID": data["report"]["UserID"], "Identity": data["report"]["Identity"], "VideoTimes": None, # "IsSnapshot":None, "SnapshotTimes": None, "VideoStartTime": None, "FirstSnapshortTime": None, "LastSnapshotTime": None, "IsClosure": None, "IsUnlock": None, "ClosureTime": None, "CoinsBeforeUnlock": None, "CoinsAfterUnlock": None, "ClosureTimes": None, "UnlockPrice": None, "DeductionResult": None } elements.UserHomeButton(driver).click() coin_number = int(elements.MatchPageCoinsElement(driver).text) elements.MatchHomeButton(driver).click() logger.info("before match coin number: %s" % coin_number) if elements.MatchPornographicTestCheckBox(driver).element.get_attribute( "checked") == 'false': elements.MatchPornographicTestCheckBox(driver).click() match_gender_filter(driver, data) time.sleep(1) end_time = time.time() + data["match_time_seconds"] lock_times = 0 first_video = True video_times = 0 remote_user_id = "" tmp_report = copy.deepcopy(report) elements.MatchHomeButton(driver).click() while time.time() < end_time and lock_times < 4: if elements.MatchInfoElement(driver): logger.info("video connect success.") video_times += 1 if first_video: logger.info("first video not save [%s]" % video_times) tmp_report = pornographic_closure_report_info( driver, tmp_report) tmp_report["VideoTimes"] = video_times first_video = False else: logger.info("not first video save [%s]" % video_times) tmp_report["IsClosure"] = False settings.thread_pool.submit(settings.closure_report.append, tmp_report, 3.25) tmp_report = copy.deepcopy(report) tmp_report = pornographic_closure_report_info( driver, tmp_report) tmp_report["VideoTimes"] = video_times pornographic_closure_hangup(driver, data) elif elements.MatchPornographicPopUpElement(driver): logger.info("closure with pornographic") tmp_report["VideoTimes"] = video_times tmp_report["IsClosure"] = True tmp_report["ClosureTimes"] = lock_times + 1 tmp_report[ "ClosureTime"] = elements.MatchPornographicClosureTimeElement( driver).text # tmp_report["IsSnaphot"] = "true" lock_times += 1 if elements.MatchPornographicPopUpUnlock(driver): tmp_report["IsUnlock"] = True elements.MatchPornographicPopUpCancel(driver).click() elements.UserHomeButton(driver).click() coin_number = int(elements.MatchPageCoinsElement(driver).text) elements.MatchHomeButton(driver).click() tmp_report["CoinsBeforeUnlock"] = coin_number logger.info("Coin Number: %s" % coin_number) elements.MatchHomeButton(driver).click() elements.MatchPornographicPopUpUnlock(driver, 6, 1).click() unlock_price_tips = elements.MatchPornographicUnlockCoins( driver).text unlock_price = re.search( r'\d{1,}', unlock_price_tips).group(0) if re.search( r'\d{1,}', unlock_price_tips) else None logger.info(unlock_price_tips) # unlock price tmp_report["UnlockPrice"] = unlock_price elements.MatchPornographicPopUpUnlock(driver).click() time.sleep(0.5) driver.back() time.sleep(0.2) elements.MatchStopEnsureButton(driver).click() # common.restart_app(driver) # sign.new_user_popup_handle(driver) if elements.MatchPornographicTestCheckBox( driver).element.get_attribute("checked") == 'false': elements.MatchPornographicTestCheckBox(driver).click() elements.UserHomeButton(driver).click() temp_coin_number = int( elements.MatchPageCoinsElement(driver).text) elements.MatchHomeButton(driver).click() logger.info("current coin number: %s" % temp_coin_number) tmp_report["CoinsAfterUnlock"] = temp_coin_number if int(unlock_price) == coin_number - temp_coin_number: tmp_report["DeductionResult"] = True else: tmp_report["DeductionResult"] = False coin_number = temp_coin_number logger.info("Coin Number: %s" % coin_number) elements.MatchHomeButton(driver).click() first_video = True else: tmp_report["IsUnlock"] = False elements.MatchPornographicPopUpCancel(driver).click() elements.MatchHomeButton(driver).click() elements.MatchHomeButton(driver).click() settings.thread_pool.submit(settings.closure_report.append, tmp_report, 3.25) tmp_report = copy.deepcopy(report) elif elements.MatchPornographicAlert(driver): logger.info("closure alert with pornographic") elements.MatchPornographicAlert(driver).click() driver.close_app()
def match_performance(driver, data): if not elements.UserHomeButton(driver): elements.MatchHomeButton(driver).click() match_gender_filter(driver, data) match_region_filter(driver, data) #start match elements.MatchHomeButton(driver).click() start_time = float( time.mktime( time.strptime(driver.device_time, '%a %b %d %H:%M:%S CST %Y'))) current_time = time.time() while time.time() < (current_time + data["match_time_seconds"]): ret = copy.deepcopy(data["report"]) vstime = time.time() if elements.VideoingQuit(driver, 1): vtime = time.time() - vstime start_time += vtime logger.info("connect success,start time (%s)" % start_time) ret["MatchResult"] = 1 ret["VideoResult"] = 1 c_time = time.mktime( time.strptime(driver.device_time, '%a %b %d %H:%M:%S CST %Y')) match_info = "" for _ in range(2): match_info = elements.MatchInfoElement(driver, 1).text if match_info: break if match_info: reqtimes, matcheduid, match_time = match_info.split("|") ret["RequestTimes"] = int(reqtimes) if re.match( r'^\d{1,}$', reqtimes) else None ret["MatchedUserID"] = int(matcheduid) if re.match( r'^\d{1,}$', matcheduid) else None faild_video_ele = elements.MatchVideoErrorInfoElement( driver, 1) if not faild_video_ele: ret["MatchSpacingTime"] = ( int(match_time) / 1000 - start_time) if (int(match_time) / 1000 - start_time) > 0 else 1.0 ret["VideoSpacingTime"] = ( c_time - start_time) if (c_time - start_time) > 0 else 1.1 else: fail_video_text = "" for _ in range(2): fail_video_text = elements.MatchVideoErrorInfoElement( driver, 1).text if fail_video_text: break if fail_video_text: _start_time = int( fail_video_text.split(",")[-1].split("|") [-1]) / 1000 + vtime ret["MatchSpacingTime"] = ( int(match_time) / 1000 - _start_time) if (int(match_time) / 1000 - _start_time) > 0 else 1.0 ret["VideoSpacingTime"] = ( c_time - _start_time) if (c_time - _start_time) > 0 else 1.1 settings.thread_pool.submit(put_connect_fail, data, fail_video_text, start_time) # fail_job = Thread(target=put_connect_fail,args=(data, fail_video_text, start_time)) # fail_job.start() else: ret["MatchSpacingTime"] = ( int(match_time) / 1000 - start_time) if (int(match_time) / 1000 - start_time) > 0 else 1.0 ret["VideoSpacingTime"] = ( c_time - start_time) if (c_time - start_time) > 0 else 1.1 settings.thread_pool.submit(settings.perf_report.append, ret, 3.25) # report_job = Thread(target=settings.perf_report.append,args=(ret,2.25)) # report_job.start() match_video_quit(driver, data) start_time = float( time.mktime( time.strptime(driver.device_time, '%a %b %d %H:%M:%S CST %Y'))) time.sleep(2) driver.close_app() return ActionResult(True, "match performance")