Support for optionally setting a window foreground when connecting the window #1068
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
该 PR 目的:在 Windows 环境下,初始化
airtest.core.win.Windows
对象时,允许开发者选择性跳过connect()
方法中的set_foreground()
功能。特殊场景
我们在 Windows 环境下调用
airtest.core.api.connect_device(uri)
方法发现某个窗口(实际样式是菜单)闪了一下就消失了。在
airtest.core.win.Windows
源码中,发现对象在初始化时会调用一次set_foreground()
方法。(似乎该窗口接收到任意非鼠标点击指令都会触发关闭事件?)
得益于 Python 的特性和 Airtest 的
CUSTOM_DEVICES
的设计,我们临时通过以下方式禁用了该功能:虽然这种方式可以解决上述的问题,但是实现不够优雅,于是希望能将其作为一个 featrue 实现。
实现方案
为
airtest.core.win.Windows
的connect
方法新增一个foreground
参数,默认为True
,与原行为保持一致。使用方法
最后,非常感谢 Airtest 的各位 Maintainers 和 Contributors,Airtest 不仅在自动化测试方面很优秀,在其他场景也非常好用,例如:我们使用 Airtest 实现了机器人流程自动化。
希望能和大家共同完善项目。