gpt4 book ai didi

ios - 如何检测我的功能测试在哪个 iOS 设备上运行?

转载 作者:行者123 更新时间:2023-11-28 23:09:10 27 4
gpt4 key购买 nike

我目前有许多使用 Apple 的 UIAutomation API 以 javascript 编写的功能测试。这些测试是为 iPhone 编写的,但该应用程序也支持 iPad。

要扩展我的测试以在 iPad 上运行,我需要对代码进行一些调整,但首先我需要找出运行测试的设备。

如何检测正在运行测试的设备/模拟器?当我从自动化工具运行 javascript 测试时。

最佳答案

UIATarget.localTarget().model() 保存有关测试在哪个设备上运行的信息。

我发现了 Alex Vollmer's tuneup_js library .它至少在某种程度上允许设备独立代码。

例如)

test("my test", function(target, app) {
assertWindow({
"navigationBar~iphone": {
leftButton: { name: "Back" },
rightButton: { name: "Done" }
},
"navigationBar~ipad": {
leftButton: null,
rightButton: { name: "Cancel" }
},
});
});

编辑

在tuneup_js中发现如下:

   /**
* A convenience method for detecting that you're running on an iPad
*/
isDeviceiPad: function() {
return this.model().match(/^iPad/) !== null;
},

/**
* A convenience method for detecting that you're running on an
* iPhone or iPod touch
*/
isDeviceiPhone: function() {
return this.model().match(/^iPhone/) !== null;
}

有了这些,我将能够编写特定于设备的代码。

关于ios - 如何检测我的功能测试在哪个 iOS 设备上运行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8699969/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com