import time
import pytest
import allure
from page import login_xpath
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
@allure.feature("项目登录测试")
class Test_leopardv5_Login():
def setup(self):
self.driver = webdriver.Chrome()
self.driver.maximize_window()
self.driver.get('*************')
self.driver.implicitly_wait(10)
def teardown(self):
self.driver.quit()
# 登录模块
@pytest.mark.parametrize('casename,username,pwd,expect',
[
['正确的用户名错误的密码', 'admin', '32232', '用户名或密码错误'],
['错误的用户名密码', 'ad4min', '4343', '用户名或密码错误'],
['正确的用户名和正确的密码', 'admin4', 'admin', '控制台']
])
def test_login(self, casename, username, pwd, expect):
allure.dynamic.title(casename) # 用例名称
allure.dynamic.description('登录模块测试用例') # 用例描述‘
with allure.step('step1:输入用户名'):
self.driver.find_element(By.NAME, login_xpath.username).send_keys(username)
with allure.step('step1:输入密码'):
self.driver.find_element(By.NAME, login_xpath.pwd).send_keys(pwd)
with allure.step('step1:点击登录按钮'):
self.driver.find_element(By.CLASS_NAME, login_xpath.login_buttun).click()
self.driver.implicitly_wait(10)
time.sleep(2)
if casename.__contains__('错误'):
msg = self.driver.find_element(By.XPATH, login_xpath.errors).text
WebDriverWait(self.driver, 5, poll_frequency=0.5, ignored_exceptions=None).until(
EC.visibility_of_element_located((By.XPATH, login_xpath.errors)))
assert msg == expect
else:
kongzhitai = self.driver.find_element(By.XPATH, login_xpath.kongzhi).text
WebDriverWait(self.driver, 5, poll_frequency=0.5, ignored_exceptions=None).until(
EC.visibility_of_element_located((By.XPATH, login_xpath.kongzhi)))
assert kongzhitai == expect
if __name__ == '__main__':
pytest.main()
相似问题