appium / appium-mac2-driver

Next-gen Appium macOS driver, backed by Apple XCTest
Apache License 2.0
116 stars 24 forks source link

Current keyboard layout problems #135

Open matyukhin-maxim opened 2 years ago

matyukhin-maxim commented 2 years ago

Hello. Does anybody can say how correct way to use elementSendKeys or script macos: keys with multi-language input?

I will explain: If current keyboard layout is en and try to send input in en locale then all correct work (control receive desired text)

But if the layout differs from the input text, then all sorts of errors occur ...

    // ... init driver
    // current keyboard layout is RU
    const { elementId } = await driver.$('~WEB_BROWSER_ADDRESS_AND_SEARCH_FIELD');
    await driver.elementSendKeys(elementId, 'hello');

in result test ends with tear down

    2022-04-27T14:33:28.434Z INFO webdriver: COMMAND elementSendKeys("2F841458-A696-42FD-97D9-6EC21FFD0273", <object>)
    2022-04-27T14:33:28.435Z INFO webdriver: [POST] http://127.0.0.1:4567/session/f42812cd-1bdb-437c-bc63-399464bfa4d3/element/2F841458-A696-42FD-97D9-6EC21FFD0273/value
    2022-04-27T14:33:28.435Z INFO webdriver: DATA { value: [ 'h', 'e', 'l', 'l', 'o' ] }
    info HTTP --> POST /session/f42812cd-1bdb-437c-bc63-399464bfa4d3/element/2F841458-A696-42FD-97D9-6EC21FFD0273/value
    info HTTP {"value":["h","e","l","l","o"]}
    info Mac2Driver@137d (f42812cd) Driver proxy active, passing request on via HTTP proxy
    dbug WD Proxy Matched '/session/f42812cd-1bdb-437c-bc63-399464bfa4d3/element/2F841458-A696-42FD-97D9-6EC21FFD0273/value' to command name 'setValue'
    dbug Protocol Converter Added 'text' property "hello" to 'setValue' request body
    dbug WD Proxy Proxying [POST /session/f42812cd-1bdb-437c-bc63-399464bfa4d3/element/2F841458-A696-42FD-97D9-6EC21FFD0273/value] to [POST http://127.0.0.1:10100/session/134E8923-42D1-4A5D-8F37-25F9A45A93C0/element/2F841458-A696-42FD-97D9-6EC21FFD0273/value] with body: {"value":["h","e","l","l","o"],"text":"hello"}
    dbug WebDriverAgentMac [xcodebuild] t =     5.99s Find the "WEB_BROWSER_ADDRESS_AND_SEARCH_FIELD" TextField
    dbug WebDriverAgentMac [xcodebuild] t =     6.70s Find the "WEB_BROWSER_ADDRESS_AND_SEARCH_FIELD" TextField
    dbug WebDriverAgentMac [xcodebuild] t =     7.13s Find the "WEB_BROWSER_ADDRESS_AND_SEARCH_FIELD" TextField
    dbug WebDriverAgentMac [xcodebuild] t =     7.67s Find the "WEB_BROWSER_ADDRESS_AND_SEARCH_FIELD" TextField
    dbug WebDriverAgentMac [xcodebuild] t =     8.07s Type 'hello' into "WEB_BROWSER_ADDRESS_AND_SEARCH_FIELD" TextField
    dbug WebDriverAgentMac [xcodebuild] t =     8.07s     Wait for com.apple.Safari to idle
    dbug WebDriverAgentMac [xcodebuild] t =     8.07s     Find the "WEB_BROWSER_ADDRESS_AND_SEARCH_FIELD" TextField
    dbug WebDriverAgentMac [xcodebuild] t =     8.61s     Synthesize event
    dbug WebDriverAgentMac [xcodebuild] t =    39.72s         Failed: Timed out while synthesizing event.
    dbug WebDriverAgentMac [xcodebuild] t =    39.72s         Requesting snapshot of accessibility hierarchy for app with pid 63748
    dbug WebDriverAgentMac [xcodebuild] WebDriverAgentRunner.m:54: Expected failure in -[UITestingUITests testRunner]: Failed to synthesize event: Timed out while synthesizing event.Reason: (Ignore all failures)
    dbug WD Proxy Got response with status 200: {"value":null,"sessionId":"134E8923-42D1-4A5D-8F37-25F9A45A93C0"}
    info WD Proxy Replacing sessionId 134E8923-42D1-4A5D-8F37-25F9A45A93C0 with f42812cd-1bdb-437c-bc63-399464bfa4d3
    info HTTP <-- POST /session/f42812cd-1bdb-437c-bc63-399464bfa4d3/element/2F841458-A696-42FD-97D9-6EC21FFD0273/value 200 39530 ms - 65
    info HTTP
    dbug WebDriverAgentMac [xcodebuild] t =    45.51s Tear Down
    dbug WebDriverAgentMac [xcodebuild] Test Case '-[UITestingUITests testRunner]' passed (45.717 seconds).
    dbug WebDriverAgentMac [xcodebuild] Test Suite 'UITestingUITests' passed at 2022-04-27 17:34:08.174.
    dbug WebDriverAgentMac   Executed 1 test, with 0 failures (0 unexpected) in 45.717 (45.718) seconds
    dbug WebDriverAgentMac [xcodebuild] Test Suite 'WebDriverAgentRunner.xctest' passed at 2022-04-27 17:34:08.174.
    dbug WebDriverAgentMac   Executed 1 test, with 0 failures (0 unexpected) in 45.717 (45.719) seconds
    dbug WebDriverAgentMac Test Suite 'All tests' passed at 2022-04-27 17:34:08.174.
    dbug WebDriverAgentMac   Executed 1 test, with 0 failures (0 unexpected) in 45.717 (45.720) seconds
    dbug WebDriverAgentMac [xcodebuild] 2022-04-27 17:34:08.438 xcodebuild[63740:2196830] [MT] IDETestOperationsObserverDebug: 46.344 elapsed -- Testing started completed.
    dbug WebDriverAgentMac 2022-04-27 17:34:08.438 xcodebuild[63740:2196830] [MT] IDETestOperationsObserverDebug: 0.000 sec, +0.000 sec -- start
    dbug WebDriverAgentMac [xcodebuild] 2022-04-27 17:34:08.438 xcodebuild[63740:2196830] [MT] IDETestOperationsObserverDebug: 46.344 sec, +46.344 sec -- end
    dbug WebDriverAgentMac [xcodebuild] Test session results, code coverage, and logs:
    dbug WebDriverAgentMac  /Users/mmp/Library/Developer/Xcode/DerivedData/WebDriverAgentMac-dkpyypthdmwmhvdyeohwiudgmlku/Logs/Test/Test-WebDriverAgentRunner-2022.04.27_17-33-21-+0300.xcresult
    dbug WebDriverAgentMac
    dbug WebDriverAgentMac ** TEST EXECUTE SUCCEEDED **
    dbug WebDriverAgentMac [xcodebuild] Testing started
    info WebDriverAgentMac Mac2Driver host process has exited with code 0, signal null

Likewise the reverse

    // ... init driver
    // current keyboard layout is EN
    const { elementId } = await driver.$('~WEB_BROWSER_ADDRESS_AND_SEARCH_FIELD');
    await driver.elementSendKeys(elementId, 'привет');

lead to

    2022-04-27T14:41:32.413Z INFO webdriver: COMMAND elementSendKeys("2C3D3FD7-4058-4060-926D-23E1AAEA62AD", <object>)
    2022-04-27T14:41:32.413Z INFO webdriver: [POST] http://127.0.0.1:4567/session/a51169d3-bc29-48a2-870b-601806cb3edd/element/2C3D3FD7-4058-4060-926D-23E1AAEA62AD/value
    2022-04-27T14:41:32.413Z INFO webdriver: DATA { value: [ 'п', 'р', 'и', 'в', 'е', 'т' ] }
    info HTTP --> POST /session/a51169d3-bc29-48a2-870b-601806cb3edd/element/2C3D3FD7-4058-4060-926D-23E1AAEA62AD/value
    info HTTP {"value":["п","р","и","в","е","т"]}
    info Mac2Driver@0606 (a51169d3) Driver proxy active, passing request on via HTTP proxy
    dbug WD Proxy Matched '/session/a51169d3-bc29-48a2-870b-601806cb3edd/element/2C3D3FD7-4058-4060-926D-23E1AAEA62AD/value' to command name 'setValue'
    dbug Protocol Converter Added 'text' property "привет" to 'setValue' request body
    dbug WD Proxy Proxying [POST /session/a51169d3-bc29-48a2-870b-601806cb3edd/element/2C3D3FD7-4058-4060-926D-23E1AAEA62AD/value] to [POST http://127.0.0.1:10100/session/F325F31C-8B97-4ADF-AF32-6E6A09F5E471/element/2C3D3FD7-4058-4060-926D-23E1AAEA62AD/value] with body: {"value":["п","р","и","в","е","т"],"text":"привет"}
    dbug WebDriverAgentMac [xcodebuild] t =     8.32s Find the "WEB_BROWSER_ADDRESS_AND_SEARCH_FIELD" TextField
    dbug WebDriverAgentMac [xcodebuild] t =     8.77s Find the "WEB_BROWSER_ADDRESS_AND_SEARCH_FIELD" TextField
    dbug WebDriverAgentMac [xcodebuild] t =     9.33s Find the "WEB_BROWSER_ADDRESS_AND_SEARCH_FIELD" TextField
    dbug WebDriverAgentMac [xcodebuild] t =     9.78s Find the "WEB_BROWSER_ADDRESS_AND_SEARCH_FIELD" TextField
    dbug WebDriverAgentMac [xcodebuild] t =    10.34s Type 'привет' into "WEB_BROWSER_ADDRESS_AND_SEARCH_FIELD" TextField
    dbug WebDriverAgentMac [xcodebuild] t =    10.34s     Wait for com.apple.Safari to idle
    dbug WebDriverAgentMac [xcodebuild] t =    10.35s     Find the "WEB_BROWSER_ADDRESS_AND_SEARCH_FIELD" TextField
    dbug WebDriverAgentMac [xcodebuild] t =    10.77s     Synthesize event
    dbug WebDriverAgentMac [xcodebuild] t =    10.78s     Wait for com.apple.Safari to idle
    dbug WD Proxy Got response with status 200: {"value":null,"sessionId":"F325F31C-8B97-4ADF-AF32-6E6A09F5E471"}
    info WD Proxy Replacing sessionId F325F31C-8B97-4ADF-AF32-6E6A09F5E471 with a51169d3-bc29-48a2-870b-601806cb3edd
    info HTTP <-- POST /session/a51169d3-bc29-48a2-870b-601806cb3edd/element/2C3D3FD7-4058-4060-926D-23E1AAEA62AD/value 200 2475 ms - 65
    info HTTP

Despite the fact that the test does not complete and there is no error, the target element does not receive the desired text

I believe that this behavior is due to different character codes, but I still don’t understand how to fix it without switching the system language.