import time from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.edge.service import Service def loginAndCheck(username,password): driver = webdriver.Edge(service=Service("E:\selenium\msedgedriver.exe")) # 设置10s,每隔30s找一次!! driver.implicitly_wait(10) driver.maximize_window() driver.get("http://127.0.0.1/mgr/sign.html") if username is not None: driver.find_element(By.ID,'username').send_keys(username) if password is not None: driver.find_element(By.ID,'password').send_keys(password) driver.find_element(By.CSS_SELECTOR,"button[type='submit']").click() time.sleep(2) alertText = driver.switch_to.alert.text print(alertText) return alertText
from lib.webui import loginAndCheck标签:第一个,alertText,loginAndCheck,self,driver,测试程序,assert,自动化,def From: https://www.cnblogs.com/shuangshuangzi/p/16802220.html
class Test_错误登录:
def test001(self):
alertText = loginAndCheck(None, 88888888)
assert alertText == '请输入用户名'
def test002(self):
alertText = loginAndCheck('byhy',None)
assert alertText == '请输入密码'
def test003(self):
alertText = loginAndCheck('byh',88888888)
assert alertText == '登录失败 : 用户名或者密码错误'
def test004(self):
alertText = loginAndCheck('byhy',8888888)
assert alertText == '登录失败 : 用户名或者密码错误'
def test005(self):
alertText = loginAndCheck('byhy',888888888)
assert alertText == '登录失败 : 用户名或者密码错误'