def test4(self): # 获取充值前代币的储值 a = MySql.db_Query_233(self, dict['mysql']['datebase233'], dict['mysql']['查询代币']) b = re.findall(r"['](.+?)[.]", str(a)) db_befor = b[0] time.sleep(1) # 获取充值前预存款的储值 mean.wechat_login(self) time.sleep(1) mean.swipe_to_down(self) time.sleep(1) yck_befor = mean.get_text(self, dict['element']['预存款储值']) time.sleep(1) # 登录盈客宝充值代币 mean.wechat_login(self) mean.swipe_to_down(self) mean.click(self, dict['element']['代币充值按钮']) time.sleep(1) # 选择充值套餐 mean.click(self, dict['element']['商品100代币']) time.sleep(1) # 选取预存款支付 mean.click(self, dict['element']['预存款支付']) time.sleep(1) # 点击支付 mean.click(self, dict['element']['支付按钮']) time.sleep(1) # 输入会员密码 mean.input(self, dict['element']['会员密码输入框'], dict['element']['会员密码']) time.sleep(1) # 点击【确定】 mean.click(self, dict['element']['会员密码确定按钮']) time.sleep(1) # 充值后代币的储值 c = MySql.db_Query_233(self, 'YCHMALL', dict['mysql']['查询代币']) d = re.findall(r"['](.+?)[.]", str(c)) db_after = d[0] # 充值后预存款储值 time.sleep(2) mean.click(self, dict['element']['订单完成返回首页按钮']) time.sleep(1) mean.swipe_to_down(self) time.sleep(1) yck_after = mean.get_text(self, dict['element']['预存款储值']) self.driver.close() # 断言 try: assert db_befor + int(100) == db_after and yck_befor - float( 0.01) == yck_after print('代币充值成功,预存款扣款正确!') except Exception as error: print('代币充值失败!', error)
def environmentPrepar(self): mobile_emulation = {'deviceName': 'iPhone 5'} options = webdriver.ChromeOptions() options.add_experimental_option("mobileEmulation", mobile_emulation) self.driver = webdriver.Chrome(executable_path='chromedriver.exe', chrome_options=options) self.driver.implicitly_wait(15) self.driver.maximize_window() self.driver.get(dict_load['url']['C端URL']) sleep(1) loc = (By.CSS_SELECTOR, dict_load['C端页面元素']['用户积分']) WebDriverWait(self.driver, 10).until( expected_conditions.visibility_of_element_located(loc)) u1 = means.get_text(self, 'css', dict_load['C端页面元素']['用户积分']) u2 = re.findall(r"(......+?)", str(u1)) u3 = str(u2).replace(',', '') # C端用户下单前用户积分 u4 = u3[2:-2] # 0>>> table.cretaTable(self) table.write(self, 0, u4) sleep(4) if int(u4) <= 4000: print('用户积分不足,请充值积分!') elif int(u4) > 4000: print('积分充足!准备执行用例......') else: print('用户积分为0,请检查环境!') # 数据库初始化 self.db = pymysql.connect( host=dict_load['mysql']['host'], user=dict_load['mysql']['user'], password=dict_load['mysql']['pwd'], ) try: self.db print('数据库连接成功!准备执行用例......') except: print('数据库连接失败!请检查!') self.cursor = self.db.cursor() self.cursor.execute('SHOW DATABASES') c = MySql.db_Query(self, dict_load['mysql']['商家菜籽db'], dict_load['mysql']['查询商家菜籽sql']) c1 = re.findall(r"[(]'(.......+?).", str(c)) if int(c1[0]) <= 1000000: MySql.db_NotQuery(self, dict_load['mysql']['商家菜籽db'], dict_load['mysql']['加菜籽sql']) print('菜籽充足!准备执行用例......') else: print('菜籽充足!准备执行用例......')
def order_status(self): db_PartnerOrderNO = MySql.db_Query(self, dict_load['mysql']['查询新订单号db'], dict_load['mysql']['查询新订单号sql']) c_OrderNO = table.read(self, 4) assert db_PartnerOrderNO[0] == c_OrderNO # 5>> table.write(self, 5, '待发货')
def test5(self): # 获取充值前代币的储值 a = MySql.db_Query_233(self, dict['mysql']['datebase233'], dict['mysql']['查询代币']) b = re.findall(r"['](.+?)[.]", str(a)) db_befor = b[0] # 获取充值前预存款的储值 mean.wechat_login(self) time.sleep(1) mean.swipe_to_down(self) time.sleep(1) yck_befor = mean.get_text(self, dict['element']['预存款储值']) time.sleep(1) # 登录盈客宝充值代币 mean.click(self, dict['element']['代币充值按钮']) time.sleep(1) # 选择充值套餐 mean.click(self, dict['element']['商品100代币']) time.sleep(1) # 选择微信支付 mean.click(self, dict['element']['微信支付']) time.sleep(1) mean.click(self, dict['element']['支付按钮']) time.sleep(1) mean.input(self, dict['element']['微信支付密码输入框'], dict['element']['微信支付密码']) time.sleep(1) # 获取充值后预存款储值 mean.click(self, dict['element']['订单返回按钮']) time.sleep(1) mean.swipe_to_down(self) time.sleep(1) yck_after = mean.get_text(self, dict['element']['预存款储值']) self.driver.close() # 获取充值后的的代币 c = MySql.db_Query_233(self, dict['mysql']['datebase233'], dict['mysql']['查询代币']) d = re.findall(r"['](.+?)[.]", str(c)) db_after = d[0] # 断言 try: assert db_befor + int(100) == db_after and yck_befor - float( 0.01) == yck_after print('微信充值代币成功!') except Exception as e: print('微信充值代币失败!', e)
def get_JD_values(self): AccessToken = MySql.db_Query(self, dict_load['mysql']['京东预存款db'], dict_load['mysql']['查询京东AccessToken']) url = dict_load['url']['京东预付款URL'] date = {'token': AccessToken} respones = requests.post(url, date) AdvanceDeposit = re.findall(r'"result":"(.+?)"', str(respones.text)) value = AdvanceDeposit[0] return value
def test6(self): # 获取当前金币储值 a = MySql.db_Query_233(self, dict['mysql']['datebase233'], dict['mysql']['查询金币']) b = re.findall(r"['](.+?)[.]", str(a)) jb_befor = b[0] # 获取当前预存款储值 mean.wechat_login(self) time.sleep(1) mean.swipe_to_down(self) time.sleep(1) yck_befor = mean.get_text(self, dict['element']['预存款储值']) time.sleep(1) mean.click(self, dict['element']['金币充值按钮']) time.sleep(1) mean.click(self, dict['element']['商品100金币']) time.sleep(1) mean.click(self, dict['element']['预存款支付']) time.sleep(1) mean.click(self, dict['element']['支付按钮']) time.sleep(1) mean.input(self, dict['element']['会员密码输入框'], dict['element']['会员密码']) time.sleep(1) mean.click(self, dict['element']['会员密码确定按钮']) time.sleep(1) mean.click(self, dict['element']['订单完成返回首页按钮']) time.sleep(1) mean.swipe_to_down(self) time.sleep(1) # 获取充值后预存款余额 yck_after = mean.get_text(self, dict['element']['预存款储值']) # 获取充值后金币储值 c = MySql.db_Query_233(self, dict['mysql']['datebase233'], dict['mysql']['查询金币']) d = re.findall(r"['](.+?)[.]", str(c)) jb_after = d[0] self.driver.close() # 断言 try: assert yck_after + float(0.01) == yck_befor and jb_befor + int( 100) == jb_after print('金币充值成功!') except Exception as err: print('金币充值失败!', err)
def BuyMeal(self): self.driver = webdriver.Chrome() url = dict['B端测试环境']['url'] self.driver.get(url) self.driver.implicitly_wait(15) self.driver.maximize_window() self.driver.find_element_by_css_selector( dict['B端测试环境']['用户名输入框']).send_keys(dict['B端测试环境']['登录用户名']) self.driver.find_element_by_css_selector( dict['B端测试环境']['密码输入框']).send_keys(dict['B端测试环境']['登录密码']) time.sleep(1) self.driver.find_element_by_css_selector(dict['B端测试环境']['登录按钮']).click() time.sleep(2) self.driver.find_element_by_css_selector(dict['B端测试环境']['线上']).click() time.sleep(2) self.driver.switch_to_frame(1) time.sleep(1) self.driver.find_element_by_css_selector(dict['B端测试环境']['线上渠道']).click() time.sleep(1) self.driver.switch_to_default_content() time.sleep(1) self.driver.switch_to_frame(2) self.driver.find_element_by_css_selector(dict['B端测试环境']['盈客宝管理']).click() time.sleep(1) self.driver.switch_to_default_content() self.driver.switch_to_frame(3) self.driver.find_element_by_css_selector(dict['B端测试环境']['会员注册设置']).click() time.sleep(1) # 选择购买入会套餐 self.driver.switch_to_frame(1) self.driver.find_element_by_css_selector(dict['B端测试环境']['购买入会套餐']).click() time.sleep(1) self.driver.find_element_by_xpath(dict['B端测试环境']['超级会员套餐复选框']).click() time.sleep(1) # 保存按钮 self.driver.find_element_by_css_selector( dict['B端测试环境']['入会方式保存按钮']).click() time.sleep(1) self.driver.close() # 断言 # 入会方式:0自动注册入会;1购买超级套餐入会 try: sql = dict['mysql']['查询会员入会方式'] result = MySql.db_Query_233(self, dict['mysql']['datebase233'], sql) result2 = re.findall(r"[(](.+?)[,]", str(result)) wayValues = result2[0] if wayValues == '0': print(r'当前入会方式为:自动注册入会!') elif wayValues == '1': print(r'当前入会方式为:购买超级套餐入会!') except Exception: print('查询入会方式失败!', Exception)
def test(self): print('>>>>>>>>>>>>>>>>>>>未填收货地址 >> 跳转至收货地址填写<<<<<<<<<<<<<<<<<<<<<<') # 环境检测 intializating.initialization.environmentPrepar(self) time.sleep(1) # 清空收货地址 MySql.db_NotQuery(self, dict_load['mysql']['清空收货地址db'], dict_load['mysql']['清空收货地址sql']) time.sleep(1) # 选取商品 get_goods.get_goods(self) time.sleep(1) loc = (By.CSS_SELECTOR, dict_load['商品']['立即兑换']) WebDriverWait(self.driver, 5).until( expected_conditions.visibility_of_element_located(loc)) means.click(self, 'css', dict_load['商品']['立即兑换']) time.sleep(1) # 获取跳转收货地址填写页面截图 means.get_img(self) time.sleep(1) # 获取收货地址页面元素 text = means.get_text(self, 'css', dict_load['C端页面元素']['收货地址页面']) text1 = re.search(r"^(....)", str(text)) text2 = text1.group() time.sleep(1) print( '********************************状态*******************************************' ) print('跳转到页面信息:', format(str(text))) print( '********************************断言*******************************************' ) # 断言 assert text2 == '收货地址' print('用例通过!')
def get_caizi_values(self): c = MySql.db_Query(self, dict_load['mysql']['商家菜籽db'], dict_load['mysql']['查询商家菜籽sql']) c1 = re.findall(r"[(]'(.......+?).", str(c)) return c1[0]
def wipe_data(self): MySql.db_NotQuery(self, dict_load['mysql']['清空所有订单db'], dict_load['mysql']['清空所有订单sql'])
def get_NewOrderNumber_On_db(self): db_PartnerOrderNO = MySql.db_Query(self, dict_load['mysql']['查询新订单号db'], dict_load['mysql']['查询新订单号sql']) db_odd_numbers = re.findall(r"'(.+?)'", str(db_PartnerOrderNO)) return db_odd_numbers[0]
def get_countOrder_values(self): a = MySql.db_Query(self, dict_load['mysql']['商家菜籽db'], dict_load['mysql']['查询用户订单总数sql']) a1 = re.findall(r"[(][(](.+?),", str(a)) return a1[0]
def test2(self): # 手机号注册登录 mean.phone_login(self) self.driver.close() # 断言 page_phoneNumber = self.driver.find_element_by_xpath( '//*[@class="android.view.View" and @index="2"]').text sql = 'SELECT phone FROM MEM_UserBase WHERE Phone =' + str( page_phoneNumber) text1 = MySql.db_Query_200(self, dict['mysql']['datebase200'], sql) text2 = re.findall(r"'(.+?)'", str(text1)) db_phoneNumber = text2[0] try: assert page_phoneNumber == db_phoneNumber print('微信快捷注册登录入会成功!') except Exception as e: print(e) # 清空测试数据 delete_localhost_sql = "DELETE FROM saas_member_test_20190428.MEM_UserBase WHERE Phone = " + str( page_phoneNumber) try: MySql.db_NotQuery_200(self, dict['mysql']['datebase200'], delete_localhost_sql) except Exception as err: print(err) delete_ywpt_sql1 = "update dbo.Mall_Leaguer set Phone=null where Phone = " + str( page_phoneNumber) delete_ywpt_sql2 = "update dbo.Mall_LeaguerApply set PhoneNumber=null where PhoneNumber = " + str( page_phoneNumber) delete_ywpt_sql3 = "DELETE FROM dbo.Ykb_NewMembersGivingLog WHERE Phone = " + str( page_phoneNumber) try: MySql.db_NotQuery_233(self, dict['mysql']['datebase233'], delete_ywpt_sql1) MySql.db_NotQuery_233(self, dict['mysql']['datebase233'], delete_ywpt_sql2) MySql.db_NotQuery_233(self, dict['mysql']['datebase233'], delete_ywpt_sql3) except Exception as err: print(err) # 断言数据是否清空 sql = "select Phone from saas_member_test_20190428.MEM_UserBase WHERE Phone = " + str( page_phoneNumber) sql1 = "select Phone from dbo.Mall_Leaguer where Phone = " + str( page_phoneNumber) sql2 = "select Phone from dbo.Ykb_NewMembersGivingLog where Phone = " + str( page_phoneNumber) sql3 = "select PhoneNumber from dbo.Mall_LeaguerApply where PhoneNumber = " + str( page_phoneNumber) locdb = MySql.db_Query_200(self, dict['mysql']['datebase200'], sql) ywpt1 = MySql.db_Query_233(self, dict['mysql']['datebase233'], sql1) ywpt2 = MySql.db_Query_233(self, dict['mysql']['datebase233'], sql2) ywpt3 = MySql.db_Query_233(self, dict['mysql']['datebase233'], sql3) try: assert locdb == () and ywpt1 == [] and ywpt2 == [] and ywpt3 == [] print('用户数据清除成功!') except Exception as er: print(er)