A cnblog login test with Python+selenium

Source: Internet
Author: User
Tags assert

Use Python+selenium automation to do a cnblog login test, can be used for reference! The following includes the test code and each of the test cases:

The login test of the Cnblog is divided into the following situations: (1) The username and password are correct (2) The username is correct, the password is incorrect (3) The username is correct, the password is blank (4) The user name is wrong, the password is correct (5) The user name is empty, the password is correct (and the user name and password are This is not tested separately) "' import unittestfrom selenium import webdriverfrom time import  Sleepclass logincase (unittest. TestCase):     def setup (self):         self.dr  = webdriver. Chrome ()         self.dr.maximize_window ()     # Define Login Method     def login (Self, username, password):         self.dr.get (' Https://passport.cnblogs.com/user/signin ')    #cnblog登录页面          self.dr.find_element_by_id (' input1 '). Send_keys (username)          self.dr.find_element_by_id (' Input2 '). Send_keys (password)          self.dr.find_element_by_id (' signin '). Click ()    def test_login_success (self):         " Username, password correct ' ' '         self.login (' kemi_xxx ',  ' kemi_xxxx ')  # Correct user name and password         sleep (3)          link = self.dr.find_element_by_id (' Lnk_current_user ')          self.asserttrue (' rookie can M '  in link.text)     #用assertTrue (x) method to assert    BOOL (x)  is True  user nickname in Lnk_current_user after successful login     def test_login_pwd_ Error (self):         "username correct, password incorrect"          self.login (' kemi_xxx ',  ' Kemi ')    #正确用户名, error password          sleep (2)         error_message =  self.dr.find_element_by_id (' tip_btn '). text         self.assertin (' Username or password error ',  error_message)    #用assertIn (A, B) method to assert  a in b   ' username or password error ' in Error_message     def test_ Login_pwd_null (self):         "username is correct, password is empty"          self.login (' kemi_xxx ',  ')    #密码为空          error_message = self.dr.find_element_by_id (' Tip_input2 ') .text         self.assertequal (error_message, ' Please enter password ')    #用assertEqual (A, B) method to assert    a == b   Please enter a password equal to Error_message    def test_login_user_error (self):          ' username wrong, password correct '          self.login (' kemixing ',  ' kemi_xxx ')    #密码正确, user name error          sleep (2)         error_message = self.dr.find_element_by_id (' tip_btn '). Text         self.assertin (' The user does not exist ',  error_message)   # Use the Assertin (A, B) method to assert  a in b    def test_login_user_null (self):          ' User name is blank, password is correct '          Self.login (',  ' kemi_xxx ')    #用户名为空, password correct         error_ message = self.dr.find_element_by_id (' tip_input1 ') .text         self.assertequal (error_message, ' Please enter login username ')    #用assertEqual (A, B) method to assert   a ==  B    def teardown (self):         sleep (2)         self.dr.quit () if __name__ ==  ' __main__ ':     unittest.main ()

As follows:

Correct user name and password login successful!

650) this.width=650; "src="/e/u261/themes/default/images/spacer.gif "style=" Background:url ("/e/u261/lang/zh-cn/ Images/localimage.png ") no-repeat center;border:1px solid #ddd;" alt= "Spacer.gif"/>650 "this.width=650;" src= "http ://images2015.cnblogs.com/blog/942023/201612/942023-20161227214635804-1740521108.png "style=" border:0px; Font-family:verdana, Arial, Helvetica, Sans-serif;font-size:14px;white-space:normal;background-color:rgb ( 255,255,255); "/>

Correct user name, error password Login failed!

650) this.width=650; "Src=" http://images2015.cnblogs.com/blog/942023/201612/942023-20161227214901195-660984531. PNG "style=" Border:0px;font-family:verdana, Arial, Helvetica, Sans-serif;font-size:14px;white-space:normal; Background-color:rgb (255,255,255); "/>

User name is correct, password is empty, login failed!

650) this.width=650; "Src=" http://images2015.cnblogs.com/blog/942023/201612/942023-20161227214802492-326761308. PNG "style=" Border:0px;font-family:verdana, Arial, Helvetica, Sans-serif;font-size:14px;white-space:normal; Background-color:rgb (255,255,255); "/>

User name is wrong, password is correct, login failed!

650) this.width=650; "Src=" http://images2015.cnblogs.com/blog/942023/201612/942023-20161227214957632-23278223. PNG "style=" Border:0px;font-family:verdana, Arial, Helvetica, Sans-serif;font-size:14px;white-space:normal; Background-color:rgb (255,255,255); "/>

With the named empty, the correct password, login failed!

650) this.width=650; "Src=" http://images2015.cnblogs.com/blog/942023/201612/942023-20161227215036961-1582028544. PNG "style=" Border:0px;font-family:verdana, Arial, Helvetica, Sans-serif;font-size:14px;white-space:normal; Background-color:rgb (255,255,255); "/>

This article comes from "No idea, no achievement!" "Blog, be sure to keep this provenance http://kemixing.blog.51cto.com/10774787/1886692

A cnblog login test with Python+selenium

Related Article

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.