How to check label name in table view using iOS tools?

I use the Xcode Tools tool to create automation for an iOS application, and I need to make sure that the label for the entry I created in my application is correct.

The code below for some reason does not lead to a serious pass or crash. Rather, when it starts, I get a "Problem" warning in the log and test outputs without explicit closure.

I want to modify my tests to verify that the name of the label, which I know, is created because I see it with the AccessibilityViewer after my automation.

If the label is correct, then I want to register the test as a pass.

I used UIATarget.localTarget().logElementTree() to map my item tree, and I used the AccessibilityInspector to check the name of my label after my record was created. The problem is that I just cannot get the syntax for validation.

My Accessibility Inspector verified that the label name: MyDogs! and it has the attributes of a Static text and gives the Frame {{114, 0}, {166,480}}

Looking at the element tree that I would like to insert here, it looks like the label will be found along this path:

 \Target -+ --\Application ---+ ----\Window -----+ ------\TableView -------+ --------\TableCell: name:MyDogs! rect:{0, 40},{480,166}} ---------|UIAStaticText: name:MyDogs! value:MyDogs! rect:{{0, 40},{480, 166}} ---------|UIAButton: name:story list share rect:{{439, 41},{33, 28}} 

Can someone tell me how to check this shortcut?

My current code looks like this (but doesn't check the label - because I don't know how to do this):

 var testName = "LoginCreateEntry"; //Start test logging UIALogger.logStart(testName); //This is supposed to target the entry that my automation has created. //The flow goes, run the automation that creates the entry, then verify that the entry //got created as expected and is visible to the user in the iPhone interface. var myEntry = target.frontMostApp().mainWindow().scrollViews().staticTexts()["My Dogs!"].value(); var entryName = "My Dogs!"; //Do a bunch of UI automation here to create my entry, which results in the entry //appearing in the mainWindow with the label: My Dogs! //If myEntry evaluates to true, then call this test a pass. if (myEntry === entryName) { UIALogger.logMessage("My entry was created!"); //Mark the test as a PASS UIALogger.logPass(testName); } else { UIALogger.logMessage("My entry was not created!"); //Mark the test as a FAIL UIALogger.logFail(testName); } //End test 

Any feedback or help would be most appreciated.

--------------------------------- UPDATE ------------- --- ----------------------
Thank you all for your help! I really got the meaning of the name and will show my solution below. But I CAN'T use the pass / fail logging functionality to work correctly no matter what I do - and the problem was met by other people . I keep exciting

Issue: Script ended without explicting closing this test

at the end of my tests. I make sure this is a mistake with the Tools.

Here is my updated test:

 var target = UIATarget.localTarget(); var app = UIATarget.localTarget().frontMostApp(); var testName = "LoginCreateEntry"; //Start test logging UIALogger.logStart( testName ); //Do lots of gui automation stuff here to create the entry which will appear in my app interface. //I want to verify that the title I gave the entry matches what appears in the app interface var window = app.mainWindow(); var tableView = window.tableViews()[0]; var tableGroup = tableView.groups()[0]; var entryName = "My Dogs!"; var myEntry = tableView.cells()[0].name(); //<-- This is what I needed!!! UIALogger.logMessage("My Story Title: " + myEntry); //Print out entry name in log if (myEntry === entryName) { UIALogger.logMessage("My entry was created!"); //Mark the test as a PASS UIALogger.logPass (testName); } else { UIALogger.logMessage("My entry was not created!"); //Mark the test as a FAIL UIALogger.loFails (testName); } //End test 
+6
source share
2 answers

I recommend using tuneup_js . Using this library you can easily create test cases and check if a label exists and is equal to My Dogs

You can use it like this:

 test("LoginCreateEntry", function(target,app){ //Create Entry //.... var myEntry = target.frontMostApp().mainWindow().scrollViews().staticTexts()["My Dogs!"].name(); //Check is Label is equal to My Dogs //Test "LoginCreateEntry" will fail if myEntry is not equal to My Dogs assertEquals(myEntry, "My Dogs"); }); 

PS you must use .name() , not .value() to get the name of the label

+5
source

At least since the summer of 2012 and iOS 5, I found that I could not access the UIA element using accessibilityLabel unless the accessibilityIdentifier parameter was also set.

And, unfortunately, from now on (and with Xcode 4.2), the accessibilityIdentifier can only be set in code, not in Interface Builder. Not sure if the situation has improved since then. See this SO question for more information:

Can I set the availability identifier in the interface builder? Xcode4.2

But, as I said before, you can access UIA using an automation tool to work if you have access to the application source. (Or it may affect someone with access, I suppose!)

I have a github project that shows how to set the access identifier in UILabel (in the application source), and then write a UIA test that successfully accesses the element, as your code is trying to try.

First, this is my test file, where I try to find a UILabel displaying the string "!":

https://github.com/billagee/UnicodeTapper-iphone4.2/blob/master/UnicodeTapperTests/tests.js

  // for iOS 5 - note 4 must be handled differently var charDisplayed = window.staticTexts()["bigCharLabel"].value(); if (charDisplayed == "!") { UIALogger.logPass("Exclamation point displayed at startup"); } else { UIALogger.logFail("Incorrect character displayed: " + charDisplayed); } 

Then, in the target application source, setting the UILabel availability attributes looks like this:

 // If device supports it, set accessibility identifiers for the UILabels // in order to find them in UIAutomation easily. Note that the // accessibilityIdentifier can't be set in IB yet, as of Xcode 4.3.3; // also, it only supported in iOS 5 and up. topBarLabel.isAccessibilityElement = YES; bigCharLabel.isAccessibilityElement = YES; if ([topBarLabel respondsToSelector:@selector(accessibilityIdentifier)]) { topBarLabel.accessibilityIdentifier = @"topBarLabel"; bigCharLabel.accessibilityIdentifier = @"bigCharLabel"; } else { topBarLabel.accessibilityLabel = @"topBarLabel"; bigCharLabel.accessibilityLabel = @"bigCharLabel"; } 

The full source is here:

https://github.com/billagee/UnicodeTapper-iphone4.2/blob/master/UnicodeTapper/UnicodeTapperViewController.m

+5
source

All Articles