I've got a test like below:
let navnTextField = app.textFields["First Name"]
let name = "Henrik"
navnTextField.tap()
navnTextField.typeText("Henrik")
XCTAssertEqual(navnTextField.value as? String, name)
Problem is that by default my iPhone Simulator
has got Polish keyboard because of the system settings and "Henrik" is automatically changed into "ha" by autocorrect.
Simple solution is to remove Polish keyboard from the iOS Settings
. This solution however is not solving the problem because iPhone Simulator
can be reset and then test will fail again.
Is there any way to setup autocorrect before test case or other way to input text to text field.
UI testing allows you to automate this procedure, so every time you update your code, Xcode will automatically test whether your app works correctly without you having to manually do it. When is UI testing used?
The easiest option to get XCUITests done for your app is to use Xcode Test Recorder. With this, native UI components can be identified and specific interaction on those is done automatically based on the object’s characteristics (class, ID, attributes etc.).
Frankly, Xcode Storyboard has numerous benefits for every app developer, but those also work as a great illustration for those who implement test automation for the app. Furthermore, if you select to start using Xcode, it’s always recommended to get a deep understanding of which pros and cons are provided with it for testing.
In this case, you might want to look at UI testing for Swift. UI testing allows you to automate this procedure, so every time you update your code, Xcode will automatically test whether your app works correctly without you having to manually do it. When is UI testing used?
Here's a small extension on XCUIElement to accomplish this
extension XCUIElement {
// The following is a workaround for inputting text in the
//simulator when the keyboard is hidden
func setText(text: String, application: XCUIApplication) {
UIPasteboard.generalPasteboard().string = text
doubleTap()
application.menuItems["Paste"].tap()
}
}
It can be used like this
let app = XCUIApplication()
let enterNameTextField = app.otherElements.textFields["Enter Name"]
enterNameTextField.tap()
enterNameTextField.setText("John Doe", app)
There is a workaround to use UIPasteboard to provide input text:
let navnTextField = app.textFields["First name"]
navnTextField.tap()
UIPasteboard.generalPasteboard().string = "Henrik"
navnTextField.doubleTap()
app.menuItems.elementBoundByIndex(0).tap()
XCTAssertEqual(navnTextField.value as? String, name)
You can check link with description as a workaround for secure input in GM
Edit
For better readability instead app.menuItems.elementBoundByIndex(0).tap()
you can do app.menuItems["Paste"].tap()
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With