質問

I want to test my iOS app. It contains dynamically generated UI elemnts. I create all the UI elements programmatically without using the interface builder. To test I need to access them via Automation tool.

I can't at least print them with logElementTree() and I don't know how to access the dynamically generated elements.

If there is any way I can access dynamically generated elements using a script?

This is my code that tries to log the UI elements.

var target = UIATarget.localTarget();

var app = target.frontMostApp();

var window = app.mainWindow();

target.logElementTree();

I further tried using app.mainWindow().logElementTree(); it is also not working.

Any help will be highly appreciated.

役に立ちましたか?

解決

Here is the answer. I did it myself. This is the process.

We can use the method delay(int) to pause the test script because of that the script stays alive. Otherwise the script will end before the dynamic UI is drawn.

Now the logElementTree() methods works and we can access the UI elements.

This is how we access the dynamically generated UI elements. In my app first there is connect button and when it is clicked a UI with a text box and a log in button is dynamically drawn.

This is the script to access UI elements.

var target = UIATarget.localTarget(); var app = target.frontMostApp(); app.logElementTree();

//-- select the elements UIALogger.logMessage( "Click the connect button" ); var window = UIATarget.localTarget().frontMostApp().mainWindow().buttons() [0].tap();

UIALogger.logMessage( "Wait for the next UI" ); target.delay( 2 ); target.frontMostApp().logElementTree(); UIALogger.logMessage( "Enter user name" );

UIALogger.logMessage( "Wait for the next UI" ); target.delay( 3 ); target.frontMostApp().logElementTree(); target.frontMostApp().mainWindow().scrollViews()[0].textFields()[0].setValue("admin"); UIALogger.logMessage( "Dismiss the keyboard" ); var name = UIATarget.localTarget().frontMostApp().keyboard().buttons()["done"].tap();

Hope this helps for someone

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top