Login Module Package file: public.py
#coding =utf-8from selenium import webdriverfrom time import sleepclass Login (): #登陆 def user_login (self,driver): driver.find_element_by_id ("Loginform-username"). Clear () driver.find_element_by_id ("Loginform-username"). Send_keys ("91CTT") driver.find_element_by_id ("Loginform-password"). Clear () driver.find_element_by_id ("Loginform-password"). Send_keys ("CTT1106648034") driver.find_element_by_name ("Login-button"). Submit () #退出 def user_logout (self,driver): driver.find_element_by_link_text ("[Exit]"). Click () sleep (5) driver.quit ()
Test file test22.py
From selenium import webdriverfrom time import sleepfrom public import Logindriver = Webdriver. Chrome () #目的网址: 51cto.comurl = "Http://home.51cto.com/index?reback=http://9603083.blog.51cto.com/9593083/d-2" Driver.get (URL) login (). User_login (Driver) sleep (2) login (). User_logout (Driver)
The login class is defined in file public.py, which contains two function methods, the User_login method, and the User_logout method
Login and exit operation for 51cto.com
File test22.py is the actual operation of the test login and Exit interface
Call the User_login method and the User_logout method by introducing the login class of the module public
Selenium Learning: An example of modular drive testing