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