Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode ui test: staticTexts start with

I want to check if an element on my ui which start with a prefix is present. How is it possible to implement it in Xcode 7 UI Tests?

app.tables["AAA"].staticTexts["Fax: 0049XXXXXXXX"].exists

I have three element into a tableview cell and only one (the third or last one) starts with the prefix Fax: 0049. How can i check the present of this element?

I tried with

app.tables["AAA"].cells.staticTexts.elementBoundByIndex(2).exists

But nothing, some ideas? Cheers

like image 351
emoleumassi Avatar asked Feb 19 '16 15:02

emoleumassi


People also ask

How do I test UI in Xcode?

How to Run XCUI Tests on XCode. To run the XCUITests on XCode, you can click the highlighted icon below to see your newly created UI Test targets. You can hover on the “testExample()” test case and click the “Play” icon to run that specific test to see if everything was set up properly.

Which test framework does XCUITest use?

What is XCUITest framework? Developed by Apple in 2015, XCUITest is an automated UI test framework for performing iOS automation testing. It utilizes XCTest - an integrated test framework for Xcode by Apple.


1 Answers

You can use a BEGINSWITH predicate to check if an element starts with a prefix.

let app = XCUIApplication()
let faxPredicate = NSPredicate(format: "label BEGINSWITH 'Fax: '")
let faxLabel = app.staticTexts.element(matching: faxPredicate)
XCTAssert(faxLabel.exists)

Here's a working example for selecting elements with a different BEGINSWITH predicate, a picker with multiple wheels.

like image 86
Joe Masilotti Avatar answered Oct 03 '22 21:10

Joe Masilotti