python+selenium+unittest单元测试框架的使用
上一篇 /
下一篇 2018-08-14 17:52:19
/ 个人分类:python
unittest参考文档:https://docs.python.org/3/library/unittest.html
这是一个测试三种字符串方法的简短脚本:
import unittest
class TestStringMethods(unittest.TestCase):
def test_upper(self):
self.assertEqual('foo'.upper(), 'FOO')
def test_isupper(self):
self.assertTrue('FOO'.isupper())
self.assertFalse('Foo'.isupper())
def test_split(self):
s = 'hello world'
self.assertEqual(s.split(), ['hello', 'world'])
# check that s.split fails when the separator is not a string
with self.assertRaises(TypeError):
s.split(2)
if __name__ == '__main__':
unittest.main()
python+selenium引用:unittest
import unittest
例子:
import unittest
import time
class So(unittest.TestCase):
#初始化设置
def setUp(self):
self.driver = webdriver.Chrome()
self.driver.implicitly_wait(30)
self.base_url = "http://www.so.com"
self.verificationErrors=[]
#360搜索用例
def test_so(self):
driver = self.driver
driver.get(self.base_url)
driver.find_element_by_id("input").click()
driver.find_element_by_id("input").clear()
driver.find_element_by_id("input").send_keys("Selenium Webdriver")
driver.find_element_by_id("search-button").click()
time.sleep(2)
print ("360搜索ok")
driver.close()
def tearDown(self):
self.driver.quit()
self.assertEqual([], self.verificationErrors)
if __name__ == "__main__":
unittest.main()
收藏
举报
TAG: