class TestWebBaseCase(TestBaseCase): """ web测试初始化 """ def setup(self): super(TestWebBaseCase, self).setup() self.driver = WebChrome() self.driver.implicitly_wait(5) self.driver.get(BASEURL) # 使用cookie打开浏览器 with shelve.open(f"{mydbs_dir}/cookies") as db: # coo = self.driver.get_cookies() # db["cookies"] = coo cookies = db["cookies"] for cookie in cookies: if "expiry" in cookie.keys(): cookie.pop("expiry") continue self.driver.add_cookie(cookie) self.driver.get(BASEURL) self.log.info("进入主界面") self.main_page = MainPage(self.driver) def teardown(self): super(TestWebBaseCase, self).teardown() self.log.info("关闭浏览器") self.driver.quit()
def job1(useid, password): #通过python自带的模块判断是不是节假日 nowTime = datetime.date(datetime.datetime.now().year, datetime.datetime.now().month, datetime.datetime.now().day) print(is_workday(nowTime)) if is_workday(nowTime): print('Its weekday') driver = WebChrome() driver.implicitly_wait(20) driver.get( "http://sso.portal.unicom.local/eip_sso/aiportalLogin.html?appid=na186&success=http://service.aiportal.unicom.local/ssoclient/ssologin&error=http://sso.portal.unicom.local/eip_sso/aiportalLogin.html&return=http://sso.portal.unicom.local/eip_sso/aiportalLogin.html" ) driver.find_element_by_id('login').send_keys(useid) driver.find_element_by_id('password').send_keys(password) driver.find_element_by_xpath("//button[@class='login_botton']").click() driver.find_element_by_xpath( "//div[@class='pan' and @label='人力资源2.0']").click() driver.switch_to_new_tab() driver.find_element_by_xpath( "//a[@class = 'gn_block gn_block1']").click() driver.switch_to_new_tab() driver.find_element_by_xpath( "//button[@class='ant-btn sign-btn signout ant-btn-primary']" ).click() driver.quit() else: print('Its holiday')
from selenium import webdriver from selenium.webdriver.common.keys import Keys from airtest_selenium.proxy import WebChrome driver = WebChrome() driver.implicitly_wait(10) driver.maximize_window() driver.get("https://www.yigongla.com/") driver.find_element_by_xpath("//a[@href='/index/index/index']").click() driver.find_element_by_xpath("//a[@href='/index/qyserve/qyserve']").click() driver.assert_exist("/html/body/div[3]/div/h3", "xpath", "我的价值") driver.find_element_by_xpath("//a[@href='/index/inquiry/inquiry']").click() driver.find_element_by_xpath("//a[@href='/index/about/about']").click() driver.find_element_by_xpath("/html/body/div/div[2]/a/button").click() driver.assert_exist("/html/body/div/div/div/div/div/div", "xpath", "密码登录") driver.assert_exist("/html/body/div/div/div/div/div/div[2]", "xpath", "验证码登录") driver.assert_exist("/html/body/div/div/div/div[3]/p", "xpath", "还没有易工账号") driver.assert_exist("/html/body/div/div/div/div[3]/div/a/span", "xpath", "立即注册") driver.assert_exist("passwordLogin", "id", "登录") driver.assert_exist("/html/body/div[2]/p", "xpath", "从蓝领招聘开始解决缺工现象.") driver.quit()