当前位置:网站首页>App automation "element positioning mode, element operation, mixed application, layered design, code mode execution of pytest command"

App automation "element positioning mode, element operation, mixed application, layered design, code mode execution of pytest command"

2020-12-07 12:40:54 itread01

Stick to original output , Click on the blue word and focus on me

author : QingHan
Blog :oschina、 Cloud + community 、 I know that there are all platforms .

Catalog

  • One 、App How elements are positioned
  • Two 、 Element operation
  • 3、 ... and 、 Testing hybrid applications
  • Four 、 Run as code Pytest command
  • 5、 ... and 、App Automated hierarchical design

App Automation is currently used Appium, Yes Python Version of Uiautomator2. This is directly through Uiautomator2 To do , One is to use the middle Appium To do .Appium Cross platform, cross language .

One 、App How elements are positioned

coordinates idxpathandroid_uiautomatorclassnameaccesiblity_id.

accesiblity_id It's one of Android's ways of locating elements .

Two 、 Element operation

This is with Web Automation is beyond some common operations , It has some extra operations . for example : Slide screen operation 、 Touch screen operation 、 Hybrid applications 、toast Get .

swipe:swipe Also through touchAction To achieve .

Touch screen operation :touchAction

toast:toast Get the Android version 、Appium All versions have requirements .

use uiautomatorview It can't be caught , Through xpath To get toast Information .

xpath The expression   Text matching 
loc ='//*[contains(@text,"{}")]'.format(" Cell phone number or password ")

contains Through xpath In the expression contains Function @text,text In Android , It's an attribute .

xpath Positioning expression , After you get it , Often used is presence.

#  While waiting , You have to use the condition of the element's existence . You can't use the condition that the element is visible .

try:
    WebDriverWait(driver,10,0.01).until(EC.presence_of_elements_located((MobileBy.XPATH,loc)))
    #  ceiling 10 Seconds is enough , Confirm toast How long has it been on the page , It doesn't have 0.5 second , You go to the interval 0.5, Maybe it's gone , You're still here .
    print(driver.find_element_by_xpath(loc).text)
except:
    print(" No match was found toast!!!!")

do Web Automation or whatever , Waiting for elements to be visible . stay toast When we get information , It's waiting for elements to exist , And get the text of it .

There's a question of probability in this place : Use it to get toast, The shorter the time , The higher the probability . May face 1%-10% The failure rate of . Of course, different products are different .

3、 ... and 、 Testing hybrid applications

The primary control element is concerned with html What is the element ID of the page ?

Web In automation, another page is embedded in one page , It's using iframe.webview On behalf of Web view .

If you switch from native controls to web view , The name of the switch is context, The premise of switching is to get it .

Get webview Corresponding context, And then operate in this .

Switch from native control element to html Page , Through context After switching , Should be html Do element positioning in the page .

Uiautomatorview There's no way to find html Page , So use Uc-devtools.

After finding the element , The follow-up is Web It's automated , To see Webview Page time , It has to be turned on debug Pattern , Otherwise you won't see it .

Some online operations can be forced to open it , But the operation process is more complicated , It's going to destroy something .

Hybrid applications are App and Web The combination of Automation . Wechat applet is actually Web Automation , It's just embedded in wechat .

Wechat itself is a App, Operate in wechat , Switch to the applet , Do what you want in a small program Web Automated testing .

Primary control element +html Page : Hybrid applications -webview\ Switch context\uc-devtools\web Automation

Four 、 Run as code Pytest command

import pytest

if __name__ == '__main__':
    pytest.main()

This is to Python Code Pytest command , Let's see main The original code of the function :

Before that cmd Enter pytest -m Filter the tags , such as smoke Label pytest -m smoke, Or designate html Report pytest -m smoke - It's all written here .

pytest -m smoke Such an order , Just write it in code .

It's here , The first argument is the command written , But it's a list , Just save it in the form of a list .

import pytest

if __name__ == '__main__':
    pytest.main(["-m","smoke"])

Separated by spaces in the command line , Put it in the list as well . The execution effect in the code follows cmd As like as two peas .

5、 ... and 、App Automated hierarchical design

App Automation and Web Automation is the same , It's all layered like this :

stay PO You want to click on the element in the pattern 、 You have to wait for elements to be visible , There are also the most basic 4 How to operate elements : Input operation 、 Click operation 、 Get the text of it 、 Get its properties .

Locator It is bound with the element location method and location type .Locator From PageLocators In folder .

The screen is so big ,App Make sure the layout is loose , Finger touch screen , To ensure that clicking on a function will not encounter other .

Actually do automated testing ,Web Web pages are very complex ,App The cycle of automated testing is better than Web Automation time is much shorter .

Write the frame and write the page first , First of all, study the page structure , Take a look at the relevance of page functions .


Public number 「 QingHan software test 」 Starting , More original articles : QingHan software test 103+ Original article , Welcome to pay attention 、 communication , Third party reprint is prohibited without authorization .

版权声明
本文为[itread01]所创,转载请带上原文链接,感谢
https://chowdera.com/2020/12/20201207123703222l.html