In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "the brief introduction and concrete use of Selenium automation framework", interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Now let the editor to take you to learn "the brief introduction and specific use of the Selenium automation framework"!
What is Selenium?
Selenium is a browser-based automation tool that provides an end-to-end web automation solution across platforms and browsers. Selenium mainly consists of three parts: Selenium IDE, Selenium WebDriver and Selenium Grid:
An extension of Selenium IDE:Firefox that allows recording and playback and exports recording operations into test cases in multiple languages (such as java,python, etc.).
Selenium WebDriver: provides the API needed for Web automation, primarily for browser control, page element selection, and debugging. Different browsers require different WebDriver.
Selenium Grid: provides the ability to run selenium tests on different browsers on different machines
In this paper, we use Python combined with Selenium WebDriver library to build an automated testing framework.
II. Automated testing framework
A typical automated testing framework generally includes use case management module, automatic execution controller, report generation module and log module, which complement each other.
Next, let's introduce the logical units of each module:
1) use case management module
The use case management module includes operation units such as adding, modifying and deleting. These units will also involve the use case writing mode, the management of the test database, the reusable library and so on.
2) Automation controller
The controller is the organization module for automating the execution of use cases, which is mainly responsible for how to execute our test cases
3) report generation module
Mainly responsible for the generation of reports after the implementation of use cases, generally in HTML format, the information is mainly the implementation of use cases. You can also configure the ability to send mail.
4) log module
It is mainly used to record the execution of use cases in order to efficiently investigate the failure information of use cases and track the implementation of use cases.
Design and implementation of automation framework
1. Demand analysis
First of all, our test object is a web platform, and the framework based on this platform should include test case management, test execution controller, test report and test log generation.
2. Design and implementation
1) Page management
Suppose the test web object is a typical single-page application, so we use the page mode. Page mode
It is the link between the page and the test case, which abstracts each page into a separate class, which provides the location and operation of the page elements for the test case.
BaseClass, as a parent class, contains only driver member variables, which are used to identify WebDriver in Selenium so that page elements can be located in subclasses. LoginClass and PageClass, as subclasses, provide methods for locating and manipulating page elements. Such as the login page.
From the page, the elements that need to be operated are login user name, password, next automatic login and login button. The specific implementation code is as follows:
Page parent class BaseClass.py
LoginClass inherits from BaseClass and performs login element location and operation implementation. Username and password are located in the code, and the action to set the user name and password is added.
2) Common library module
The common library module serves for the creation of test cases, including constants, common functions, logs, reports and so on.
Common.py
The test case information class is used to identify test cases, and includes execution case and execution result information, mainly including the following fields.
Logs are mainly used to record test case execution steps and error messages. Different information has different log levels, such as Information,Warning,Critical and Debug. Because each test case produces fewer log entries, only the highest level of log printing, that is, the Debug level, is used in the test framework, which also prints out all other log level information. In the specific implementation, the logging class library in the Python standard library is referenced in order to more easily control the log output.
3) Test case warehouse
The use case warehouse is mainly used to organize automated test cases. Each test case is abstracted into a separate class and inherits from the unittest.TestCase class. The unittest library in Python provides rich support for testing frameworks, including setUp and tearDown methods for test cases, which can be rewritten during the implementation of the use case. Relying on the page methods and common functions implemented by the page management and common library modules, the writing of each test case script will be very clear and concise.
From this test case, we can see
1. Some instantiation work before executing test cases is defined in Setup.
2. TearDown cleaned up and wrote log files after the test.
3. Test steps, test data and test checkpoints are very clear and easy to change (such as username and password)
4. Log level is only Debug, so you only need to use the same Log method to write log.
3) use case execution module
The execution module is mainly used to control the batch execution of test case scripts to form a test set. The execution of the use case refers to the subprocess in the Python standard library to execute the shell command of nosetests, thus executing the use cases in a given set of test cases. The test case set is a simple plain text file, which uses the .txt file testcases.txt in the implementation.
Test case scripts that are not marked with "#" before the use case will be executed, while those marked with "#" will be ignored, so that the execution of the test suite can be easily controlled, and of course, different files can be created to execute different test sets.
4. Modules that need to be improved
The existing implemented testing framework can already meet the automation requirements of web objects, but there are still some areas that can be improved, such as:
1) some use cases can try data-driven
2) encapsulate the By function of selenium twice to locate elements more efficiently
3) there is no continuous integration.
At this point, I believe you have a deeper understanding of the "brief introduction and specific use of the Selenium automation framework". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.