A complete automated login test-2017-7-4

Source: Internet
Author: User
#coding =utf-8

'''
Created on 2017-7-4
@auther: Qigege
ProjectLogin Test Cases
'''

Import UnitTest
From seleniumImport Webdriver
From Selenium.webdriver.firefox.firefox_binaryImport Firefoxbinary
Import time

ClassLogincase (unittest. TestCase):
DefSetUp (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 the method of login
DefLoginSelfUsernamePassword):
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 'Conditions are correct temporarily skipped')
DefTest_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 ')
PrintUConditions are correct——Test Cases'

# @unittest. Skip (U 'Password error temporarily skipped')
DefTest_login_pwd_error (Self):
"' Username right and password error '
Self.login (' Qigege ',' 123123 ')
Time.sleep (2)
link=SELF.DRIVER.FIND_ELEMENT_BY_ID (' Tip_btn ')
Self.asserttrue (UIncorrect user name or password', Link.text)
Self.driver.get_screenshot_as_file (E\\Py-sql\\Example\\Pro5_note\\Err_pwd.jpg ')
PrintUPassword error——Test Cases'

# @unittest. Skip (U 'Password is empty temporarily skipped')
DefTest_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 (UPlease enter your password'In Link.text)
Self.driver.get_screenshot_as_file (E\\Py-sql\\Example\\Pro5_note\\Null_pwd.jpg ')
PrintUPassword is empty——Test Cases'

DefTest_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 (UIncorrect user name or password', Link.text)
Self.driver.get_screenshot_as_file (E\\Py-sql\\Example\\Pro5_note\\Err_user.jpg ')
Printu ' 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 ' Please enter login username ' in Link.text ) self.driver.get_screenshot_as_file (' e:\\py-sql\\example\\pro5_note\\null_user.jpg ') print u ' user name is empty--test case ' Def TearDown (self): Time.sleep (2) Print U ' Test finished! ' Self.driver.quit () if __name__== ' __main__ ': Unittest.main ()

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.