Is it possible to “toggle software keyboard” via the code in UI test?

前端 未结 7 632
时光取名叫无心
时光取名叫无心 2020-12-24 03:25

I have UI tests which testing login functionality (and uses it to test other stuff), but sometimes when focus is changed from one field to another - the keyboard hides, and

7条回答
  •  眼角桃花
    2020-12-24 03:54

    Tested with Xcode 10.1 I tried different approaches but none of them solve how to get the simulator UDID

    #Find the UDID of the booted simulator
    #And use PlistBuddy to change the flag to true or false
    #Set the variable useHardwareKeyboard with the desired result
    #Relaunch the simulator
    useHardwareKeyboard=false
    export UDID=$(xcrun simctl list devices | grep "(Booted)" | grep -E -o -i "([0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12})")
    /usr/libexec/PlistBuddy -c "Set :DevicePreferences:$UDID:ConnectHardwareKeyboard ${useHardwareKeyboard}" ~/Library/Preferences/com.apple.iphonesimulator.plist
    xcrun simctl shutdown $UDID
    xcrun simctl boot $UDID
    

    You can also verify these changes.

    Find your simulator UDID: (More here: https://nshipster.com/simctl/)

    xcrun simctl list devices | grep "(Booted)" | grep -E -o -i "([0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12})"
    

    Run one of these commands and find your changes based on the UDID from above:

    defaults read com.apple.iphonesimulator
    #OR
    open ~/Library/Preferences/com.apple.iphonesimulator.plist
    

提交回复
热议问题