一袍暴、webUI自動(dòng)化
1十绑、airtest簡介
Airtest是網(wǎng)易出品的一款基于圖像識(shí)別和poco控件識(shí)別的一款UI自動(dòng)化測試工具。
官方網(wǎng)站:http://airtest.netease.com/
安裝:官方網(wǎng)站下載文件為zip壓縮包文件,直接解壓储笑,即可使用
2茧泪、啟動(dòng)
1)設(shè)置瀏覽器驅(qū)動(dòng)和Log路徑
做ui自動(dòng)化蜓氨,首先要設(shè)置瀏覽器:在選項(xiàng)-設(shè)置中**
image.png
默認(rèn)Log選項(xiàng)也在此頁面
2)啟動(dòng)瀏覽器
首先點(diǎn)擊窗口-selenium window,打開輔助窗口队伟,然后點(diǎn)擊圓球圖標(biāo)啟動(dòng)瀏覽器
image.png
然后點(diǎn)擊提示語中的“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:定位并點(diǎn)擊頁面元素港令,執(zhí)行click操作
text:定位并點(diǎn)擊元素,執(zhí)行sendkeys操作
assert:斷言
snapshot:截屏
previous_tab&new_tab:瀏覽器標(biāo)簽頁的切換
airtest_touch:當(dāng)touch定位不到元素時(shí)候锈颗,可以用此功能缠借,會(huì)在瀏覽器指定位置截屏并點(diǎn)擊,和sikuli有點(diǎn)類似
assert_template:就是斷言airtest_touch框選的圖片是否存在
※iframe切換要用python語法:
driver.switch_to_frame()宜猜,里面只能是id或者name泼返,或者索引
driver.switch_to_default_content()回到主界面
image.png
4、Record按鈕姨拥,就是錄制绅喉,點(diǎn)擊之后,會(huì)錄制在瀏覽器上的操作叫乌,并自動(dòng)生成代碼
image.png