UIATarget.onAlert =功能onAlert(警报)问题 - 脚本似乎没有进入正确块 [英] UIATarget.onAlert = function onAlert(alert) Issue - Script doesn't seem to go into block correctly

查看:155
本文介绍了UIATarget.onAlert =功能onAlert(警报)问题 - 脚本似乎没有进入正确块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先感谢您百忙之中阅读,并希望提供一些煽动到我的问题的时间。此刻,我很只是试图自动执行登录和注销我公司正在使用仪器的应用程序。我遇到了一些小问题(你可以用密码输入看,我摇炭炭所代替使用,因为一个奇怪的打字问题的字符串)。

问题是,当我得到的警报弹出到屏幕上我想挖掘退出按钮。但是,似乎我从来没有输入应处理警报块。我可以推断出这一点,因为我在onAlert块散落在运行测试脚本时,它不会出现在我的日志日志消息中的。我知道,默认的处理程序只是驳斥任何警报,除非警报显式地处理除外。我也相信我,或者至少试图显式处理该警报,这样我可以点击右边的按钮。

我是什么做错了吗?我跟着苹果仪器引导,我相信我使用的是完全相同的语法,因为他们提供的一个例子。请找我下面code,我包括所有的,但感兴趣的块是在最后。

  VAR的目标= UIATarget.localTarget();
VAR密码=东西UIALogger.logStart(测试1);target.frontMostApp()的主窗口()scrollViews()[0] .webViews()[0] .textFields()[0] .tap()。;target.frontMostApp()键盘()typeString(东西)。;。UIATarget.localTarget()延迟(2);target.frontMostApp()的主窗口()scrollViews()[0] .webViews()[0] .secureTextFields()[0] .tap()。;。UIATarget.localTarget()延迟(2);对于(i = 0; I< password.length;我++){    变种strChar = password.charAt(ⅰ);
    target.frontMostApp()键盘()typeString(strChar);}。target.frontMostApp()的主窗口()scrollViews()[0] .webViews()[0] .buttons()[登录]点击();target.frontMostApp()的主窗口()tableViews()[0] .cells()后10次擦除数据] staticTexts()后10次擦除数据] scrollToVisible()。。target.frontMostApp()的主窗口()tableViews()[0] .groups()[注销默认]按钮()[注销默认]点击()。。
//警报检测。处理警报前pressions应移入UIATarget.onAlert函数定义。UIALogger.logMessage(只是警报之前);UIATarget.onAlert =功能onAlert(警报){    UIALogger.logMessage(在警报!);    UIATarget.delay(1);
    VAR标题= alert.name();
    UIALogger.logMessage(警报标题为+标题+'碰到的问题!);
    UIALogger.alert.logElementTree();
    alert.buttons()[注销]点击()。
}


解决方案

我有这个问题,并最终发现,自动化code的进展到UI先下一行(在这种情况下,警报视图)的显示在模拟器。
为了减轻这种我加入之前的onAlert块,以允许将被显示的警报视图的延迟。

  UIATarget.localTarget()。延迟(3)
UIATarget.onAlert =功能onAlert(警报){
    VAR标题= alert.name();
    UIALogger.logWarning(警报标题为+标题+'碰到的问题!);
    。target.frontMostApp()警报()cancelButton()点按()。
    返回false; //使用默认处理程序
}

Thanks firstly for taking the time to read and hopefully offer some incite into my issue. At the moment, I'm quite simply trying automate logging in and logging out of an app that my company is making using Instruments. I ran into a few small issues (as you can see with the password entry, I roll char by char instead of using string because of a strange typing issue).

The issue is that when I get the alert pop up to the screen I wish to tap the Logout button. However, it seems that I never enter the block that should be handling the alert. I can deduce this because of the logMessages that I littered in the onAlert block, which do not appear in my logs when the test script is run. I know that the default handler just dismisses any alerts unless the alert is explicitly handled otherwise. I also believe that I am or at least trying to explicitly handle that alert so that I can tap the right button.

What am I doing wrong? I followed the Apple Instruments guide and I believe I'm using the exact same syntax as they offer as an example. Please find my code below, I included all of it, but the block of interest is at the very end.

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();


}

解决方案

I had this issue and eventually found that the automation code was progressing onto the next line before the UI (in this case the alert view) was displayed in the simulator. To mitigate this I added a delay prior to the onAlert block to allow the alert view to be displayed.

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 =功能onAlert(警报)问题 - 脚本似乎没有进入正确块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆