def test_04_hasregister_again(self): """已注册的号码重新注册""" try: # 已注册的号码 all_phone = Mysql().sql_result('select username from user') tel = random.choice(all_phone)[0] ele_mobile = self.driver.find_element_by_id("et_mobile") ele_code = self.driver.find_element_by_id('et_code') ele_get_code = self.driver.find_element(By.ID, "btn_get_code") ele_nikename = self.driver.find_element(By.ID, "et_nickname") ele_password = self.driver.find_element_by_id('et_password') ele_commit = self.driver.find_element_by_id('btn_register') req = Four_Vesion_Api().sendAuthenticationCode_112(tel) time.sleep(0.5) db_code = Mysql().reslut_replace( f'SELECT message FROM sms_send_his WHERE phone={tel} ORDER BY id DESC LIMIT 1' ) code = re.findall('验证码是(.*),5分钟', db_code) code = code[0] ele_mobile.clear() ele_mobile.send_keys(tel) ele_code.clear() ele_code.send_keys(code) ele_nikename.clear() ele_nikename.send_keys(Public_Function().random_name(3)) pwd = '123456' ele_password.clear() ele_password.send_keys(pwd) ele_commit.click() assert self.driver.current_activity == '.activity.MobileRegActivity', u"已注册的号码再次注册功能正常" except Exception as e: raise e
def test_03_except_password_register(self): """密码长度不满足要求""" try: # 已注册的号码 all_phone = Mysql().sql_result('select username from user') while True: tel = random.randint(19800000000, 19899999999) if (str(tel), ) not in all_phone: break ele_mobile = self.driver.find_element_by_id("et_mobile") ele_code = self.driver.find_element_by_id('et_code') ele_get_code = self.driver.find_element(By.ID, "btn_get_code") ele_nikename = self.driver.find_element(By.ID, "et_nickname") ele_password = self.driver.find_element_by_id('et_password') ele_commit = self.driver.find_element_by_id('btn_register') req = Four_Vesion_Api().sendAuthenticationCode_112(tel) time.sleep(0.5) db_code = Mysql().reslut_replace( f'SELECT message FROM sms_send_his WHERE phone={tel} ORDER BY id DESC LIMIT 1' ) code = re.findall('验证码是(.*),5分钟', db_code) code = code[0] ele_mobile.clear() ele_mobile.send_keys(tel) ele_code.clear() ele_code.send_keys(code) ele_nikename.clear() ele_nikename.send_keys(Public_Function().random_name(3)) ele_commit.click() assert self.driver.current_activity == '.activity.MobileRegActivity', u"密码为空时注册功能正常" sort_pwd = '12345' long_pwd = '12345123451234512' ele_password.clear() ele_password.send_keys(sort_pwd) ele_commit.click() long_name = Public_Function().random_name(16) assert self.driver.current_activity == '.activity.MobileRegActivity', u"密码长度低于6位时注册功能正常" ele_password.clear() if not Public_Function().is_emulator(): ele_password.send_keys(long_pwd) ele_commit.click() assert self.driver.current_activity == '.activity.MobileRegActivity', u"密码长度高于16位时注册功能正常" ele_nikename.clear() ele_nikename.send_keys(long_name) ele_password.send_keys("123456") ele_commit.click() assert self.driver.current_activity == '.activity.MobileRegActivity', u"昵称长度高于16位时注册功能正常" except Exception as e: raise e
def test_05_errorcode_register(self): """验证码不正确进行注册""" try: all_phone = Mysql().sql_result('select username from user') while True: tel = random.randint(19800000000, 19899999999) if (str(tel), ) not in all_phone: break ele_mobile = self.driver.find_element_by_id("et_mobile") ele_code = self.driver.find_element_by_id('et_code') ele_get_code = self.driver.find_element(By.ID, "btn_get_code") ele_nikename = self.driver.find_element(By.ID, "et_nickname") ele_password = self.driver.find_element_by_id('et_password') ele_commit = self.driver.find_element_by_id('btn_register') code = ''.join(random.sample(string.digits, 6)) ele_mobile.clear() ele_mobile.send_keys(tel) ele_code.clear() ele_code.send_keys(code) ele_nikename.clear() ele_nikename.send_keys(Public_Function().random_name(3)) pwd = '123456' ele_password.clear() ele_password.send_keys(pwd) ele_commit.click() assert self.driver.current_activity == '.activity.MobileRegActivity', u"验证码正确时注册功能正常" except Exception as e: raise e
def test_001_init_search(self): """搜索默认界面""" try: ele_search_btn = self.driver.find_element(By.ID, Config(HomePage).get("search_button")) # 搜索按钮 ele_search_btn.click() assert self.driver.current_activity == ".activity.JianghuSearchWebViewActivity", u"搜索页面activity正常" assert PublicShell(self.driver).is_elementExits(By.XPATH, "//*[@text='热门搜索']") == True, u'热门搜索存在' assert PublicShell(self.driver).is_elementExits(By.ID, "toppic_radio_button") == True, u'话题存在' assert PublicShell(self.driver).is_elementExits(By.ID, "collection_radio_button") == True, u'藏品存在' assert PublicShell(self.driver).is_elementExits(By.ID, "friden_radio_button") == True, u'藏友存在' assert PublicShell(self.driver).is_elementExits(By.ID, "guild_radio_button") == True, u'门派存在' topic_bar = self.driver.find_element(By.ID, "toppic_radio_button") assert topic_bar.get_attribute('checked') == "true", u"初始页面话题默认被选中" # 热门搜索内容 hot_search_text = self.driver.find_elements_by_xpath \ ('//*[@resource-id="cn.dcpai.auction:id/gridView_hot"]/android.widget.TextView') # 数据库存储热门搜索内容 database_search_text = Mysql().sql_result \ ('SELECT `value` from param WHERE `type`="HOT_SEARCH_KEYWORD" ORDER BY param_order') assert len(hot_search_text) == len(database_search_text), u"热搜内容个数和数据库一致" for i in range(len(database_search_text)): hot_text = hot_search_text[i].text db_hot_text = database_search_text[i][0] assert hot_text == db_hot_text, u"热搜内容一致" except Exception as e: raise e
def test_06_register(self): """正常注册""" try: all_phone = Mysql().sql_result('select username from user') while True: tel = random.randint(19800000000, 19899999999) if (str(tel), ) not in all_phone: break ele_mobile = self.driver.find_element_by_id("et_mobile") ele_code = self.driver.find_element_by_id('et_code') ele_get_code = self.driver.find_element(By.ID, "btn_get_code") ele_nikename = self.driver.find_element(By.ID, "et_nickname") ele_password = self.driver.find_element_by_id('et_password') ele_commit = self.driver.find_element_by_id('btn_register') ele_mobile.clear() ele_mobile.send_keys(tel) req = Four_Vesion_Api().sendAuthenticationCode_112(tel) time.sleep(0.5) db_code = Mysql().reslut_replace( f'SELECT message FROM sms_send_his WHERE phone={tel} ORDER BY id DESC LIMIT 1' ) code = re.findall('验证码是(.*),5分钟', db_code) code = code[0] ele_code.clear() ele_code.send_keys(code) ele_password.clear() ele_password.send_keys('123456') ele_nikename.clear() nikename = Public_Function().random_name(3) ele_nikename.send_keys(nikename) ele_commit.click() assert self.driver.current_activity == '.MainActivity', u"注册成功后返回登主界面" user_nickname = self.driver.find_element_by_id('tv_nickname') assert user_nickname.text == nikename except Exception as e: raise e
def test_001_into_login(self): """进入登录界面""" ele = self.driver.find_element(By.ID, 'cn.dcpai.auction:id/mine') # 按钮--我的 ele.click() time.sleep(0.5) current_activity = self.driver.current_activity assert current_activity in [ ".activity.LoginMainActivity", ".MainActivity" ] # 点击我的后进入的界面只能在对应的activity中 try: if current_activity == '.activity.LoginMainActivity': weixin_login_button = self.driver.find_element_by_id( 'btn_weixin_login') # 微信登录按钮 user_login_button = self.driver.find_element_by_id( 'btn_mobile_login') # 账号登录按钮 new_user_register = self.driver.find_element_by_id( 'tv_user_reg') # 新用户注册 assert PublicShell(self.driver).is_elementExits( By.XPATH, "//*[@text='快速登录']") == True # 文字-快速登陆存在 else: user_icon = self.driver.find_element_by_id('iv_avatar') # 用户头像 user_nickname = self.driver.find_element_by_id( 'tv_nickname') # 用户昵称 user_num = self.driver.find_element_by_id( 'tv_account') # 用户龖藏号 while True: get_log() user_icon.click() self.driver.back() break pidList = Config(Pid_PATH).get('Pid') for pid in pidList: end_log(pid) with open(self.logpath, 'r', errors='ignore') as f: for line in f.readlines(): if 'http://train-h5.dcpai.cn/app/interface/mobile/getMemberDetailInfo_112 response is' in line: memberId = re.findall('"id":"(.*?)",', line) break user_info = Mysql().sql_result( f'select name, zang_num from user where id={memberId[0]}') assert user_nickname.text == user_info[0][0], u"用户昵称显示一致" assert user_num.text.split( ":")[1].strip() == user_info[0][1], u"龖藏号一致" assert PublicShell(self.driver).is_elementExits( By.XPATH, "//*[@text='我的订单']") == True, u"我的订单元素存在" assert PublicShell(self.driver).is_elementExits( By.ID, "tv_obligation") == True, u"我的订单-待付款元素存在" assert PublicShell(self.driver).is_elementExits( By.ID, "tv_wait_send_out") == True, u"我的订单-待发货元素存在" assert PublicShell(self.driver).is_elementExits( By.ID, "tv_wait_take") == True, u"我的订单-待收货元素存在" assert PublicShell(self.driver).is_elementExits( By.ID, "tv_wait_comment") == True, u"我的订单-待评价元素存在" assert PublicShell(self.driver).is_elementExits( By.ID, "tv_aftermarket") == True, u"我的订单-退款|售后元素存在" assert PublicShell(self.driver).is_elementExits( By.ID, "mine_msg") == True, u"消息按钮存在" assert PublicShell(self.driver).is_elementExits( By.XPATH, "//*[@text='我的钱包']") == True, u"我的钱包元素存在" assert PublicShell(self.driver).is_elementExits( By.XPATH, "//*[@text='可用余额']") == True, u"我的钱包--可用余额元素存在" assert PublicShell(self.driver).is_elementExits( By.XPATH, "//*[@text='待入账']") == True, u"我的钱包--待入账元素存在" assert PublicShell(self.driver).is_elementExits( By.XPATH, "//*[@text='保证金']") == True, u"我的钱包--保证金元素存在" assert PublicShell(self.driver).is_elementExits( By.XPATH, "//*[@text='龙珠']") == True, u"我的钱包--龙珠元素存在" assert PublicShell(self.driver).is_elementExits( By.XPATH, "//*[@text='提现']") == True, u"我的钱包--提现元素存在" element_user_bar = self.driver.find_element_by_id( 'rl_user_bar') # 用户信息条 element_user_bar.click() time.sleep(0.5) PublicShell(self.driver).up_swipe() assert '.activity.MyInfoActivity' == self.driver.current_activity, u"我的资料界面activity正常" logout = self.driver.find_element_by_id( 'cn.dcpai.auction:id/btn_logout') logout.click() time.sleep(1) self.test_001_into_login() except Exception as e: raise e
def test_005_right_login(self, username, password): """正常登录""" try: phone = WebDriverWait(self.driver, timeout=5).until( EC.visibility_of_element_located((By.ID, "et_mobile")), message="登录手机号码") pwd = WebDriverWait(self.driver, timeout=5).until( EC.visibility_of_element_located((By.ID, "et_password")), message="登录密码") login = WebDriverWait(self.driver, timeout=5).until( EC.visibility_of_element_located( (By.XPATH, "//*[@class='android.widget.Button'][@text='登录']")), message="登录按钮") is_code = PublicShell(self.driver).is_elementExits( By.ID, "auth_code_input") if is_code: code = WebDriverWait(self.driver, timeout=5).until( EC.visibility_of_element_located((By.ID, "btn_get_code")), message="验证码") code_input = self.driver.find_element(By.ID, "auth_code_input") img_name = os.path.join(self.IMG_PATH, "code.png") self.driver.save_screenshot(img_name) cut_img(img_name, code.location['x'], code.location['y'], code.location['x'] + code.size['width'], code.location['y'] + code.size['height']) code_text = ReadImg(img_name, 175).get() # 因为技术不成熟导致需要多次刷新验证码,直到能够识别出来方可 while True: # 读取出来的code码长度为4且只能是数字和字母组成 if len(code_text) == 4 and code_text.isalnum(): break else: code.click() self.driver.implicitly_wait(1) self.driver.save_screenshot(img_name) cut_img(img_name, code.location['x'], code.location['y'], code.location['x'] + code.size['width'], code.location['y'] + code.size['height']) code_text = ReadImg(img_name, 175).get() code_input.clear() code_input.send_keys(code_text) get_log() phone.send_keys(username) pwd.send_keys(password) self.driver.implicitly_wait(1) login.click() time.sleep(0.2) pidList = Config(Pid_PATH).get('Pid') for pid in pidList: end_log(pid) assert self.driver.current_activity == ".MainActivity", u"已登录情况下当前为MainActivity" user_icon = self.driver.find_element_by_id('iv_avatar') user_nickname = self.driver.find_element_by_id('tv_nickname') user_num = self.driver.find_element_by_id('tv_account') with open(self.logpath, 'r', errors='ignore') as f: for line in f.readlines(): if self.host + 'interface/mobile/pmall/loginByPhone_220 response is' in line: memberId = re.findall('"id":"(.*?)",', line) break user_info = Mysql().sql_result( f'select name, zang_num from user where id={memberId[0]}') assert user_nickname.text == user_info[0][0] assert user_num.text.split(":")[1].strip() == user_info[0][1] except Exception as e: raise e