1.5 web automation testing¶
Selenium is a web automation testing framework that supports a variety of browsers, including Chrome, Safari, Firefox, and other major browsers.
Thanks to Selenium’s good support for Python, the Airtest-Selenium plugin was added to the Airtest Project. AirtestIDE can be used for web automation script recording, running and report generation. This article describes how to use AirtestIDE for web automation testing using Chrome driver.
Please note that this article is above 1,000 words. It may take up to 4 minutes to read it fully
Airtest-Selenium test framework diagram¶
Recording video example¶
Automated recording steps¶
- Install locally the latest version of AirtestIDE and Chrome browser;
- Open the Selenium auxiliary window: “Window” -> “Selenium Window”
- Set Chrome local path: “Options” -> “Settings” -> “Selenium” -> “Set Chrome Path”;
- Open the browser and generate the initialization code: Click Open the browser - click the prompt that pops up in the edit box to generate the initialization code;
from selenium import webdriver from selenium.webdriver.common.keys import Keys from airtest_selenium.proxy import WebChrome driver = WebChrome() driver.implicitly_wait(20)
- Generate code to access the URL to be tested: enter the web page to be tested in the browser and then click start_web in the auxiliary window:
- Start Airtest-Selenium script recording: Click Record and operate in the browser
- End the recording of the script: Click the Run Script button
- After the run, click the report button to view the report
When the user wants to generate a single code statement separately, the button of the auxiliary window can be used to help generate the desired operation. The buttons are divided into two categories which functions are described in detail below.
Multi-tab recording logic¶
Airtest-Selenium is a test framework that supports multi-tab operations. The rules for switching between different tabs are described in detail in this section.
Airtest-Selenium uses the
driver.switch_to_latest_window() interfaces to handle the logic between different tabs.
driver.switch_to_latest_window after a new tab is generated, for example, as a result of clicking a certain element:
The browser is originally on the first tab page (A).
After the first sentence runs, another tab page is generated (B). Since the browser’s behaviour is to jump to the new tab, most use cases would need to operate on this newly opened B tab.
In order to tell the web driver to load the B’s dom tree structure instead of A’s, the
driver.switch_to_latest_window() statement is required.
driver.switch_to_last_window() statement to go back to the tab prior to the
In the example above, after the operation on the B tab page is completed, use
driver.switch_to_last_window() in order to tell the web driver to load the A’s dom tree structure again instead of B’s.
The next line of script will be executed on the A tab.
In the recording mode, when the user generates a new tab through an operation, Airtest-Selenium recognizes the change of the tab and switches to the latest tab, generating the corresponding code in the edit box. Click on ‘Close tab’ and Airtest-Selenium will jump back to the previous tab, generating the code to close and recall the tab in the edit box.
Here is a small video to see the effects of multi-tab recording: