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

例子:
from selenium import webdriver
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:

 

评分:0

我来说两句

我的栏目

日历

« 2024-04-19  
 123456
78910111213
14151617181920
21222324252627
282930    

我的存档

数据统计

  • 访问量: 1913
  • 日志数: 4
  • 建立时间: 2018-08-14
  • 更新时间: 2018-08-14

RSS订阅

Open Toolbar