Selenium(八)測試用例的設計與模塊化
阿新 • • 發佈:2019-03-05
xxx col 窗口 登錄 打開 urn selenium def firefox
一.設計測試用例
1.分析我之前寫的登錄腳本:
from selenium import webdriver import time from selenium.webdriver.common.action_chains import ActionChains from selenium.webdriver.support.ui import WebDriverWait url = ‘http://www.maiziedu.com/‘ login_path = ‘/html/body/div[2]/div/div/div/div/a[2]‘ account = ‘xxx‘ #這裏需填實際的賬號pwd = ‘maizi123456‘ #預先設定好網址和賬號密碼 def get_ele_times(driver,times,func): return WebDriverWait(driver,times).until(func) #等待方法 def login_test(): driver = webdriver.Firefox() #open firefox driver.get(url) #打開url time.sleep(1) driver.maximize_window()#最大化窗口 ele_login = get_ele_times(driver,10, lambda driver:driver.find_element_by_xpath(login_path)) ele_login.click() #找到登錄,然後點擊 #相當於:driver.find_element_by_link_text(login_text).click() account_ele = driver.find_element_by_xpath(‘//*[@id="id_account_l"]‘) account_ele.send_keys(‘‘) account_ele.send_keys(account) password_ele = driver.find_element_by_xpath(‘//*[@id="id_password_l"]‘) password_ele.send_keys(‘‘) password_ele.send_keys(pwd) driver.find_element_by_xpath(‘//*[@id="login_btn"]‘).click() try: driver.find_element_by_link_text(‘該賬號不正確‘) print ("ACCOUNT AND PWD ERROR!") except: print ("ACCOUNT AND PWD RIGHT!") if __name__ == ‘__main__‘: login_test()
2.分析腳本功能是否可以模塊化
3.模塊化與數據隔離
4.修改後的模型
二.測試用例模塊化
1.
Selenium(八)測試用例的設計與模塊化