#coding=utf-8
'''
Created on 2017-7-4
@auther:Qigege
project:登录测试用例
'''
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'
#定义登录的方法
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'条件均正确暂时跳过')
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'条件均正确——测试用例'
#@unittest.skip(u'密码错误暂时跳过')
def test_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(u'用户名或密码错误',link.text)
self.driver.get_screenshot_as_file('E:\\py-sql\\example\\pro5_note\\err_pwd.jpg')
print u'密码错误——测试用例'
#@unittest.skip(u'密码为空暂时跳过')
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'请输入密码' in link.text)
self.driver.get_screenshot_as_file('E:\\py-sql\\example\\pro5_note\\null_pwd.jpg')
print u'密码为空——测试用例'
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'用户名或密码错误',link.text)
self.driver.get_screenshot_as_file('E:\\py-sql\\example\\pro5_note\\err_user.jpg')
print u'用户名错误——测试用例'
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'请输入登录用户名' in link.text) self.driver.get_screenshot_as_file('E:\\py-sql\\example\\pro5_note\\null_user.jpg') print u'用户名为空——测试用例' def tearDown(self): time.sleep(2) print u'测试完毕!' self.driver.quit()if __name__=='__main__': unittest.main()
以上就是一次完整的自动化登录测试-2017-7-4的详细内容,更多请关注php中文网其它相关文章!
已抢186130个
抢已抢67098个
抢已抢352649个
抢已抢666602个
抢已抢121398个
抢已抢22281个
抢