web foundation Automation

Automation effect: used for regression testing repeatedly in code execution working tools: Python + selenium (frame) + unittest + HtmlTestRunner selenium: web testing framework, encapsulates the major browser driven api unittest: unit testing framework, to load all use cases performing HtmlTestRunner: generating Html test report format category: Interface automation web automation app automated web automation: positioning elements: id positioned id = kw name Location name = wd class positioning class = s_ipt link_text positioning text location tag_name positioning tab positioned xpath Location: / / relative path / absolute path to the current node contains:. comprising "// a [contains (@ id, 'kw')]" starts-with what elements beginning with '// input [starts-with (@ name,' w ' )] 'browser operation: maximize browser d.maximize_window () to close the current window handle corresponding d.close () to exit the browser and end cheomedriver process d.quit () to open the url d.get () Gets the current page title d.title browser forward d.forward () browser back d.back () browser refresh d.refresh () Gets the current page url d.current_url get the browser name d.nam e screenshot d.get_screenshot_as_file ( "") page elements object manipulation: click () Click send_keys (str) Gets the label name text input tag_name get clear empty label text contents of the object get_attribute (attributes) Gets the element object's properties is_displayed () to determine page elements is visible, the frame switch returns a Boolean value: d.switch_to. frame ( "") d.switch_to.default_content () handles switching: a.switch_to.window (a.window_handles) waiting time: the time.sleep forced to wait (in seconds) to wait recessive implicitly_wait (seconds) waiting a predetermined time All elements of the page loaded, exceeds the set number of seconds is given explicit wait b = WebDriverWait (webdriver, timeout, frequency) b.unti (function, message = "") until the internal function performs incoming, will whether the set frequency detecting element is loaded, if the load is positioned within the set time, otherwise an error keyboard events: by introducing selenium from selenium.webdriver.config.keys import Keys simulated keyboard simulation Select: C = wait.until (lambda x: x.find_element_by_id ( 'kw')) c.send_keys ( "game of life") c.send_keys (Keys.CONTROL, "a") analog Enter: c = wait.until (lambda x : x.find_element_by_id ( 'su')) c.send_keys ( "game of life") c.send_keys (Keys.ENTER) mouse events: import from selenium.webdrive.config.action_chains import ActionChains double click: b = a.find_element_by_id ( "kw") b.send_keys ( "Gamer Health ") ActionChains (a) .double_click (b) .perform () Mouse movement: b = a.find_element_by_xpath ( ' ), The "map")) print (b) ec.text_to_be_present_in_element_value (()): value determined property tag is equal to the incoming text, returns a Boolean value b = wait.until (ec.text_to_be_present_in_element_value (( "id", "kw"), "game of life")) print (b) * ec.alert_is_present () (a): to determine whether there is a page pop, if present, directly into pop, there is no return False b = ec.alert_is_present () (a) print (b) ec.title_is (): get the page title, the title passed judgment and equality, returns a Boolean value b = wait.until (ec.title_is ( "Baidu, you know.") ) print (b) * ec.frame_to_be_available_and_switch_to_it (()): determining whether the frame may be cut, can be cut into the frame, otherwise False b = ec.frame_to_be_available_and_switch_to_it (( "xpath", "pa")) (a) print (b ) class decorator: decorator higher order function = + + syntax function closure glucose: without modifying the function is called the premise of how to add a new feature function, the function does not modify the source @classmethod: the class function attributes declared as class attributes, can not directly access the instance properties @staticme thod: The function attributes declared class static properties, static properties and function attributes can not directly access the class and instance properties @property: The function attribute class declaration after property, Call without parentheses and the unittest (unit testing) frame: Inheritance test class, the use case to be introduced from unittest begin test import TestCase class MyTest (TestCase): When @classmethod # entire test class starts, execute setUpClass, performed only once def setUpClass (cls): pass # before each use case executed, perform setUp def setUp (self): pass # after each use case are performed tearDown def tearDown (self): pass @classmethod # At the end of the test the whole class, perform tearDownClass , performed only once def tearDownClass (cls): pass def test_01 (self): # determine the expected results and the actual results are equal, not equal an error is thrown, execution failed self.assertEqual use cases ( "expected results", "actual results" ) # Analyzing the expected results and the actual results are not equal, equal, an error is thrown on failure self.assertNotEqual ( "expected results", "actual results") is determined by the left argument Example # is smaller than the right parameters self.assertLess (1,2 ) # actual judgment result is not False self.assertFalse (False) PO mode: object layer: the BasePage class encapsulates all operations of selenium (Initialization, custom page function) Elemental layer: a package page elements of a page package class business layer: the business layer defines all classes must inherit BasePage service layer encapsulating projects all business processes a process a class with Example Layer: Examples layer and data, element, the traffic separating the service layer function calls, test execution Pass # before each use case executed, perform setUp def setUp (self): pass # after each use case are performed tearDown def tearDown (self): pass @classmethod # test class at the end of the whole, to perform tearDownClass, performed only once def tearDownClass (cls): pass def test_01 (self): # determine the expected results and the actual results are equal, not equal an error is thrown, execution failed self.assertEqual ( "expected results", "actual results") to determine the expected use case # the results and the actual results are not equal, equal, an error is thrown on failure self.assertNotEqual ( "expected results", "actual results") is determined by the left argument Example # is smaller than the right parameters self.assertLess (1,2) # determine the actual the result is not False self.assertFalse (False) PO mode: object layer: the BasePage class encapsulates all operations selenium (initialization function defined page) elemental layer: a package encapsulating a page elements of a page-based service layer: all the service layer defines classes inherit BasePage be encapsulated project business layer processes all business processes that a class is a layer of Example: EXAMPLE layer and data elements Business call the business layer separation function, test case execution Pass # before each use case executed, perform setUp def setUp (self): pass # after each use case are performed tearDown def tearDown (self): pass @classmethod # test class at the end of the whole, to perform tearDownClass, performed only once def tearDownClass (cls): pass def test_01 (self): # determine the expected results and the actual results are equal, not equal an error is thrown, execution failed self.assertEqual ( "expected results", "actual results") to determine the expected use case # the results and the actual results are not equal, equal, an error is thrown on failure self.assertNotEqual ( "expected results", "actual results") is determined by the left argument Example # is smaller than the right parameters self.assertLess (1,2) # determine the actual the result is not False self.assertFalse (False) PO mode: object layer: the BasePage class encapsulates all operations selenium (initialization function defined page) elemental layer: a package encapsulating a page elements of a page-based service layer: all the service layer defines classes inherit BasePage be encapsulated project business layer processes all business processes that a class is a layer of Example: EXAMPLE layer and data elements Business call the business layer separation function, test case execution

Guess you like

Origin www.cnblogs.com/szwlycw/p/11544501.html