Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to Detect if Keyboard is shown in Xcode UI test

I am writing a UI text in swift under the new Xcode 7 UI test framework. the requirement is to test whether the system keyboard is shown in an app. can someone give me a clue on how to do that? thanks

like image 777
user2823793 Avatar asked Jan 08 '16 19:01

user2823793


People also ask

How do I test UI in Xcode?

When you're ready to test, go to a test class and place the cursor inside the test method to record the interaction. From the debug bar, click the Record UI Test button. Xcode will launch the app and run it. You can interact with the element on-screen and perform a sequence of interactions for any UI test.


1 Answers

Try this check:

let app = XCUIApplication()
XCTAssert(app.keyboards.count > 0, "The keyboard is not shown")

Or check for specific keyboard keys like:

let app = XCUIApplication()
XCTAssert(app.keyboards.buttons["Next:"].exists, "The keyboard has no Next button")

You can also control interactions on the keyboard:

let app = XCUIApplication()
app.keyboards.buttons["Next:"].tap()
like image 69
JoriDor Avatar answered Oct 13 '22 09:10

JoriDor