项目目录下要有的内容:
tests目录里的测试代码
可以先写注释梳理流程,再写代码
from selenium import webdriver from selenium.webdriver.common.by import By class TestSignIn: def test_sign_in(self): """测试登录功能 步骤: 1、输入登录url: https://v4.ketangpai.com/User/login.html 2、输入用户名: aaa, name=account 3、输入密码 123, name=pass 4、点击登录按钮, css=.btn-btn :return: """ username = 'aaa' password = '123' expected = '密码有效长度是6到30个字符' with webdriver.Chrome(executable_path=r'D:\tests\chromedriver') as browser: browser.implicitly_wait(5) browser.maximize_window() # 访问url url = 'https://v4.ketangpai.com/User/login.html' browser.get(url) # 输入用户名 username_el = browser.find_element(By.NAME, 'account') username_el.clear() username_el.send_keys(username) # 输入密码 browser.find_element(By.NAME, 'pass').send_keys(password) # 点击登录 browser.find_element(By.CSS_SELECTOR, '.btn-btn').click() # 获取文本 actual = browser.find_element(By.CSS_SELECTOR, '.error-tips').text # actual = browser.find_element(By.CSS_SELECTOR, '.error-tips').get_attribute('name') assert actual == expected