若仅使用selenium无法执行用例和生成报告,只能对页面UI进行操作;
故我的猜想是使用selenium操作页面,结合python框架unittest执行用例+HTMLTestRunner生成测试报告就可做成一个完整的自动化测试流程。
开发环境:
python + selenium + unittest+ HTMLTestRunner
python安装:http://www.cnblogs.com/hongten/p/hongten_python_install.html
selenium安装:http://blog.csdn.net/miaodalengshui/article/details/51605455
unittest安装:python自带框架,无需安装。
HTMLTestRunner安装 :http://blog.csdn.net/a542551042/article/details/46744677
---------------------------------------------------------------------------------------------------------------------------
模块学习:
python+selenium教程:http://www.cnblogs.com/hanxiaobei/p/6108677.html
unittest单元测试框架教程:http://www.cnblogs.com/yufeihlf/p/5707929.htmlunittest
unittest断言: http://blog.csdn.net/julia294/article/details/70098942
HTMLTestRunner使用说明:http://www.cnblogs.com/miniren/p/5301081.html
-----------------------------------------------------------------------------------------------------------------------
简单Dome:
two.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from selenium import webdriver
br = webdriver.Chrome()
br.maximize_window()
br.get('http://www.baidu.com')
def baidu1():
title = br.title
return title
def baidu2():
jg = br.find_element_by_id('jgwab').text
return jg
one.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import unittest
import HTMLTestRunner
import two
class MyTestCase(unittest.TestCase):
# 初始化工作
def setUp(self):
pass
# 退出清理工作
def tearDown(self):
pass
# 具体的测试用例,一定要以test开头
def test_Case1(self):
self.assertMultiLineEqual(two.baidu1(), u'百度一下,你就知道')
def test_Case2(self):
self.assertMultiLineEqual(two.baidu2(), u'京公网安备11000002000001号')
def Suite():
suiteTest = unittest.TestSuite()
suiteTest.addTest(MyTestCase("test_Case1"))
suiteTest.addTest(MyTestCase("test_Case2"))
return suiteTest
if __name__ == '__main__':
# 确定生成报告的路径
filePath = "pyResult.html"
fp = file(filePath, 'wb')
# 生成报告的Title,描述
runner = HTMLTestRunner.HTMLTestRunner(stream=fp, title='Python TestReport', description='This is Python Report')
# runner = unittest.TextTestRunner()
runner.run(Suite())