2026/1/19 2:49:48
网站建设
项目流程
淘客网站让别人做,全国装修公司大概多少家,app推广兼职,响应式网站建设公司1. 前言
一直以来#xff0c;大家都还挺关注 Airtest是否有剪切板功能 的。从Airtest1.3.1版本起#xff0c;我们新增了Android、iOS设备的剪切板功能#xff0c;自此#xff0c;3大平台的剪切板功能就齐全啦。
正好趁这个机会#xff0c;我们给各大平台的剪切板功能做个…1. 前言一直以来大家都还挺关注Airtest是否有剪切板功能的。从Airtest1.3.1版本起我们新增了Android、iOS设备的剪切板功能自此3大平台的剪切板功能就齐全啦。正好趁这个机会我们给各大平台的剪切板功能做个合集方便同学们查阅使用~2. Android设备的剪切板功能Android设备的剪切板功能包含设置剪切板内容、获取剪切板内容、剪切板粘贴# -*- encodingutf8 -*-__author__ AirtestProjectfrom airtest.core.api import *auto_setup(__file__)text_1 test_clipboardset_clipboard(text_1) # 设置剪切板内容get_text get_clipboard() # 获得剪切板内容print(get_text) # - test_clipboard# 剪切板粘贴接口paste() # text(get_clipboard())3. iOS设备的剪切板功能iOS的剪切板功能和Android是大同小异的对于本地iOS设备特别是本地机器上只安装了一个WDA的我们无需在使用剪切板功能时指定WDA的bundle ID但是对于远程iOS设备我们必须指定WDA的bundle ID# 远程iOS设备text_1 test_clipboardbundle_id com.2303xxxxxxxxx.WebDriverAgentRunner.xctrunnerset_clipboard(text_1,bundle_id) # 设置剪切板内容get_text get_clipboard(bundle_id) # 获得剪切板内容print(get_text) # - test_clipboard# 剪切板粘贴接口paste(bundle_id) # text(get_clipboard())否则会出现如下的报错Traceback (most recent call last):File airtest\cli\runner.py, line 75, in runTestFile site-packages\six.py, line 703, in reraiseFile airtest\cli\runner.py, line 72, in runTestFile D:\demo\untitled.air\untitled.py, line 9, in moduleset_clipboard(text_1) # 设置剪切板内容File airtest\utils\logwraper.py, line 131, in wrapperFile airtest\core\api.py, line 698, in set_clipboardFile E:\AirtestIDE-win-1.2.16\AirtestIDE\airtest\core\ios\ios.py, line 47, in wrapperreturn func(self, *args, **kwargs)File E:\AirtestIDE-win-1.2.16\AirtestIDE\airtest\core\ios\ios.py, line 956, in set_clipboarde.g. set_clipboard(content, wda_bundle_id).)RuntimeError: Remote device need to set running wda bundle id parameter, e.g. set_clipboard(content, wda_bundle_id).----------------------------------------------------------------------Ran 1 test in 2.169sFAILED (errors1)[Finished]1小tips关于如何获取WDA的bundle ID我们可以使用Airtest1.3.0新增的iOS接口来查询# -*- encodingutf8 -*-__author__ AirtestProjectfrom airtest.core.api import *import airtestauto_setup(__file__)dev device()#列出并打印用户安装的APPprint(---------以下是用户安装的APP的信息-----------)user_app dev.list_app(user)print(user_app)此时我们安装在手机上的WDA信息也会被打印出来不过该方式只能适用于本地的iOS设备4. Windows平台的剪切板功能对于Windows应用Airtest虽然没有封装专门的剪切板功能但其实我们都知道Windows平台的复制粘贴就是键盘操作 “CtrlC”、“CtrlV”并且Airtest封装有keyevent接口支持我们执行键盘操作# -*- encodingutf8 -*-__author__ AirtestProjectfrom airtest.core.api import *auto_setup(__file__)text(11111111)# 模拟按键CtrlA实现全选文本keyevent(^a)# 模拟按键CtrlC实现复制文本keyevent(^c)# 回车换行keyevent({ENTER})# 模拟按键CtrlV实现复制文本keyevent(^v)其实pywin32的模块里面也有一些现成的关于Windows剪切板功能的接口感兴趣的同学可以自行网上查阅资料~感谢每一个认真阅读我文章的人礼尚往来总是要有的虽然不是什么很值钱的东西如果你用得到的话可以直接拿走这些资料对于【软件测试】的朋友来说应该是最全面最完整的备战仓库这个仓库也陪伴上万个测试工程师们走过最艰难的路程希望也能帮助到你!有需要的小伙伴可以点击下方小卡片领取