python—airtest

一、webUI自动化

1、airtest简介

Airtest是网易出品的一款基于图像识别和poco控件识别的一款UI自动化测试工具。
官方网站:http://airtest.netease.com/
安装:官方网站下载文件为zip压缩包文件,直接解压,即可使用

2、启动

1)设置浏览器驱动和Log路径
做ui自动化,首先要设置浏览器:在选项-设置中**

image.png

默认Log选项也在此页面
2)启动浏览器
首先点击窗口-selenium window,打开辅助窗口,然后点击圆球图标启动浏览器
image.png

然后点击提示语中的“Yes”,生成了初始化代码

# -*- encoding=utf8 -*-
__author__ = "小二哥"

from airtest.core.api import *

auto_setup(__file__)
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from airtest_selenium.proxy import WebChrome
driver = WebChrome()
driver.implicitly_wait(20)

3、编写脚本,功能介绍

start_web:访问指定url
touch:定位并点击页面元素,执行click操作
text:定位并点击元素,执行sendkeys操作
assert:断言
snapshot:截屏
previous_tab&new_tab:浏览器标签页的切换
airtest_touch:当touch定位不到元素时候,可以用此功能,会在浏览器指定位置截屏并点击,和sikuli有点类似
assert_template:就是断言airtest_touch框选的图片是否存在
※iframe切换要用python语法:
driver.switch_to_frame(),里面只能是id或者name,或者索引
driver.switch_to_default_content()回到主界面


image.png
4、Record按钮,就是录制,点击之后,会录制在浏览器上的操作,并自动生成代码
image.png

你可能感兴趣的:(python—airtest)