思路:一个方法 一条用例
from selenium import webdriver
import unittest
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
class loginTest(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Firefox()
url = "------------"
self.driver.get(url)
# 封装用户登录
def user_login(self, username, password):
self.driver.find_element_by_id("username").send_keys(username)
self.driver.find_element_by_id("passwords").send_keys(password)
self.driver.find_element_by_css_selector(".ant-btn").click()
WebDriverWait(self.driver, 20,0.02).until(EC.presence_of_element_located ((By.XPATH, "//*[@id='root']/div/div[1]/div[2]/ul/li[1]/div")))
def test_login1(self):
'''用户名、密码为空登录'''
self.user_login("", "")
def test_login2(self):
'''用户名为空,密码正确'''
self.user_login("", "真实密码")
def test_login3(self):
'''用户名正确,密码为空'''
self.user_login("真实账号名", "")
def test_login4(self):
'''用户名密码正确 '''
self.user_login("真实账号名", "真实密码")
if __name__ == '__main__':
unittest.main()
网友评论