程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Airtest automated testing -- Python writing and executing use cases (Part 2)

編輯:Python

Catalog

  1. Guide pack

  2. Connecting device

  3. Write a script

  4. Generate a report

3.2.2 Assertion

3.2.2.1 Assert that there is

assert_exists(v, msg="") There is an assertion target on the device screen

Parameters :

v – The target to check

msg – A short description of the assertion , It will be recorded in the report

trigger :

AssertionError – If the assertion fails

return :

Target coordinates

3.2.2.2 Assertion does not exist

assert_not_exists(v, msg="") The assertion target does not exist on the device screen

Parameters :

v – The target to check

msg – A short description of the assertion , It will be recorded in the report

trigger :

AssertionError – If the assertion fails

return :

Target coordinates

3.2.2.3 Assert equality

assert_equal(first, second, msg="") Assert that two values are equal

Parameters :

first – The first value is

second – Second value

msg – A short description of the assertion , It will be recorded in the report

trigger :

AssertionError – If the assertion fails

return :

Target coordinates

3.2.2.4 Assertion is not equal

assert_not_equal(first, second, msg="") Assert that two values are not equal

Parameters :

first – The first value is

second – Second value

msg – A short description of the assertion , It will be recorded in the report

trigger :

AssertionError – If the assertion fails

return :

Target coordinates

3.3 Other api

3.3.1 airtest.core.api module

init_device(platform=“Android”, uuid=None, **kwargs) Initialization equipment , And set it to the current device

connect_device(uri) use URI String to initialize the device , And set it to the current device

give an example :

android:/// # At present Android equipment , Connect using default parameters

long-range Android equipment , And used custom parameters

android://adbhost:adbport/1234566?cap_method=javacap&touch_method=adb

windows:/// # Local Windows desktop

ios:/// # iOS equipment

device() Return to the device currently in use

set_current(idx) Set the current device

auto_setup(basedir=None, devices=None, logdir=None, project_root=None, compress=None)

Automatically configure the running environment , If there is no currently connected device , Try to connect by default Android equipment

shell(cmd) Run remote on the target device shell Instructions

start_app(package, activity=None) Start the target application on the device

stop_app(package) Terminate the operation of the target application on the device

clear_app(package) Clear the data of the target application

install(filepath, **kwargs) Installation applied to the device

# Support only android

uninstall(package) Unload the application on the device

# Support only android

wake() Wake up and unlock the target device

# Be careful : It may not work on some brand mobile phones

home() return HOME Interface

click(*args, **kwargs) Click once on the current device screen

# and touch The same effect

double_click(v) Double click the coordinates on the current device

pinch(in_or_out=‘in’, center=None, percent=0.5) Execute a double finger on the device screen pinch Kneading operation

in_or_out – Knead inward or expand outward , stay [“in”, “out”] Enumerate a value in

center – pinch The central position of the action , The default value is None Is the center point of the screen

percent – pinch Screen percentage of action , The default value is 0.5

# Support only Android

sleep(secs=1.0) Set a wait sleep Time , It will be displayed in the report

find_all(v) Find all the targets that appear on the device screen and return to their coordinate list

Return to the list of coordinates :[(x, y), (x1, y1), …]

3.3.2 android.core.android

Reference documents :

https://airtest.readthedocs.io/zh_CN/latest/all_module/airtest.core.android.html

3.3.3 android.core.ios

Reference documents :

https://airtest.readthedocs.io/zh_CN/latest/all_module/airtest.core.ios.html

3.3.4 airtest.core.win

Reference documents :

https://airtest.readthedocs.io/zh_CN/latest/all_module/airtest.core.win.html

3.3.5 airtest subpackages

airtest.aircv package

Reference documents :

https://airtest.readthedocs.io/zh_CN/latest/all_module/airtest.aircv.html

airtest.cli package

Reference documents :

https://airtest.readthedocs.io/zh_CN/latest/all_module/airtest.cli.html

airtest.core package

Reference documents :

https://airtest.readthedocs.io/zh_CN/latest/all_module/airtest.core.html

airtest.report package

Reference documents :

https://airtest.readthedocs.io/zh_CN/latest/all_module/airtest.report.html

  1. Generate a report

4.1 Settings before generating the report

  1. Guide pack

from airtest.report.report import simple_report

  1. stay setup Set... In the statement log route , Or will logdir=True

if not cli_setup():

auto_setup(file, logdir=True, devices=[

“Android:///”,

], project_root=“D:/pyworkspace/airtest_demo1/test”)

4.2 Report generation

Insert a code generation report at the end of the code

simple_report(file)

4.3 The style of the report

and AirtestIDE The resulting reports are consistent

The test report is roughly composed of two parts :

The first half :

The name of the report 、 author 、 Report description ( Customizable , See below ) And a quick look, etc . Click any one of the snapshots , The corresponding test information will be displayed below

The second part of :

Each test action and its execution are shown in detail . Click the test action on the left , The details of the execution results of the corresponding actions will be displayed on the right .

And we can also filter different execution results on the right

4.4 Other

4.4.1 log route

Execute the script after initialization , It will be generated in the script directory log.html and log Folder ( There is... In it log.txt). But if we specify it manually logdir The catalog of ,log.txt Will be generated in the specified directory

4.4.2 simple_report Parameters

def simple_report(filepath, logpath=True, logfile=LOGFILE, output=HTML_FILE):

path, name = script_dir_name(filepath)

if logpath is True:

logpath = os.path.join(path, LOGDIR)

rpt = LogToHtml(path, logpath, logfile=logfile, script_name=name)

rpt.report(HTML_TPL, output_file=output)

Which can be passed in logpath= To manually specify the script log Catalog , To simply generate log.html

4.4.3 More complex requirements

There are more complex requirements , For example, you need to specify the export directory export_dir , Or in the script poco sentence , Need to use –pluginpoco.utils.airtest.report

Reference documents :

https://airtest.readthedocs.io/zh_CN/latest/all_module/airtest.report.report.html#airtest.report.report.LogToHtml

【 End 】


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved