2

I want to write test cases where i can change the keyboard language for each test case in a text field.

I am using XCUItest framework to write these test cases. But i am not able to change the keyboard language while running the test case.

I have gone through this link

iPhone: Change Keyboard language programmatically

and tried the below solution. Here i am getting the return value but i am not able to use this to change the language in the text field while running the test.

class CustomTextField: UITextField {

    private func getKeyboardLanguage() -> String? {
        return "en" // here you can choose keyboard any way you need
    }

    override var textInputMode: UITextInputMode? {
        if let language = getKeyboardLanguage() {
            for tim in UITextInputMode.activeInputModes {
                if tim.primaryLanguage!.contains(language) {
                    return tim
                }
            }
        }
        return super.textInputMode
    }

}
Kaushik Makwana
  • 1,329
  • 2
  • 14
  • 24
Abinash Sahoo
  • 87
  • 1
  • 9

0 Answers0