介绍
###### 测试的系统:
###### 技术:selenium,pytest
###### 测试的功能:登录,退出登录。
测试用例
| 用例编号 | 主模块 | 子模块 | 前置条件 | 测试步骤 | 预期结果 | 实际结果 |
|---|---|---|---|---|---|---|
| Login_01 | 登录 | 登录 | 已注册 | 1.输入正确的用户名,不输入密码。2.点击登录 | 登录不成功,有相关的提示 | 登录不成功,提示:请输入密码 |
| Login_02 | 登录 | 登录 | 已注册 | 1.不输入用户名,输入正确的密码。2.点击登录 | 登录不成功,有相关的提示 | 登录不成功,提示:请输入用户名 |
| Login_03 | 登录 | 登录 | 已注册 | 1.输入正确的用户名,输入错误的密码。2.点击登录 | 登录不成功,有相关的提示 | 登录不成功,提示:登录失败 : 用户名或者密码错误 |
| Login_04 | 登录 | 登录 | 已注册 | 1.输入错误的用户名,输入正确的密码。2.点击登录 | 登录不成功,有相关的提示 | 登录不成功,提示:登录失败 : 用户名或者密码错误 |
| Login_05 | 登录 | 登录 | 已注册 | 1.输入错误的用户名和错误的密码。2.点击登录 | 登录不成功,有相关的提示 | 登录不成功,提示:登录失败 : 用户名或者密码错误 |
| Login_06 | 登录 | 登录 | 已注册 | 1.输入正确的用户名和正确的密码。2.点击登录 | 登录成功 | 登录成功 |
| LogOut_07 | 退出登录 | 退出登录 | 已登录 | 1.点击退出登录按钮 | 退出登录成功 | 退出登录成功 |
自动化测试程序
python
#configuration.py
from selenium import webdriver
url = 'http://127.0.0.1/mgr/sign.html'
chrome = webdriver.Chrome()
python
#LoginSuccessfully.py
"""
@author:zulnger(丽格)
"""
from selenium import webdriver
from time import sleep
import pytest
from configuration import driver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.common.exceptions import NoAlertPresentException
def Login(Uname,pw):
# 打开系统
driver.chrome.get('http://127.0.0.1/mgr/sign.html')
sleep(3)
# Login_01
# 定位元素
userName = driver.chrome.find_element(By.ID, 'username')
userName.clear()
userName.send_keys(f'{Uname}')
sleep(2)
password = driver.chrome.find_element(By.ID, 'password')
password.clear()
password.send_keys(f'{pw}')
sleep(2)
#点击登录
submit = driver.chrome.find_element(By.XPATH,"//div[@class='col-xs-12']/button")
submit.click()
sleep(3)
python
#test_login.py
"""
@author:zulnger(丽格)
"""
from selenium import webdriver
from time import sleep
import pytest
from configuration import driver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from Login.LoginSuccessfully import *
class Test_Login:
def test_Login_01(self):
#Login_0
log = Login('byhy','')
# Confirm 弹窗
try:
Confirm = driver.chrome.switch_to.alert
print("登录失败!!!")
text = Confirm.text
print('登录失败提示语 ------> ', text)
Confirm.accept()
sleep(3)
except NoAlertPresentException:
print("登录成功~")
print("当前没有 alert,跳过处理")
assert text == '请输入密码'
def test_Login_02(self):
log = Login('','byhy')
# Confirm 弹窗
try:
Confirm = driver.chrome.switch_to.alert
print("登录失败!!!")
text = Confirm.text
print('登录失败提示语 ------> ', text)
Confirm.accept()
sleep(3)
except NoAlertPresentException:
print("登录成功~")
print("当前没有 alert,跳过处理")
assert text == '请输入用户名'
def test_Login_03(self):
log = Login('byhy', '8888888')
# Confirm 弹窗
try:
Confirm = driver.chrome.switch_to.alert
text = Confirm.text
print('登录失败提示语 ------> ', text)
Confirm.accept()
sleep(3)
except NoAlertPresentException:
print("登录成功~")
print("当前没有 alert,跳过处理")
assert text == '登录失败 : 用户名或者密码错误'
def test_Login_04(self):
log = Login('byh', '88888888')
# Confirm 弹窗
try:
Confirm = driver.chrome.switch_to.alert
text = Confirm.text
print('登录失败提示语 ------> ', text)
Confirm.accept()
sleep(3)
except NoAlertPresentException:
print("登录成功~")
print("当前没有 alert,跳过处理")
assert text == '登录失败 : 用户名或者密码错误'
def test_Login_05(self):
log = Login('by', '99999999')
# Confirm 弹窗
try:
Confirm = driver.chrome.switch_to.alert
text = Confirm.text
print('登录失败提示语 ------> ', text)
Confirm.accept()
sleep(3)
except NoAlertPresentException:
print("登录成功~")
print("当前没有 alert,跳过处理")
assert text == '登录失败 : 用户名或者密码错误'
def test_Login_06(self):
log = Login('byhy','88888888')
sleep(2)
logo_text = driver.chrome.find_element(By.CSS_SELECTOR,".main-header .logo-lg").text
assert logo_text == '白月黑羽SMS'
python
#test_loout.py
from time import sleep
import pytest
from configuration import driver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from Login.LoginSuccessfully import *
from selenium.common.exceptions import TimeoutException
def test_logout():
Login('byhy','88888888')
try:
# 例:退出按钮、用户昵称、头像......
userAvatarElement = driver.chrome.find_element(By.XPATH, '//div[@class="navbar-custom-menu"]/ul/li[2]/a')
userAvatarElement.click()
sleep(2)
logOutElement = driver.chrome.find_element(By.XPATH, '//div[@class="pull-right"]/a')
logOutElement.click()
sleep(2)
print('退出登录成功!!!!!')
except TimeoutException:
print('退出登录失败')