简体   繁体   English

iOS UI自动化:处理两个alertView,其中一个触发另一个

[英]iOS UI automation: Handling two alertViews, where one triggers another

Here is what I am trying to do. 这是我想要做的。

1) I have one alertView that asks "where are you shopping?". 1)我有一个alertView,询问“您在哪里购物?”。 This alert has two buttons skip/cancel and continue. 此警报具有两个按钮,分别为“跳过/取消”和“继续”。 2) By clicking the skip button it pops up another alertView with title "Nearby listings:" and shows a tableView list of nearby stores from which user can select any store. 2)通过单击跳过按钮,它会弹出另一个标题为“附近列表:”的alertView,并显示附近商店的tableView列表,用户可以从中选择任何商店。 This one has only one Cancel button. 这只有一个“取消”按钮。 (cancel button dismisses the alert and takes back to the home page) (取消按钮可解除警报,并返回首页)

My problem is whenever I am trying to bypass the default handler like so 我的问题是每当我试图绕过默认处理程序时

    UIATarget.onAlert = function onAlert(alert) {
        var title = alert.name();
        UIALogger.logWarning("Alert with title ’" + title + "’ encountered!");
        if (title == "Where are you shopping?") {
            alert.buttons()["Skip"].tap();
            return true; // bypass default handler
        }
        return false; 
        }

This taps the skip button and the second alert pops up and the default button is tapped on the second alert even if I have not written any code for it to do so. 这将点击“跳过”按钮,第二个警报将弹出,并且即使我没有编写任何代码来在第二个警报上点击默认按钮。

I want to tap the skip button of the first alert and tap on one of the cells of the second alert. 我想点击第一个警报的跳过按钮,然后点击第二个警报的一个单元格。 So I tried the code below but it still dismisses the second alert without tapping the cell. 因此,我尝试了下面的代码,但它仍不关闭第二个警报而无需点击单元格。 Not sure how to do it. 不知道该怎么做。 I am a beginner so would really appreciate any help. 我是一个初学者,因此非常感谢您的帮助。

    var target = UIATarget.localTarget();
    var app = target.frontMostApp();
    var window = app.mainWindow();
    var testName = "Test 1";

    UIALogger.logStart(testName);


    var buttonScan = target.frontMostApp().windows()[0].buttons()["scan btn"];
    //UIATarget.localTarget().pushTimeout(1);

    target.delay(1);

    //app.logElementTree();

    if (buttonScan.isValid()) {
  buttonScan.tap();

  // first alert box "Where are you shopping"
  UIATarget.onAlert = function onAlert(alert) { // this is never called
      var title = alert.name();
      UIALogger.logWarning("Alert with title ’" + title + "’ encountered!");
      if (title == "Where are you shopping?") {
          alert.buttons()["Skip"].tap();
      return true; // bypass default handler
      }
  return false; 
}

// second alert box "Nearby listings:"
UIATarget.onAlert = function onAlert(alert) {
    var title = alert.name();
UIALogger.logMessage( "Dismiss the keyboard" + title );
    UIALogger.logWarning("Alert2 with title ’" + title + "’ encountered!");
    if (title == "Nearby listings:") {

        return true; // bypass default handler
    }
    return false; // use default handler that is dismissing the alert
   }


      UIALogger.logPass(testName);


   } else {

        UIALogger.logFail(testName);

    }

Try setting your onAlert handler before you take the instance of UITarget . 请尝试设置onAlert处理程序中采取的实例之前UITarget

For example: 例如:

// first alert box "Where are you shopping"
UIATarget.onAlert = function onAlert(alert) { // this is never called
      var title = alert.name();
      UIALogger.logWarning("Alert with title ’" + title + "’ encountered!");
      if (title == "Where are you shopping?") {
          alert.buttons()["Skip"].tap();
          return true; // bypass default handler
      }
  return false; 
}
    var target = UIATarget.localTarget();
    var app = target.frontMostApp();
    var window = app.mainWindow();
    var testName = "Test 1";

    UIALogger.logStart(testName);

    var buttonScan = target.frontMostApp().windows()[0].buttons()["scan btn"];
    //UIATarget.localTarget().pushTimeout(1);

    target.delay(1);
    //app.logElementTree();

    if (buttonScan.isValid()) {
  buttonScan.tap();

   //alert should happen here

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM