Py角色登录

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)

    @staticmethod
    def 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()

猜你喜欢

转载自www.cnblogs.com/afhkv/p/10761190.html
py