第一条自动化测试用例_邮箱登录
#testcase_01.py
from selenium import webdriver
from time import sleep
from login_module import Login
dr = webdriver.Chrome()
#测试数据与测试代码分离:
user_info = [{"username":'',"passwd":'error'},
{"username":'error',"passwd":''},
{"username":'error',"passwd":'error'}]
def test_username_null():
dr.get("https://126.com")
dr.maximize_window()
sleep(3)
l = Login(dr)
l.login(user_info[0]["username"],user_info[0]["passwd"])
def test_passwd_null():
dr.get("https://126.com")
dr.maximize_window()
sleep(3)
l = Login(dr)
l.login(user_info[1]["username"],user_info[1]["passwd"])
def test_passwd_error():
dr.get("https://126.com")
dr.maximize_window()
sleep(3)
l = Login(dr)
l.login(user_info[2]["username"],user_info[2]["passwd"])
test_username_null()#测试用户名与空
test_passwd_null() #测试密码为空
test_passwd_error()#测试用户名和密码错误
dr.quit()
--------------
#login_module.py
class Login:
def __init__(self,driver):
self.dr = driver
def login(self,username,passwd):
dr = self.dr
#当iframe表单页签id动态变化时,可以配合上层页签一起定位
frame = dr.find_element_by_css_selector("div#loginDiv > iframe")
dr.switch_to.frame(frame)
dr.find_element_by_name("email").send_keys(username)
dr.find_element_by_name("password").send_keys(passwd)
dr.find_element_by_id("dologin").click()
dr.switch_to.parent_frame()