1 ImportUnitTest2 fromSeleniumImportWebdriver3 fromTimeImportSleep4 5 classlonintest (unittest. TestCase):6 @classmethod7 defsetUp (self):8Self.driver =Webdriver. Firefox ()9Self.driver.implicitly_wait (30)Ten deftest_login_sucess (self): OneSelf.login ("XXXXX","XXXXXXX") ASleep (3) -Logoutname = Self.driver.find_element_by_class_name ("Menu-link-label") -Self.asserttrue ('Change Password' inchlogoutname.text) the - deflogin (self, username, password): -Self.driver.get ("http:xxxxxxxxxx") -Input_field = Self.driver.find_element_by_name ("username") + input_field.clear () - Input_field.send_keys (username) + AInput_password = Self.driver.find_element_by_name ("Password") at input_password.clear () - input_password.send_keys (password) - -Login = Self.driver.find_element_by_tag_name ("Button") - Login.click () - in defTearDown (self): - self.driver.quit () to +Unittest.main ()
As a small white person who has just opened a study python+selenium+unnitest, tell me about the problems I have encountered in writing this code.
Problem: Running the program is reported Typeerror:test_login () missing 2 required positional arguments: ' username ' and ' password '
Later after a variety of troubleshooting found: The login function before the test is removed, because login is a function called internally, Test begins with each use case
DefTest_login_sucess (Self):
Self.Test_login("XXXXXX", "XXXXXX")
Sleep (3)
Logoutname = self.driver.find_element_ By_class_name ( "Menu-link-label")
self.asserttrue ( in logoutname.text)
def test_login (self self.driver.get ( "xxxxxxxxxxxxx")
Input_field = self.driver.find_element_by_name ( " Username ")
Input_field.clear ()
Input_field.send_keys (username)
Python+selenium+unnitest Write a complete verification of the login