def login(self, name, password, expect): self.logs.logger.info('调用login()') try: self.logs = log.log_message("登陆页面对象") self.driver.open(self.host + self.home_uri) self.driver.click_text(self.ele_login_but) # self.logs.logger.info('用户名:id为[%s]输入[%s]' % (self.ele_name, name)) self.driver.send_key('id', self.ele_name, name) self.driver.send_key('id', self.ele_pwd, password) self.driver.click('xpath', self.ele_sub) time.sleep(5) if expect == 'true': self.login_su = self.driver.get_text('link_text', self.ele_succeed_msg) self.logs.logger.info('调用login()结束;返回%s' % self.login_su) return self.login_su elif expect == 'false': self.login_err = self.driver.get_text('xpath', self.ele_err_msg) self.logs.logger.info('调用login()结束;返回%s' % self.login_err) return self.login_err else: self.logs.logger.info('输入预期结果不在范围内!') except Exception as e: self.logs.logger.error('用例执行失败,原因:%s' % e)
def setUp(self): # 无头 # options = Options() # options.add_argument('--headless') # options.add_argument('--no-sandbox') # options.add_argument('--disable-gpu') # options.add_argument('--disable-dev-shm-usage') # options.add_argument("--start-maximized") # self.driver = webdriver.Chrome(chrome_options=options) # Windows self.driver = webdriver.Chrome() self.driver.implicitly_wait(15) self.driver.set_page_load_timeout(15) self.driver.set_script_timeout(15) self.driver.maximize_window() self.url = "https://sharpsit.jusdaglobal.com" # self.url = "https://sharpuat.jusdaglobal.com" self.driver.get(self.url) self.logs = log.log_message() self.login = Login() self.free = FreeNewOrders() self.freeEle = FreeNew() # 登录 self.login.test_click_login_btn(self.driver) sleep(5)
def login(self, name, password, expect): self.logs.logger.info('调用login()') self.logs = log.log_message("登陆页面对象") self.driver.open(self.host + self.home_uri) self.driver.make_maxwindow() self.driver.click('xpath', self.ele_login_but) self.driver.send_key('name', self.ele_name, name) self.driver.send_key('xpath', self.ele_pwd, password) sleep(1) self.driver.click('xpath', self.ele_sub) if expect == 'name_err': self.login_name_err_msg = self.driver.get_text( 'xpath', self.ele_name_err_msg) self.logs.logger.info('调用login()结束;return:[%s]' % self.login_name_err_msg) return self.login_name_err_msg elif expect == 'pwd_err': self.login_pwd_err_msg = self.driver.get_text( 'xpath', self.ele_pwd_err_msg) self.logs.logger.info('调用login()结束;return:[%s]' % self.login_pwd_err_msg) return self.login_pwd_err_msg elif expect == 'succeed': sleep(2) self.driver.move_element('id', self.ele_succend_but) self.login_su_msg = self.driver.get_text('link_text', self.ele_succeed_msg) self.logs.logger.info('调用login()结束;return:[%s]' % self.login_su_msg) return self.login_su_msg else: self.logs.logger.info('输入预期结果不在范围内!')
def storage_login(driver): ''' 通过localStorage 绕过登陆 参考:# 通过cookie判断是否登陆:https://www.cnblogs.com/mengyu/p/7078561.html # 通过localstorage绕过登陆:https://www.cnblogs.com/zanjiahaoge666/p/7576328.html :param driver: 浏览器驱动 :return: ''' try: data = get_element('login') ele_succend_but = data.get('ele_succend_but') ele_succeed_msg = data.get('ele_succeed_msg') driver.open('https://www.yunqueyi.com') # 打开首页 is_login = driver.get_text('xpath', '//*[@id="login"]/li[1]/span') logs = log.log_message('登陆测试') if is_login == '登录': # 判断如果页面有'登录'按钮则证明没有登录,向local Storage中添加token、name、doctorId api_url = 'https://www.yunqueyi.com/web/registers/saasLogin?mobile=15607241351&OS=Win10&browser=Chrome&terminalType=PC&ipAddress=183.193.128.239&password=EABD8CE9404507AA8C22714D3F5EADA9&token=E7655872126845AC8F602898938552E3' r = requests.get(api_url) driver.js('localStorage.setItem("token", %s);' % json.dumps(r.json()['token'])) driver.js('localStorage.setItem("user_name", %s);' % json.dumps(r.json()['picapDoctor']['name'])) driver.js('localStorage.setItem("doctorId", %s);' % json.dumps(r.json()['picapDoctor']['id'])) logs.logger.info('页面未登陆;向localStorage中插入:token、user_name、doctorId') else: # 如果页面没有"登陆"则证明已登录 logs.logger.info('页面已登陆;') driver.f5() driver.move_element('id', ele_succend_but) login_su_msg = driver.get_text('link_text', ele_succeed_msg) assert login_su_msg == '个人资料', '[%s]不等于[个人资料]' % login_su_msg except AssertionError as e: # 明确抛出此异常 print('登陆失败:[assert except]:%s ' % e)
def __init__(self, imgs): # 初始化浏览器 if brower == 'firefox' or brower == 'Firefox' or brower == 'f' or brower == 'F': deriver = webdriver.Firefox(root_path + "\\browser_driver\\geckodriver.exe") elif brower == 'Ie' or brower == 'ie' or brower == 'i' or brower == 'I': deriver = webdriver.Ie(root_path + "\\browser_driver\\IEDriverServer.exe") elif brower == 'Chrome' or brower == 'chrome' or brower == 'Ch' or brower == 'ch': deriver = webdriver.Chrome(root_path + "\\browser_driver\\chromedriver.exe") elif brower == 'PhantomJS' or brower == 'phantomjs' or brower == 'ph' or brower == 'phjs': deriver = webdriver.PhantomJS() elif brower == 'Edge' or brower == 'edge' or brower == 'Ed' or brower == 'ed': deriver = webdriver.Edge() elif brower == 'Opera' or brower == 'opera' or brower == 'op' or brower == 'OP': deriver = webdriver.Opera() elif brower == 'Safari' or brower == 'safari' or brower == 'sa' or brower == 'saf': deriver = webdriver.Safari() else: raise NameError( "-CreateDriver()对象只能传入:firefox,Ie,Chrome,PhantomJS,Edge,Opera,Safari;请确认%s是否合法" % brower) self.imgs = imgs self.driver = deriver self.logs = log.log_message("页面对象")
def test24NonrepetitiveValidation(self): #报告中的用例描述 self._testMethodDoc = "I/V NO不重复验证"; logs = log.log_message(); driver = self.driver; sucess_text = Logic(driver).test24(driver); # 验证arg1=arg2,不等则fail self.assertEqual('INV番号はすでに存在しています。', sucess_text)
def test10MultipleConstructionSearchAdditions(self): #报告中的用例描述 self._testMethodDoc = "多条建检索添加"; logs = log.log_message(); driver = self.driver; sucess_text = Logic(driver).test10(driver); # 验证arg1=arg2,不等则fail self.assertEqual('No data available', sucess_text)
def test1UnconditionalRetrieval(self): #报告中的用例描述 self._testMethodDoc = "无条件检索" logs = log.log_message() driver = self.driver sucess_text = Logic().test1(driver) # 验证arg1 != arg2, 相等则fail self.assertNotEqual('No data available', sucess_text)
def test7OffsitePinfan(self): #报告中的用例描述 self._testMethodDoc = "社外品番筛选添加数据"; logs = log.log_message(); driver = self.driver; sucess_text = Logic(driver).test7(driver); # 验证arg1 != arg2, 相等则fail self.assertNotEqual('No data available', sucess_text)
def test3InvalidRetrieval(self): # 报告中的用例描述 self._testMethodDoc = "P/O NO无效检索"; logs = log.log_message(); driver = self.driver; sucess_text = Logic(driver).test3(driver); # 验证arg1=arg2,不等则fail self.assertEqual('No data available', sucess_text)
def test1DetaileddataAddition(self): #报告中的用例描述 self._testMethodDoc = "INVOICE 详细数据添加"; logs = log.log_message(); driver = self.driver; sucess_text = Logic(driver).test1(driver); # 验证arg1 != arg2, 相等则fail self.assertNotEqual('No data available', sucess_text)
def test16TypewritingStartEnd(self): #报告中的用例描述 self._testMethodDoc = "输入Carton Start No和输入Carton End No功能"; logs = log.log_message(); driver = self.driver; sucess_text = Logic(driver).test16(driver); # 验证arg1=arg2,不等则fail self.assertNotEqual('No data available', sucess_text)
def test15ListDataInputIdentificationNumberFunction(self): #报告中的用例描述 self._testMethodDoc = "列表数据输入识别番号功能"; logs = log.log_message(); driver = self.driver; sucess_text = Logic(driver).test15(driver); # 验证arg1=arg2,不等则fail self.assertNotEqual('No data available', sucess_text)
def test14ListDataCountryofOriginModificationFunction(self): #报告中的用例描述 self._testMethodDoc = "列表数据原产国修改功能"; logs = log.log_message(); driver = self.driver; sucess_text = Logic(driver).test14(driver); # 验证arg1=arg2,不等则fail self.assertNotEqual('香港', sucess_text)
def test13ListDataQuantityModificationFunction(self): #报告中的用例描述 self._testMethodDoc = "列表数据'数量'修改功能"; logs = log.log_message(); driver = self.driver; sucess_text = Logic(driver).test13(driver); # 验证arg1=arg2,不等则fail self.assertNotEqual('No data available', sucess_text)
def test12PLloginAddMultipleFunctions(self): #报告中的用例描述 self._testMethodDoc = "P/L登陆-添加多条功能"; logs = log.log_message(); driver = self.driver; sucess_text = Logic(driver).test12(driver); # 验证arg1=arg2,不等则fail self.assertNotEqual('No data available', sucess_text)
def test11PLlandingfunction(self): #报告中的用例描述 self._testMethodDoc = "P/L登陆功能"; logs = log.log_message(); driver = self.driver; sucess_text = Logic(driver).test11(driver); # 验证arg1=arg2,不等则fail self.assertNotEqual('No data available', sucess_text)
def test25NOfunction(self): # 报告中的用例描述 self._testMethodDoc = "I/V NO功能"; logs = log.log_message(); driver = self.driver; sucess_text = Logic(driver).test25(driver); # 验证arg1=arg2,不等则fail self.assertEqual('保存が完了しました。', sucess_text)
def test27inputM(self): #报告中的用例描述 self._testMethodDoc = "输入M3功能"; logs = log.log_message(); driver = self.driver; sucess_text = Logic(driver).test27(driver); # 验证arg1=arg2,不等则fail self.assertNotEqual('No data available', sucess_text)
def test18EliminationFunction(self): #报告中的用例描述 self._testMethodDoc = "消除功能"; logs = log.log_message(); driver = self.driver; sucess_text = Logic(driver).test18(driver); # 验证arg1=arg2,不等则fail self.assertEqual('No data available', sucess_text)
def test2NOretrieval(self): #报告中的用例描述 self._testMethodDoc = "P/O NO检索"; logs = log.log_message(); driver = self.driver; sucess_text = Logic(driver).test2(driver); # 验证arg1 != arg2, 相等则fail self.assertNotEqual('No data available', sucess_text)
def test19EliminateCancellationFunction(self): #报告中的用例描述 self._testMethodDoc = "消除取消功能"; logs = log.log_message(); driver = self.driver; sucess_text = Logic(driver).test19(driver) # 验证arg1 != arg2, 相等则fail self.assertNotEqual('No data available', sucess_text)
def test4BusinessUnitScreeningAddData(self): #报告中的用例描述 self._testMethodDoc = "事业本部筛选添加数据"; logs = log.log_message(); driver = self.driver; sucess_text = Logic(driver).test4(driver); # 验证arg1 != arg2, 相等则fail self.assertNotEqual('No data available', sucess_text)
def test20PLBranchFunction(self): #报告中的用例描述 self._testMethodDoc = "PL行分功能"; logs = log.log_message(); driver = self.driver; sucess_text = Logic(driver).test20(driver); # 验证arg1 != arg2, 相等则fail self.assertNotEqual('No data available', sucess_text)
def test8ScreeningAddData(self): #报告中的用例描述 self._testMethodDoc = "SI.NO筛选添加数据" logs = log.log_message() driver = self.driver; sucess_text = Logic(driver).test8(driver) # 验证arg1 != arg2, 相等则fail self.assertNotEqual('No data available', sucess_text)
def test21SaveQuantitativeAttributesSame(self): #报告中的用例描述 self._testMethodDoc = "数量属性相同保存"; logs = log.log_message(); driver = self.driver; sucess_text = Logic(driver).test21(driver); # 验证arg1=arg2,不等则fail self.assertEqual('保存が完了しました。', sucess_text)
def test13CurrencyRetrieval(self): # 报告中的用例描述 self._testMethodDoc = "通货检索" logs = log.log_message() driver = self.driver sucess_text = Logic().test13(driver) # self.assertIn(a,b) 判断a in b是否成立,正确则True,否则为False logs.info_log(self.assertIn('FCA', sucess_text))
def test23WeightloginFunction(self): #报告中的用例描述 self._testMethodDoc = "重量登录功能" logs = log.log_message(); driver = self.driver; sucess_text = Logic(driver).test23(driver) # 验证arg1 != arg2, 相等则fail self.assertNotEqual('No data available', sucess_text)
def test22QuantitativeAttributesArePreservedWithDifferentAttributes(self): #报告中的用例描述 self._testMethodDoc = "数量属性不同同保存"; logs = log.log_message() driver = self.driver; sucess_text = Logic(driver).test22(driver) # 验证arg1=arg2,不等则fail self.assertEqual('PO出荷数量とPOのPackingList数量が不一致のため、保存できません。', sucess_text)
def test9MultipleConstructionSearchAdditions(self): #报告中的用例描述 self._testMethodDoc = "多条建检索添加"; logs = log.log_message() driver = self.driver sucess_text = Logic(driver).test9(driver) # 验证arg1 != arg2, 相等则fail self.assertNotEqual('No data available', sucess_text)