Python+Selenium+unittest demo

代码如下:

# coding=utf-8
import time
import unittest
from selenium import webdriver


class BaiduSearch(unittest.TestCase):
    def setUp(self):
        self.driver = webdriver.Chrome()

    def test_search_in_python_org(self):
        driver = self.driver
        driver.get("https://www.baidu.com")
        time.sleep(2)
        driver.find_element_by_id("kw").send_keys("菜鸟教程")
        time.sleep(2)
        driver.find_element_by_id("su").click()
        time.sleep(2)

    def tearDown(self):
        self.driver.close()


if __name__ == "__main__":
    unittest.main()

你可能感兴趣的:(Python,软件测试,python,自动化)