Airtest of web automation (a)

Airtest of web automation (a)

[ This document has many places related to gif moving graphs, full-screen viewing] 

Learn Airtest:

Summary:

Airtest was developed by a team Netease automation framework, the use of pre-game test (recognition by the screenshot), and later was applied to Android testing and web testing. A frame image recognition ancestors of this automation framework so powerful from its own development team, this framework is a novel graphical scripting language Sikuli. Sikuli principles of this framework is such that computer users do not need to write the code line by line, but the way the screen with a screen shot, a combination of artifacts with the procedure set them cut out graphics, which is part of Airtest. In addition, Airtest is also based on this UI controls poco search framework that is Netease's own cross-platform UI testing framework, the principle is similar to appium, by the name of the control, the control id to locate the target and the like, and then call the function method, for example, click method (), send_keys () like to click or operation of target control.

Download: http://airtest.netease.com/changelog.html

Airtest show:

This action figure is Airtest official document interception, attentive students may have found: script Airtest realize that python + selenium, has just come into contact with this framework, I think is not that python + selenium repackaged it, there is no new places. But a serious look carefully, will find Airtest powerful place ...

A: Airtest open the browser, you must import the class

Once configured chrome browser, and webdriver (this operation is very simple), click on the top left of the window selenium AirtestIDE of Earth-like icon to open the browser and the Script Editor window will prompt you to import the necessary modules, click yes (already introduced on click No)

Click yes Results: see here in addition to introducing the necessary classes, it also examples of the driver: (driver = WebChrome ()), and the wait time set recessive: (driver.implicitly_wait (20)), which are can be edited

 

start_web button: implement driver.get () operation

start_web button click will generate the code, so there are many types of buttons, they are referred to directly generate code for this category :( button button, click generate code directly. without extra operation, but some of the buttons according to the current browser actual generate different parameters. for Firefox, the viewer will not appear on the page, but directly generated code)

 

  1. start_web : Click this button to generate the address of the current page statement browser access. Example: driver.get ( "https://github.com/AirtestProject")

  2. Snapshot : Click this button to generate statements of current page screenshot. Example: driver.snapshot ()

  3. new_tab : Click this button to generate a jump in the latest statement tabs appear, usually used in a later statement to generate a new tab. Example: driver.switch_to_latest_window ()

  4. previous_tab : Click this button to generate a current to jump to the previous tab tab (the parent tag) statements. Example: driver.switch_to_last_window ()

  5. the Back : Click this button to generate back to the statement on one page. Example: driver.back ()

  6. Forward : Click this button to generate advance to the next page of the statement. Example: driver.forward ()

airtest- record:

 

As shown in Figure moving: After clicking AirtestIDE window in selenium in the top right corner of the camera can start recording, each step will be in the browser becomes the python code is stored in the Script Editor window. Of course, the recording will be some disadvantages, so it is necessary to use discretion. Drawbacks: You can not locate the element id, name this simple way of positioning may occur when too long and xpath bug (here you can try it yourself) solutions, all the elements positioning can write your own, you can also airtest_touch (click for image recognition) skip positioning elements - go into detail later

Similar to the record button there are also many, these buttons are called: class after Inspect button (this type of button clicks, will not generate code directly; the browser will enter the inspect mode, users can choose their own browser think to operate the element is clicked, the edit box will then locate the corresponding elements of the generated code, and generate the code corresponding to the operation)

  1. Inspect button : Click this button, select the page element, it will generate a positioning statement to that element. But it does not generate a corresponding operation code in the back, the user can add their own selenium statements want to perform. Example: driver.find_element_by_xpath ( "// * [@ the above mentioned id = \" navbarContent \ "] / ul / li [2] / A") also supports the other methods of finding elements *

  2. touch button : This button, when clicked, will generate the code click on the corresponding element. Example: driver.find_element_by_xpath ( "// * [@ ID = \" navbarContent \ "] / UL / Li [2] / A") the Click ().

  3. text button : Click this button to generate the input text of a statement within the specified elements, the generated code, users need to enter the text you wish to enter inside. At the same time, the user can define the execution of a keyboard event after input, such as a carriage return. Example: driver.find_element_by_xpath ( "INPUT // [placeholder @ = 'Search']") send_keys ( "Airtest the Project", Keys.ENTER).

  4. assert Button : assert button click, generate an assert statement whether page elements are present. This is a Airtest-Selenium package statements at run-time parameter method tries to find the representative element, if find returns True, if not found returns False. Scripts can be used to test whether a successful interpretation. Example: driver.assert_exist ( "// * [@ ID = \" JS-pjax-Container \ "] / div / header / div / NAV / A [2]", "XPath")

Airtest——Airtest_touch

 

Avoids complex positioning element, and the case of frequent switching frame

airtest-assert_template (picture identification based on the assertion)

 

The above two buttons are Airtest carrying image recognition button (this type of button, click into the clipped image mode, the current screen shots and marquee area.)

 

  1. airtest_touch : Click this button to turn the screen shot mode, the current screen screenshots, can intercept area of the picture from the browser. Click on the image to represent the interception. example:

    1_airtest_touch

  2. assert_template : Click this button, the current screenshot. It represents the assertion that there is a current picture browser. example

    1_assert_template

 

airtest-- test report:

Airtest script is automatically generated after completion of the test run report, click on the top of the IDE LOG tab button and you can view, every step of the test report will record the entire script of the latest version of the test report and the style moving map display and some do not the same, but the content is about the same:

Airtest other actions:

Airtest pure python code is generated code, there are many other operations can be implemented directly python + selenium

upload files:

1, upload files for input elements on the page positioning, it should be the type attribute to file (usually the box or button to upload the file)

2, with the positioning element driver.find_element_by ...

3, the elements send_Keys (), the contents of the file you want to upload

Loading a user profile: sometimes need to bypass the authentication code, or use a browser to use when configuring other

1. Create ChromeOptions before the browser startup code () property option

2, in option () method by adding attributes add_argument '--user - data - dir'

3, before starting the browser calls webChrome method, plus chrome_options = option parameter loading a user profile

4, visit the Web site, you can load the local browser cookie that has been recorded

code show as below:

    = the Option ChromeOptions () the Option. add_argument ( ' - the User - the Data - dir = "path to your browser stores the configuration file" ') Driver = WebChrome ( chrome_options = the Option)



 

Attachment:

Prior to this attached a presentation and write a little script:

Had wanted to use the process to achieve this script to explain themselves to record gif, but the effect is too record is not very good, too time-consuming, so he gave up.

Wave Airtest summary of the highlights:

1, can quickly locate elements, a key to achieve many of our common action (click, enter, forward, backward, screenshots ...)

2, selenium assertions about the elements of the package achieved

3, you can record a script, you reduce the difficulty of automation

4, a switch windows, handles less went through trouble of switching windows

5, click on the picture identification and assertions, to avoid the difficult positioning element, iframe frequent switching problem

The entire script implementation process in about 2 minutes, Airtest to assist in writing automated scripts efficiency is really high, but the only question now is can not find the entire automation framework can be expected to cooperate, it is difficult to achieve PO design, test report for the entire project is also quite redundant.

But the script is run Airtest recorded in other python environment, we need to install two libraries on which it relies: 'atrtest' and 'poco', this is the case, the above stated disadvantages or have a solution (re-posted next speak).

 

 

Guess you like

Origin www.cnblogs.com/fccyccf/p/11613246.html