To say what kind of a relationship between unit testing and UI Automation, say my personal experience, I do not have much experience in this area, because the work itself is less, there is a functional test point for me this lazy person, more complex than unit testing ... Considering the correspondence between the processing logic and the UI of the unit test, according to the test idea of layered automation, the Ui>> interface >> the bottom is the unit, for the unit level Automation test, is the white box test category, with a piece of code to test a piece of code, And we need to write our automated test scripts using some of the organizational drivers of the unit test framework, and UnitTest is the unit test framework that comes with python, and we don't have to delve into it, we just use a part of the rule method encapsulated by UnitTest to populate your script
#Coding:utf-8" "@author: Hx@desc: Focus on learning unittest usage Note setup/setupclass, Teardown/teardownclass difference 1.setUp: Run 2.tearDown before each test function runs: After each test function executes 3.setUpClass: The @classmethod adorner must be used, all tests run once before 4.tearDownClass: The @classmethod adorner must be used, All test runs once run once UnitTest also has some less commonly used adorners: @unittest. Skip (reason): Skip test unconditionally, reason describe why you skipped the test @unittest.skipif (Condititon, Reason): Condititon is true when skipping test @unittest.skipunless (condition, reason): condition Skip Test @unittest.expectedfailure When not true: if test fails, this test does not count toward the number of failed case" "ImportUnitTestImport Time fromSeleniumImportWebdriverclasssearchtest (unittest. TestCase): @classmethoddefSetupClass (CLS): Cls.driver=Webdriver. Chrome () cls.driver.implicitly_wait (30) Cls.driver.maximize_window () Cls.base_url='http://www.baidu.com/'cls.driver.get (cls.base_url) Cls.search_text= cls.driver.find_element_by_id ('kw') cls.search_btn= cls.driver.find_element_by_id ('su') deftest_search_btn_displayed (self): Self.asserttrue (self.search_btn.is_displayed ()) Self.asserttrue (Self.s Earch_btn.is_enabled ())deftest_search_text_maxlength (self): Max_length= Self.search_text.get_attribute ('maxlength') self.assertequal ('255', Max_length)defTest_search (self): Self.search_text.clear () Self.search_text.send_keys ('Blog Park') Self.search_btn.click () Time.sleep (4) Title=Self.driver.title self.assertequal (title, U'Blog Park _ Baidu Search') @classmethoddefTeardownclass (CLS): Cls.driver.quit ()if __name__=='__main__': Unittest.main (verbosity= 3)
Python unittest frame Decorator