UnitTest is the unit test framework for Python,
Similar to the testng inside Java.
From time import sleep
From selenium import Webdriver
Import UnitTest
Class UnitTest (UnitTest. TestCase):
# UnitTest class Inherits Unittest.testcase class
def setUp (self):
# Setup is used to set up initialization work, which is executed before each test case
Self.driver = Webdriver. Firefox ()
Self.base_url = "https://www.baidu.com/"
Self.driver.maximize_window ()
Sleep (2)
def test_baidu (self):
# Search for Chinese test cases
Driver = Self.driver
Driver.get (Self.base_url)
Driver.find_element_by_xpath (".//*[@id = ' kw ']"). Send_keys ("China")
Driver.find_element_by_xpath (".//*[@id = ' su ']"). Click ()
Sleep (2)
Self.assertequal (Driver.find_element_by_xpath (".//*[@id = ' 1 ']/h3/a"). Text, "China _ Baidu Encyclopedia")
# assert China _ Baidu encyclopedia element
def tearDown (self):
# Teardown method is called after each test method is executed for clean-up work after testing
Self.driver.quit ()
if __name__ = = "__main__":
Unittest.main ()
# The entire test process is integrated in the Unitest.main () module, which defaults to the method that starts with test
Python collocation unittest