Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/260.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Automation UIATarget.onAlert=函数onAlert(警报)问题-脚本不';I don’我好像进不去_Automation_Instruments_Ui Automation - Fatal编程技术网

Automation UIATarget.onAlert=函数onAlert(警报)问题-脚本不';I don’我好像进不去

Automation UIATarget.onAlert=函数onAlert(警报)问题-脚本不';I don’我好像进不去,automation,instruments,ui-automation,Automation,Instruments,Ui Automation,首先感谢您花时间阅读,希望能对我的问题提供一些启发。目前,我只是简单地尝试自动登录和注销我的公司使用仪器制作的应用程序。我遇到了一些小问题(正如您在密码输入中看到的,由于一个奇怪的键入问题,我逐字符滚动而不是使用字符串) 问题是,当我在屏幕上弹出警报时,我希望点击注销按钮。然而,我似乎从未进入应该处理警报的区块。我可以推断出这一点,因为我在onAlert块中乱丢了日志消息,当测试脚本运行时,这些消息不会出现在我的日志中。我知道默认处理程序只会解除任何警报,除非该警报以其他方式显式处理。我还相信,

首先感谢您花时间阅读,希望能对我的问题提供一些启发。目前,我只是简单地尝试自动登录和注销我的公司使用仪器制作的应用程序。我遇到了一些小问题(正如您在密码输入中看到的,由于一个奇怪的键入问题,我逐字符滚动而不是使用字符串)

问题是,当我在屏幕上弹出警报时,我希望点击注销按钮。然而,我似乎从未进入应该处理警报的区块。我可以推断出这一点,因为我在onAlert块中乱丢了日志消息,当测试脚本运行时,这些消息不会出现在我的日志中。我知道默认处理程序只会解除任何警报,除非该警报以其他方式显式处理。我还相信,我正在或至少试图明确地处理该警报,以便点击正确的按钮

我做错了什么?我遵循了Apple Instruments指南,我相信我使用的语法与它们作为示例提供的语法完全相同。请在下面找到我的代码,我包括了所有代码,但感兴趣的代码块在最后

var target = UIATarget.localTarget();
var password = "something"

UIALogger.logStart("Test1");

target.frontMostApp().mainWindow().scrollViews()[0].webViews()[0].textFields()[0].tap();

target.frontMostApp().keyboard().typeString("something");

UIATarget.localTarget().delay(2);

target.frontMostApp().mainWindow().scrollViews()[0].webViews()[0].secureTextFields()[0].tap();

UIATarget.localTarget().delay(2);

for (i = 0; i < password.length; i++){

    var strChar = password.charAt(i);
    target.frontMostApp().keyboard().typeString(strChar);

}

target.frontMostApp().mainWindow().scrollViews()[0].webViews()[0].buttons()["Log in"].tap();

target.frontMostApp().mainWindow().tableViews()[0].cells()["Wipe data after 10 attempts"].staticTexts()["Wipe data after 10 attempts"].scrollToVisible();

target.frontMostApp().mainWindow().tableViews()[0].groups()["logout default"].buttons()["logout default"].tap();
// Alert detected. Expressions for handling alerts should be moved into the               UIATarget.onAlert function definition.

UIALogger.logMessage("Just before alert");

UIATarget.onAlert = function onAlert(alert){

    UIALogger.logMessage("In Alert!");

    UIATarget.delay(1);
    var title = alert.name();
    UIALogger.logMessage("Alert with title '" + title + "' encountered!");


    UIALogger.alert.logElementTree();
    alert.buttons()["Logout"].tap();


}
var target=uiatatarget.localTarget();
var password=“某物”
UIALogger.logStart(“Test1”);
target.frontMostApp().mainWindow().scrollViews()[0]。webViews()[0]。textFields()[0]。点击();
target.frontMostApp().keyboard().typeString(“某物”);
UIATarget.localTarget().delay(2);
target.frontMostApp().mainWindow().scrollViews()[0]。webViews()[0]。secureTextFields()[0]。点击();
UIATarget.localTarget().delay(2);
对于(i=0;i
我遇到了这个问题,最终发现在模拟器中显示UI(在本例中为警报视图)之前,自动化代码正在进入下一行。 为了缓解这种情况,我在onAlert块之前添加了一个延迟,以允许显示警报视图

UIATarget.localTarget().delay(3)
UIATarget.onAlert = function onAlert(alert){
    var title = alert.name();
    UIALogger.logWarning("Alert with title ’" + title + "’ encountered!");
    target.frontMostApp().alert().cancelButton().tap();
    return false; // use default handler
}
你有一些打字错误

首先,您需要在执行测试代码之前定义警报处理函数。将其移动到测试脚本的顶部

其次,您对函数的定义和赋值有点不正确。与此相反:

UIATarget.onAlert = function onAlert(alert){
你应该有这个:

UIATarget.onAlert = function (alert){

最后,此警报处理程序仅适用于iOS级别的警报,如权限弹出窗口。我在这里猜测,但是
alert.buttons()[“Logout”].tap()看起来像是您自己的应用程序正在创建的内容。对此,您不需要警报处理程序;只需像任何其他UI元素一样在元素树中访问它,然后点击它

还要注意的是,我一直试图坚持“如果它不起作用,请先尝试一个.delay(1),可能是仪器对于UI来说移动太快了”的方法。这里有一些多余的延迟。我能够按照上的建议自动发出警报,这对你有用吗?也有这个问题。到目前为止,尚未触发我添加的警报处理程序。在应用程序激活之前,不会显示任何警报-警报测试通过之前的所有测试。对此问题的任何回答都将不胜感激!为什么不在函数内部使用alert?