gpt4 book ai didi

testing - MonkeyTalk bool 逻辑

转载 作者:行者123 更新时间:2023-11-28 20:32:36 25 4
gpt4 key购买 nike

我正在尝试使用 JavaScript 编写脚本,以使用 MonkeyTalk 测试 iPhone 应用程序的用户界面。我如何使用逻辑和条件?现在我有一个障碍:

if (this.app.button("name").verify())
do this if button exists

问题是验证不返回 bool 值,如果按钮不存在,它只会在测试中抛出错误。有没有办法捕获错误并相应地运行脚本?

最佳答案

这似乎有效:

function verifiedViewOrNull (view)
{
var exists = false;
try
{
view.verify();
exists = true;
}
catch (e)
{

}

return exists ? view : null;
}

你可以这样调用它:

if (verifiedViewOrNull(this.app.view("name")) != null
{
// It exists
} else
//doesn't exist, not gonna throw exception

关于testing - MonkeyTalk bool 逻辑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12687749/

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