A complete automated login test-, automated-

Source: Internet
Author: User

A complete automated login test-, automated-

# Coding = UTF-8

'''
Created on 2017-7-4
@ Auther: Qigege
Project: logon test case
'''

Import unittest
From selenium import webdriver
From selenium. webdriver. firefox. firefox_binary import FirefoxBinary
Import time

Class LoginCase (unittest. TestCase ):
Def setUp (self ):
Binary = FirefoxBinary ('f: \ ff \ MozillaFirefox50.1.0 \ firefox.exe ')
Self. driver = webdriver. Firefox (firefox_binary = binary)
Self. url = 'https: // passport.cnblogs.com/user/signin? ReturnUrl = https % 3A % 2F % 2Fwww.cnblogs.com % 2F'

# Define logon methods
Def login (self, username, password ):
Driver = self. driver
Url = self. url
Driver. get (url)
Driver. find_element_by_id ('input1'). send_keys (username)
Driver. find_element_by_id ('input2'). send_keys (password)
Driver. find_element_by_id ('signin'). click ()

# @ Unittest. skip (U' the conditions are correct and skipped temporarily ')
Def test_login_success (self ):
'''Username and password right '''
Self. login ('qigege ','******')
Time. sleep (2)
Link = self. driver. find_element_by_link_text ('qigege ')
Self. assertTrue ('qigege' in link. text)
#
Self. driver. get_screenshot_as_file ('e: \ py-SQL \ example \ pro5_note \ user_pwd.jpg ')
Print U' the conditions are correct -- Test Case'

# @ Unittest. skip (u'password error skipped temporarily ')
Def test_login_pwd_error (self ):
'''Username right and password error '''
Self. login ('qigege', '20140901 ')
Time. sleep (2)
Link = self. driver. find_element_by_id ('tip _ btn ')
Self. assertTrue (u'invalid user name or password ', link. text)
Self. driver. get_screenshot_as_file ('e: \ py-SQL \ example \ pro5_note \ err_pwd.jpg ')
Print u'password error -- Test case'

# @ Unittest. skip (u'the password is blank and skipped temporarily ')
Def test_login_pwd_null (self ):
'''Username right and password null '''
Self. login ('qigege ','')
Time. sleep (2)
Link = self. driver. find_element_by_id ('tip _ input2 ')
Self. assertTrue (U' enter the password 'in link. text)
Self. driver. get_screenshot_as_file ('e: \ py-SQL \ example \ pro5_note \ null_pwd.jpg ')
Print u'password is blank -- Test case'

Def test_login_user_err (self ):
'''Username error and password right '''
Self. login ('gege ','******')
Time. sleep (2)
Link = self. driver. find_element_by_id ('tip _ input2 ')
Self. assertTrue (u'invalid user name or password ', link. text)
Self. driver. get_screenshot_as_file ('e: \ py-SQL \ example \ pro5_note \ err_user.jpg ')
Print u'user name error -- Test case'

Def test_login_user_null (self): ''' username null and password right ''' self. login ('', '*******') link = self. driver. find_element_by_id ('tip _ input1 ') self. assertTrue (U' enter the logon Username 'in link. text) self. driver. get_screenshot_as_file ('e: \ py-SQL \ example \ pro5_note \ null_user.jpg ') print U' user name is blank -- Test Case 'def tearDown (self): time. sleep (2) print U' test is complete! 'Self. driver. quit () if _ name __= = '_ main _': unittest. main ()

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.