Search code examples
iphonexcodeipadinstrumentsios-ui-automation

Why is the UI Automation instrument unable to determine if a button is enabled here?


I am working with Xcode 4.0.1 and Instruments trying to implement some UIAutomation tests.

As of right now, I am trying to determine if a button on my MainWindow (mainWindow = app.mainWindow();) is enabled.

This is an app running on an iPad II, and right now I am not feeling the love.

Can anyone assist?

Here is the syntax I am trying to use; does this seem correct?

var title="Checking that Sign-In button is disabled";  
try {  
    if (mainWindow.buttons()["Sign In"].isEnabled())  
    UIALogger.logPass("Try: " + title + " has passed.");  
}  
catch (error) {  
    UIALogger.logError(error);  
    target.logElementTree();  
    UIALogger.logFail("Try: " + title + " has failed.");  
}

Solution

  • Hey.
    I agree with Sosullivan. There may be problem with button access in general. Additionally, if mainWindow.buttons() doesn't contain one with name "Sign In" isn't whole code executed without any output? I would get sure, that button is in object tree, verify its position (so I can access it) then call .isEnabled() to see if it is enabled for user.
    maybe try this code for start:

    var title="Checking that Sign-In button is disabled";  
    try {
      if (mainWindow.buttons()["Sign In"] && mainWindow.buttons()["Sign In"].isEnabled())  {
          UIALogger.logPass("Try: " + title + " has passed.");  
      } else {
          throw new Error("no SignIn button or button not enabled");
        }
    } catch (error) {  
      UIALogger.logError(error);  
      target.logElementTree();  
      UIALogger.logFail("Try: " + title + " has failed.");  
    }
    

    First check in if will check if button was found in tree structure (under main app). If it doesn't solve the issue check where in your tree structure the button is located, then put proper location verification as precondition to checking if it is enabled.