<Learning Selenium Testing To
2018-02-22 本文已影响11人
bluescorpio
- Selenium is a set of tools for automating browsers
- Selenium IDE: This is a Firefox add-in used to record and play back the Selenium scripts with Firefox.
- Selenium WebDriver: This is a programming interface for developing advanced Selenium scripts using programming languages.
- Installing the Seleniun package: pip install -U selenium
- The selenium.webdriver module implements the browser driver classes that are supported by Selenium, including Firefox, Chrome, Interne Explorer, Safari, and various other browsers, and RemoteWebDriver to test on browsers that are hosted on remote machines
- Test Fixture: By using a test fixture, we can define the prepartion needed to perform one or more tests and any associated clean-up actions
- Test Case: A test case is the smallest unit of testing in unittest. It checks for a specific response to a particular set of actions and inputs using various assert methods provided by the unitest library. The unittest library provides a base class called TestCase that may be used to create new test cases.
- Test Suite: A test suite is a collection of multiple tests or test cases to create groups of tests representing specific functionality or modules of the application under test, which will be executed together.
- The starting point for test cases is the setUp() method, which we can use to perform some tasks at the start of each test or all the tests that will be defined in the class. The method takes no arguments and doesn't return anything. When a setUp() method is defined, the test runner will run that method prior to each test method.
- For each test method that the test runner finds, it executes the setUp() method before executing the test method.
- How about sharing a single Firefox instance between the methods instead of creating a new instance every time? This can be done by using the setUpClass() and tearDownClass() methods and using the @classmethod decorator. These methods allow us to initialize values at the classes level instead of the method level and then share these values between hte test methods.
- Using the TestSuites feature of unittest, we can collect various tests into logical groups and then into a unified test suite that can be run with a single command
- Selenium provides various find_element_by methods to find elements on a web page. These methods search for an element based on the criteria supplied to them. If a matching element is found, an instance of WebElement is returned or the NoSuchElementException exception is thrown if Selenium is not able to find any element matching the search criteria
- To create a data-driven test we need to use the @ddt decorator for the test class and use the @data decorator on the data-driven test methods.
- The @data decorator takes as many arguments as we have values that we want to feed to the test.
- The page object pattern is making tests separate from low-level actions, and providing a high-level abstraction.
- The page object pattern offers creating an object representing each web page from the application under test. We can define classes for each page, modeling all attributes and actions for that page.