编写web测试用例
untitled├── runtest.py
└── test_case
├── __init__.py
├── test_baidu.py
└── test_youdao.py
test_baidu.py
# -*- coding:utf-8 -*-
from selenium import webdriver
import unittest
import time
class MyTest(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Firefox()
self.driver.maximize_window()
self.driver.implicitly_wait(10)
self.base_url = 'http://www.baidu.com'
def test_baidu(self):
driver = self.driver
driver.get(self.base_url+'/')
driver.find_element_by_id('kw').clear()
driver.find_element_by_id('kw').send_keys('妞给爷笑一个')
driver.find_element_by_id('su').click()
time.sleep(2)
title = driver.title
self.assertEqual(title,'妞给爷笑一个_百度搜索')
def tearDown(self):
self.driver.quit()
if __name__ == "__main__":
unittest.main() #main()方法使用TestLoader类来搜索所有包含在该模块中已test命名开头的测试方法并自动执行它们
test_youdao.py
# -*- coding:utf-8 -*-
from selenium import webdriver
import unittest
import time
class Mytest(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Firefox()
self.driver.maximize_window()
self.driver.implicitly_wait(10)
self.base_url = 'http://www.youdao.com'
def test_youdao(self):
driver = self.driver
driver.get(self.base_url+'/')
driver.find_element_by_id("translateContent").clear()
driver.find_element_by_id('translateContent').send_keys('妞给爷笑一个')
driver.find_element_by_xpath('//*[@id="form"]/button').click()
time.sleep(2)
def tearDown(self):
self.driver.close()
if __name__ == "__main__":
unittest.main()
runtest.py
# -*- coding:utf-8 -*-
import unittest
from test_case import test_baidu
from test_case import test_youdao
# 构建测试集
suite = unittest.TestSuite()
#suite.addTest(test_baidu('test_baidu'))
suite.addTest(test_baidu.MyTest('test_baidu'))
suite.addTest(test_youdao.Mytest('test_youdao'))
if __name__ == '__main__':
# 执行测试
runner = unittest.TextTestRunner()
runner.run(suite)
这是 什么工具的?
哦哦 selenium 这个是基于python selenium写的吗 建议使用pom框架
页:
[1]