The road of airtest

airtest - poco

一、poco辅助窗功能

1、选择poco模式

测试什么选择对应什么

注意:(android、ios原生不需要接入poco-sdk,其他要)

 

2、检索控件

锁定检索

跟随检索

3、录制脚本

二、API介绍&定位选择器

①基本选择器利用元素的一些基本属性来进行定位,比如name、text等等

eg:poco(name="网易云音乐")

②相对选择器利用控件之间的父子关系、爷孙关系和兄弟关系等来定位控件,例如 parent()、child()、offspring()等

eg:poco("LinearLayoutCompat").child("搜索")

③空间顺序选择器常用于Ul树中多个相同名称的节点定位,根据节点在Ul树的索引顺序进行定位,索引坐标从0开始

poco("mainActivityTab").offspring("aActionBar$Tab")[0]

 

①点击操作:

poco("star_single").click()

poco('star_single'). long_click()

 

②读取和设置控件的属性:

poco("star_single").get_name()

poco("star_single").attr('name')

poco("star_single").get_text()

poco("pos_input").set_text("123")

poco("pos_input"). setattr('text',"456")

 

③判断元素是否存在:

poco(XXX).exists()

 

④拖动与滑动:

poco("star"). drag_to (poco("shel I"))

 

⑤内部偏移和外部偏移:

poco("pearl").focus([0.1,0.1]).long_click()

poco("pearl").focus([0.9,0.9]). long_click()

poco("pearl").focus([0.5,-3]). long_click()

 

⑥遍历元素:

for star in poco("playDragAndDrop").child("star"):star. drag_to (poco("shell"))

 

⑦等待事件:

poco("bomb").wait_for_appearance()

poco("bomb").wait_for_disappearance()

yellow = poco("yellow")

blue = poco("blue")

black = poco("black")

poco.wait_for_all([yellow,blue,black])

poco.wait_for_any([bomb,yellow,blue])

 

可以下载对应demo进行操作:android_poco_demo download

其他详情可以查看:官网功能详情

 

airtest - selenium

一、元素定位语句

1、find_element_by_id()

2、find_element_by_name()

3、find_element_by_class_name()

4、find_element_by_xpath()

5、find_element_by_link_text()

6、find_element_by_partial_link_text()

7、find_element_by_css_selector()

二、操作元素

元素点击:

driver.find_element_by_xpath("[@id=\"right_content\"]").click()

输入:

driver.find_element_by_id("title").send_keys("123")

元素存在:

driver.assert_exist("//div[@alt='到学术首页']","xpath","请填写测试点.")

三、元素定位与实操

下拉框定位(用到的话,需要先引用)

引入下拉框类:Select

from selenium.webdriver.support.select import Select

定位到下拉框元素:

ime_select = driver.find_element_by_id('ime')

实例下拉框类:

select = Select(ime_select)

3种定位方式:

select.select_by_index(0)

select.select_by_value('2')

select.select_by_visible_text('关闭')

 

弹出框定位(用到的话,需要先引用)

引入弹出框类:Alert

from selenium.webdriver.common.alert import Alert

获取弹出框的文本信息:

driver. switch_to_alert().text

点击弹出框的确认按钮:

driver.switch_to_alert().accept()

 

四、Selenium辅助窗口功能

1、窗口开启Selenium Window

2、设置Chrome Path路径

3、插入初始化语句

4、Selenium辅助窗功能实操

浏览器截图:driver.airtest_touch

5、利用web F12功能,定位xpath属性

 

posted on 2023-12-04 00:05  Damon_Ding  阅读(3)  评论(0编辑  收藏  举报