Search code examples
iosui-automationios-ui-automation

UIAutomation test fails after pushing new view controller (tuneup.js)


I just started trying UIAutomation with tuneup.js. I can test my first window just fine, but the second window fails -- my app is still looking at the first window and sees e.g. the "Sign in with Facebook" button. I've tried adding delays but this didn't seem to help. Any idea on what I'm doing wrong?

#import "tuneup.js"

target = UIATarget.localTarget();
application = target.frontMostApp();

test("Test first-run view controller", function(app, target) {
 assertWindow({
              buttons : [
                         { name : "Sign in with Facebook"},
                         { name : "Create account"},
                         { name : "Login"},
                         { name : "Try"}
              ], 
              onPass: function(window) {

                var createAccountButton = window.buttons()["Create account"]
                createAccountButton.tap();
              }

 });

});

test("Test Sign-in screen", function(app, target) {
 assertWindow({
    buttons : [
              { name : "Sign up"}
        ]
 });

 });

Solution

  • Ah, I found what was going on. I didn't realize it, but my sign-in screen has a scroll view containing its buttons. This code worked fine:

    test("Test the account creation", function(app, target) {
     assertWindow({
                  scrollViews: [
                        { buttons : [
                                {name :"Sign up"},
                                {name : "Terms and Conditions"}
                                ]
    
                  }
                                ],
                  onPass: function(window) {
                    var signUpButton = window.scrollViews()[0].buttons()["Sign up"];
                    signUpButton.tap()
                  }
     });
    
     });