def test01_edit_goods(self): # try: # 定位个人中心,然后点击 goods = B.find_element(P.goods) B.click(goods) # 定位个人中心页面中的个人中心字样 time.sleep(2) goodscentre = B.find_element(P.goodscentre) B.click(goodscentre) time.sleep(2) goodsdata = B.find_element(P.goodsdata) B.click(goodsdata) time.sleep(3) editbtn = B.find_element(P.edit) B.click(editbtn) time.sleep(1) # ran = random.choice('abcdefghiklmnopqrstuvwxyz') B.send_keys(B.find_element(P.goodsname), ran) B.click(B.find_element(P.gencode)) B.send_keys(B.find_element(P.priceout), ran) B.scroll() B.click(B.find_element(P.submit)) time.sleep(1) add_success_text = B.get_text(P.add_success) print(add_success_text) try: assert add_success_text == "修改成功" except Exception as e: # raise NameError("当前页面不包含%s" % (login_sucees_text)) log.error('用例%s执行不通过' % (sys._getframe().f_code.co_name)) # # format格式化,把case中的title写入{}中 log.exception(e) raise e else: log.info('用例%s执行通过' % (sys._getframe().f_code.co_name))
def test01_browse_goods(self): # try: # 定位个人中心,然后点击 goods = B.find_element(P.goods) B.click(goods) # 定位个人中心页面中的个人中心字样 time.sleep(2) goodscentre = B.find_element(P.goodscentre) B.click(goodscentre) time.sleep(2) goodsdata = B.find_element(P.goodsdata) B.click(goodsdata) time.sleep(3) offline_text = B.get_text(P.offlinegoods) print(offline_text) try: assert offline_text == "线下平台商品" except Exception as e: # raise NameError("当前页面不包含%s" % (login_sucees_text)) log.error('用例%s执行不通过' % (sys._getframe().f_code.co_name)) # # format格式化,把case中的title写入{}中 log.exception(e) raise e else: log.info('用例%s执行通过' % (sys._getframe().f_code.co_name))
def findeles (self,local): if isinstance(local,tuple): print('正在通过>>>>'+local[0]+'查找元素>>>>'+local[1]) log.info('正在通过>>>>'+local[0]+'查找元素>>>>'+local[1]) elements = WebDriverWait(self.driver,timeout=10).until(lambda x:x.find_elements(*local)) else : print('local参数必须是元组') return elements
def test01_delete_online_goods(self): # try: # 定位个人中心,然后点击 goods = B.find_element(P.goods) B.click(goods) # 定位个人中心页面中的个人中心字样 time.sleep(2) goodscentre = B.find_element(P.goodscentre) B.click(goodscentre) time.sleep(2) goodsdata = B.find_element(P.goodsdata) B.click(goodsdata) time.sleep(3) B.click(B.find_element(P.onlinegoods_platform)) time.sleep(1) B.click(B.find_element(P.gouxuan_online)) time.sleep(1) B.hold(B.find_element(P.piliang_online)) time.sleep(1) #下架 B.click(B.find_element(P.piliang_xiajia)) time.sleep(1) # B.refresh() time.sleep(2) # B.click(B.find_element(P.gouxuan_online)) # time.sleep(2) a = B.find_element(P.piliang_2) B.hold(a) #删除 time.sleep(1) B.click(B.find_element(P.piliang_delete)) time.sleep(1) # B.click(B.find_element(P.delete_alert)) B.click(B.find_element(P.delete_confirm)) del_suc_text = B.get_text(P.del_suc_text) print(del_suc_text) try: assert del_suc_text == "商品删除成功" except Exception as e: # raise NameError("当前页面不包含%s" % (login_sucees_text)) log.error('用例%s执行不通过' % (sys._getframe().f_code.co_name)) # # format格式化,把case中的title写入{}中 log.exception(e) raise e else: log.info('用例%s执行通过' % (sys._getframe().f_code.co_name))
def test01_add_online_goods(self): # try: # 定位个人中心,然后点击 goods = B.find_element(P.goods) B.click(goods) # 定位个人中心页面中的个人中心字样 time.sleep(2) goodscentre = B.find_element(P.goodscentre) B.click(goodscentre) time.sleep(2) goodsdata = B.find_element(P.goodsdata) B.click(goodsdata) time.sleep(3) B.click(B.find_element(P.onlinegoods_platform)) addonline = B.find_element(P.add_online) B.click(addonline) time.sleep(1) B.click(B.find_element(P.select_goods)) time.sleep(2) B.click(B.find_element(P.select_goods_confirm)) time.sleep(2) B.scroll() time.sleep(1) B.click(B.find_element(P.select_stuff)) time.sleep(2) #先定位到原料下拉框(只定位到了下拉框的中间) yuanliao = B.find_element(P.yuanliao) B.click(yuanliao) # stuff1 = yuanliao.find_element(P.stuff_1) # B.click(stuff1) time.sleep(1) yuanliao2 = B.find_element(P.yuanliao2) B.click(yuanliao2) # stuff_1_1 = B.find_element(P.stuff_1_1) # B.click(stuff_1_1) time.sleep(1) B.click(B.find_element(P.yuanliao3)) # B.click(B.find_element(P.stuff_1_1_1)) B.click(B.find_element(P.submit_add_onlinegoods)) # B.moveto(stuff1) # B.click(stuff1) # stuff2 = B.find_element(P.stuff_1_1) # B.moveto(stuff2) # B.click(stuff2) # stuff3 = B.find_element(P.stuff_1_1_1) # B.moveto(stuff3) # B.click(stuff3) # B.click(B.find_element(P.add_online_confirm)) # ran = random.choice('abcdefghiklmnopqrstuvwxyz') # B.send_keys(B.find_element(P.goodsname), ran) # B.click(B.find_element(P.gencode)) # B.send_keys(B.find_element(P.priceout), ran) # B.send_keys(B.find_element(P.pricein), ran) # B.send_keys(B.find_element(P.count), ran) # B.scroll() # B.click(B.find_element(P.submit)) # time.sleep(1) # add_success_text = B.get_text(P.add_success) # print(add_success_text) time.sleep(1) submit_text = B.get_text(P.submit_online_alert) print(submit_text) try: assert submit_text == "添加成功" except Exception as e: # raise NameError("当前页面不包含%s" % (login_sucees_text)) log.error('用例%s执行不通过' % (sys._getframe().f_code.co_name)) # # format格式化,把case中的title写入{}中 log.exception(e) raise e else: log.info('用例%s执行通过' % (sys._getframe().f_code.co_name))
def test01_login(self): ''' 第一个用例为登录,需要打开浏览器,输入网址并登录; 后续如果不用重新打开浏览器,则不用调用get_driver :return: ''' #调用set好的driver,后续其他用例如果需要重新打开此浏览器也可如此调用,浏览器没关则不用 driver = B.get_driver() B.wait(3) # driver.get(url) # BaseTestCaase.get_driver().get(url) driver.maximize_window() driver.get(url) #打开测试网址 B.wait(20) #输入用户名 user = B.find_element(P.uservalue) #此处的usernamenum是从excel读取的 B.send_keys(user, usernamenum) #输入验证码 # codevalue = ("css","#loginForm > div.verification > input") # code = BaseTestCaase.find_element(P.codevalue) # BaseTestCaase.send_keys(code,codenum) #输入密码 # pwdvalue = ("css","#loginForm > div.password-login > div.password-wrap > input") pwd = B.find_element(P.pwdvalue) B.send_keys(pwd, pwdnum) # 点击同意协议 # agreevalue = ("css","#loginForm > div.remember-agree > div > label") # agree = BaseTestCaase.find_element(P.agreevalue) # BaseTestCaase.click(agree) # 点击确定提交 # submitvalue = ("css","#loginForm > button") # submit = BaseTestCaase.find_element(P.submitvalue) # BaseTestCaase.click(submit) # 点击登录按钮 # 登录按钮的定位方式和值 # loginvalue = ("css","body > section.header-container > header > div.header-nav-wrap > nav > ul > li:nth-child(7) > a:nth-child(1)") # 定位登录按钮(参数为上方面的login或者P中的对应元素值,下面方式一样) loginbutton = B.find_element(P.loginvalue) # 点击登录按钮(参数为上面的定位到的登录按钮loginbutton) B.click(loginbutton) time.sleep(1) #登录成功弹窗 # login_success = B.find_element(P.submitvalue) # B.click(login_success) login_sucees_text = B.get_text(P.submitvalue) print(login_sucees_text) #断言 #获取提交后弹窗文字 #显式等待 # submit = BaseTestCaase.find_element(P.submitvalue) # submit_alert = BaseTestCaase.webdriverwait(submit) # # submit_alert = BaseTestCaase.find_element(P.submitvalue) # submit_text = submit_alert.text() # print(submit_text) # submit_text = BaseTestCaase.get_text(submit_alert) # print(submit_text) try: assert login_sucees_text == login_success except Exception as e: RD.write_data(row=2, column=6, value='未通过') # raise NameError("当前页面不包含%s" % (login_sucees_text)) log.error('用例%s执行不通过' % (sys._getframe().f_code.co_name)) # # format格式化,把case中的title写入{}中 log.exception(e) raise e # 抛出异常 # 手动触发异常 else: # 否则就正常,正常又如何 log.info('用例%s执行通过' % (sys._getframe().f_code.co_name)) RD.write_data(row=2, column=6, value='通过')