简体   繁体   中英

iPhone App UI Automation using the UIAutomation framework?

Hi people I have a serious problem at hand, I have taken a navigation bar controller in my application and inside that bar I have a right button the code for which is written as follows -:

    UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] init];
    rightButton.action = @selector(loadLeaseView);
    rightButton.target = self;
    rightButton.title = @"Next";
    rightButton.style = UIButtonTypeDetailDisclosure;
    rightButton.isAccessibilityElement = YES;
    rightButton.accessibilityLabel = @"Next";

    self.navigationItem.leftBarButtonItem = nil;
    self.navigationItem.hidesBackButton = YES;
    self.navigationItem.rightBarButtonItem  = rightButton;
    [rightButton release];  

I have set the accessibility label for this button and isAccessible flags as well, and I have written a java script to test this which basically opens up the app and taps this button so that we can move to next page in the app, but the problem is that the script is not able to tap the button, the java script I wrote is as follows -:

UIALogger.logStart("Starting Test");
var target = UIATarget.localTarget().frontMostApp().mainWindow();
var navBar = target.navigationBar().navigationItem();

var button = navBar.rightButton();
button.tap();

the above script doesn't seem to work can anyone please help me out, everytime I try to run the script using instruments it says "Fail" .

I don't believe that navigationItem is a function in UIAutomation.

I think what you're looking for is something more like …

var target = UIATarget.localTarget();
var app = target.app = target.frontMostApp();
var navBar = app.mainWindow().navigationBar();
var button = navBar.rightButton(); 
button.tap();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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