unittest学习

 1 # -*- coding:utf-8 -*-
 2 """
 3 class login 继承 unittest.Testcase 
 4 unittest.main()测试类中以 test 开头的测试用例
 5 setUp:初始化
 6 tearDown:只要setUp启动成功,不管以test开头的case程序是否执行成功, tearDown 都会被执行
 7 """
 8 from selenium import webdriver
 9 import unittest
10 
11 class login(unittest.TestCase):
12     def setUp(self):
13         self.driver = webdriver.Firefox()
14         self.driver.implicitly_wait(30)
15         self.base_url = 'http://www.51testing.com'
16         self.verificationErrors = []
17         
18     def test_loginpass(self):
19         driver = self.driver
20         driver.get(self.base_url)
21         
22         driver.find_element_by_id('username').clear()
23         driver.find_element_by_id('username').send_keys('username')
24         
25         driver.find_element_by_id('userpass').clear()
26         driver.find_element_by_id('userpass').send_keys('passworld')
27         
28         driver.find_element_by_id('dologin').click()
29         
30         driver.find_element_by_id('xspace-seccode').clear()
31         input_seccode = raw_input('请输入验证码,并按 Enter 键:')
32         driver.find_element_by_id('xspace-seccode').send_keys(input_seccode)
33         driver.find_element_by_id('securitysubmit').click()
34         
35     def tearDown(self):
36         self.driver.quit()
37         self.assertEqual([], self.verificationErrors)
38         
39 if __name__ == '__main__':
40     unittest.main()

 

posted @ 2013-06-10 15:26  Roger|  阅读(208)  评论(0编辑  收藏  举报