Python+selenium+unnitest Write a complete login verification

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.