Py角色登錄
阿新 • • 發佈:2019-04-24
orm implicit pass submit fin col click comm itl
from selenium.webdriver.common.action_chains import ActionChains from time import sleep # 登錄 class Login: @staticmethod # 在user_login函數前加上@classmethon,則該函數變為類方法,該函數只能訪問到類的數據屬性,不能獲取實例的數據屬性 def user_login(driver, username, password): driver.find_element_by_id("userName").clear() driver.find_element_by_id("userName").send_keys(username) driver.find_element_by_id("password").clear() driver.find_element_by_id("password").send_keys(password) driver.find_element_by_xpath(‘//button[@type="submit"]‘).click() sleep(3) @staticmethoddef user_logout(driver): above1 = driver.find_element_by_xpath(‘//span[@style="vertical-align: middle;"]‘) ActionChains(driver).move_to_element(above1).perform() sleep(3) above2 = driver.find_element_by_xpath(‘//*[@id="app"]/div/div[2]/div[1]/div/div[2]/div/div/div[2]/ul/li[2]‘) ActionChains(driver).move_to_element(above2).click().perform() sleep(5) driver.quit()
from selenium import webdriver from Login import Login class LoginTest: def __init__(self): self.driver = webdriver.Chrome() self.driver.implicitly_wait(10) self.driver.get("http://") self.driver.maximize_window() def test_admin_login(self): print("管理員登錄") username = "" password = "" Login.user_login(self.driver, username, password) self.driver.quit() def test_guest_login(self): print("普通員工登錄") username = "" password = "" Login.user_login(self.driver, username, password) self.driver.quit() LoginTest().test_admin_login() LoginTest().test_guest_login()
Py角色登錄