例項:[我愛我家]網站測試登入指令碼實現
阿新 • • 發佈:2018-12-19
一、用指令碼實現“我愛我家”網站的登入操作
1.分析
(1)登入有兩個引數,使用者名稱和密碼,查詢到這兩個元素輸入後點擊登入操作
(2)斷言:判斷是否登入成功可以用登入後的使用者名稱來檢驗
二、selenium+unittest指令碼實現
1.程式碼部分
#coding:utf-8 from selenium import webdriver import unittest class Login5i5j(unittest.TestCase): def setUp(self): print("開始執行測試...") self.name = "182xxxxxxxx" self.pwd = "xxxxxxx" self.browser = webdriver.Chrome() self.browser.get("https://passport.5i5j.com/passport/login?service=https%3A%2F%2Fwx.5i5j.com%2Freglogin%2Findex%3FpreUrl%3Dhttps%253A%252F%252Fwx.5i5j.com%252F%253Fpmf_group%253Dbaidu%2526pmf_medium%253Dppzq%2526pmf_plan%253D%2525E5%2525B7%2525A6%2525E4%2525BE%2525A7%2525E6%2525A0%252587%2525E9%2525A2%252598%2526pmf_unit%253D%2525E6%2525A0%252587%2525E9%2525A2%252598%2526pmf_keyword%253D%2525E6%2525A0%252587%2525E9%2525A2%252598%2526pmf_account%253D199&status=1&city=wx") self.browser.maximize_window() def test_login(self): self.browser.find_element_by_id("username").send_keys(self.name) self.browser.find_element_by_id("password").send_keys(self.pwd) self.browser.find_element_by_id("login").submit() self.browser.implicitly_wait(3) # 查詢到登入後的使用者名稱,校驗結果 verifyLoginSucceed = self.browser.find_element_by_class_name("log").text self.assertEqual("karry_sun",verifyLoginSucceed) def tearDown(self): self.browser.close() print("測試結束...") if __name__ == '__main__': unittest.main()
2.結果