appium/WebDriverAgent

Unable to use PrebuiltWDA

grishukov opened this issue · 5 comments

I tried using a pre-built WDA to reduce the session startup time and it works not as I expect.

On m1 mac I build wda.app (5.6) from source for simulator.
xcodebuild -scheme 'WebDriverAgentRunner' -sdk iphonesimulator -configuration Debug build BUILD_DIR=/path/to/
Then I provide it to "options" like this for test on sim

capabilities.AddAdditionalAppiumOption("appium:useNewWDA", "true");
capabilities.AddAdditionalAppiumOption("appium:usePrebuiltWDA", "true");
capabilities.AddAdditionalAppiumOption("appium:prebuiltWDAPath", "/Users/timur/Source/wda/builds/Debug-iphonesimulator/WebDriverAgentRunner-Runner.app");

appium server 2.0.1. \ client .net 5.0.0. beta4

When test runs without this options WDA builds ok.

with prebuild wda

appium logs have this

Details

#```

[AppiumDriver@5898] Applying relaxed security to 'XCUITestDriver' as per server command line argument. All insecure features will be enabled unless explicitly disabled by --deny-insecure
[debug] [XCUITestDriver@41cc] Creating session with W3C capabilities: {
[debug] [XCUITestDriver@41cc] "alwaysMatch": {
[debug] [XCUITestDriver@41cc] "platformName": "iOS",
[debug] [XCUITestDriver@41cc] "appium:app": "/Users/timur/Source/my_app/builds/MC/5.33.00/Debug-iphonesimulator/Myapp.app",
[debug] [XCUITestDriver@41cc] "appium:automationName": "XCUITest",
[debug] [XCUITestDriver@41cc] "appium:deviceName": "iPhone 14",
[debug] [XCUITestDriver@41cc] "appium:platformVersion": "16.4",
[debug] [XCUITestDriver@41cc] "appium:language": null,
[debug] [XCUITestDriver@41cc] "appium:systemPort": "8203",
[debug] [XCUITestDriver@41cc] "appium:useNewWDA": "true",
[debug] [XCUITestDriver@41cc] "appium:wdaStartupRetries": "2",
[debug] [XCUITestDriver@41cc] "appium:iosInstallPause": "1500",
[debug] [XCUITestDriver@41cc] "appium:usePrebuiltWDA": "true",
[debug] [XCUITestDriver@41cc] "appium:prebuiltWDAPath": "/Users/timur/Source/wda/builds/Debug-iphonesimulator/WebDriverAgentRunner-Runner.app",
[debug] [XCUITestDriver@41cc] "appium:eventLoopIdleDelaySec": "4"

and after this i see that appium tried to start build WDA

[XCUITestDriver@41cc (e343e763)] Using WDA path: '/Users/timur/.appium/node_modules/appium-xcuitest-driver/node_modules/appium-webdriveragent'
[XCUITestDriver@41cc (e343e763)] Using WDA agent: '/Users/timur/.appium/node_modules/appium-xcuitest-driver/node_modules/appium-webdriveragent/WebDriverAgent.xcodeproj'

after that something like this

[debug] [XCUITest] The app has been installed successfully.
[debug] [XCUITestDriver@41cc (e343e763)] iosInstallPause set. Pausing 1500 ms before continuing
[debug] [XCUITestDriver@41cc (e343e763)] Parsed BUILD_DIR configuration value: '/Users/timur/Library/Developer/Xcode/DerivedData/WebDriverAgent-fyjvxrpwlsooyrgxvslxsfpcejvt/Build/Products'
[debug] [XCUITestDriver@41cc (e343e763)] Got derived data root: '/Users/timur/Library/Developer/Xcode/DerivedData/WebDriverAgent-fyjvxrpwlsooyrgxvslxsfpcejvt'
[debug] [XCUITestDriver@41cc (e343e763)] Event 'appInstalled' logged at 1690924396239 (02:13:16 GMT+0500 (Uzbekistan Standard Time))
[debug] [XCUITestDriver@41cc (e343e763)] No obsolete cached processes from previous WDA sessions listening on port 8100 have been found
[DevCon Factory] Requesting connection for device FF88F575-44E1-4929-A714-367DA115B062 on local port 8100
[debug] [DevCon Factory] Cached connections count: 0
[DevCon Factory] Successfully requested the connection for FF88F575-44E1-4929-A714-367DA115B062:8100
[debug] [XCUITestDriver@41cc (e343e763)] Starting WebDriverAgent initialization with the synchronization key 'XCUITestDriver'
[debug] [XCUITestDriver@41cc (e343e763)] Capability 'useNewWDA' set to true, so uninstalling WDA before proceeding
[XCUITestDriver@41cc (e343e763)] Shutting down sub-processes
[debug] [XCUITestDriver@41cc (e343e763)] No WDAs on the device.
[debug] [XCUITestDriver@41cc (e343e763)] Event 'wdaUninstalled' logged at 1690924396369 (02:13:16 GMT+0500 (Uzbekistan Standard Time))
[debug] [XCUITestDriver@41cc (e343e763)] Trying to start WebDriverAgent 2 times with 10000ms interval
[debug] [XCUITestDriver@41cc (e343e763)] Event 'wdaStartAttempted' logged at 1690924396369 (02:13:16 GMT+0500 (Uzbekistan Standard Time))
[XCUITestDriver@41cc (e343e763)] Launching WebDriverAgent on the device
[XCUITestDriver@41cc (e343e763)] Cleaning up the WebDriverAgent project after the module upgrade has happened (5.0.0 < 5.6.0)
[debug] [XCUITestDriver@41cc (e343e763)] Cleaning the project scheme 'WebDriverAgentLib' to make sure there are no leftovers from previous installs
[debug] [XCUITestDriver@41cc (e343e763)] Cleaning the project scheme 'WebDriverAgentRunner' to make sure there are no leftovers from previous installs
[debug] [WebDriverAgent] Killing running processes 'xcodebuild.*FF88F575-44E1-4929-A714-367DA115B062, FF88F575-44E1-4929-A714-367DA115B062.*XCTRunner, xctest.*FF88F575-44E1-4929-A714-367DA115B062' for the device FF88F575-44E1-4929-A714-367DA115B062...
[debug] [WebDriverAgent] 'pgrep -if xctest.*FF88F575-44E1-4929-A714-367DA115B062' didn't detect any matching processes. Return code: 1
[debug] [WebDriverAgent] 'pgrep -if xcodebuild.*FF88F575-44E1-4929-A714-367DA115B062' didn't detect any matching processes. Return code: 1
[debug] [WebDriverAgent] 'pgrep -if FF88F575-44E1-4929-A714-367DA115B062.*XCTRunner' didn't detect any matching processes. Return code: 1
[debug] [XCUITestDriver@41cc (e343e763)] Beginning test with command 'xcodebuild test-without-building -project /Users/timur/.appium/node_modules/appium-xcuitest-driver/node_modules/appium-webdriveragent/WebDriverAgent.xcodeproj -scheme WebDriverAgentRunner -derivedDataPath /Users/timur/Library/Developer/Xcode/DerivedData/WebDriverAgent-fyjvxrpwlsooyrgxvslxsfpcejvt -destination id=FF88F575-44E1-4929-A714-367DA115B062 IPHONEOS_DEPLOYMENT_TARGET=16.4 GCC_TREAT_WARNINGS_AS_ERRORS=0 COMPILER_INDEX_STORE_ENABLE=NO' in directory '/Users/timur/.appium/node_modules/appium-xcuitest-driver/node_modules/appium-webdriveragent'
[debug] [XCUITestDriver@41cc (e343e763)] Output from xcodebuild will only be logged if any errors are present there. To change this, use 'showXcodeLog' desired capability
[debug] [XCUITestDriver@41cc (e343e763)] Waiting up to 60000ms for WebDriverAgent to start
[debug] [XCUITestDriver@41cc (e343e763)] Matched '/status' to command name 'getStatus'
[debug] [XCUITestDriver@41cc (e343e763)] Proxying [GET /status] to [GET http://127.0.0.1:8100/status] with no body
[XCUITestDriver@41cc (e343e763)] connect ECONNREFUSED 127.0.0.1:8100
[Xcode] xcodebuild exited with code '65' and signal 'null'

after a couple unsuccessful retries logs show this

[debug] [XCUITestDriver@41cc (e343e763)] No WDAs on the device.
[XCUITestDriver@41cc (e343e763)] {}
[DevCon Factory] Releasing connections for FF88F575-44E1-4929-A714-367DA115B062 device on any port number
[DevCon Factory] Found cached connections to release: ["FF88F575-44E1-4929-A714-367DA115B062:8100"]
[debug] [DevCon Factory] Cached connections count: 0
[debug] [XCUITestDriver@41cc (e343e763)] Not clearing log files. Use clearSystemFiles capability to turn on.
[debug] [IOSSimulatorLog] Stopping iOS log capture
[debug] [AppiumDriver@5898] Event 'newSessionStarted' logged at 1690924421447 (02:13:41 GMT+0500 (Uzbekistan Standard Time))
[debug] [AppiumDriver@5898] Encountered internal error running command: Error: Unable to launch WebDriverAgent because of xcodebuild failure: xcodebuild failed with code 65
[debug] [AppiumDriver@5898] xcodebuild error message:
[debug] [AppiumDriver@5898]
[debug] [AppiumDriver@5898] at quitAndUninstall (/Users/timur/.appium/node_modules/appium-xcuitest-driver/lib/driver.js:808:15)
[debug] [AppiumDriver@5898] at /Users/timur/.appium/node_modules/appium-xcuitest-driver/lib/driver.js:894:13
[debug] [AppiumDriver@5898] at wrapped (/Users/timur/.appium/node_modules/appium-xcuitest-driver/node_modules/asyncbox/lib/asyncbox.js:95:13)
[debug] [AppiumDriver@5898] at retry (/Users/timur/.appium/node_modules/appium-xcuitest-driver/node_modules/asyncbox/lib/asyncbox.js:68:13)
[debug] [AppiumDriver@5898] at retryInterval (/Users/timur/.appium/node_modules/appium-xcuitest-driver/node_modules/asyncbox/lib/asyncbox.js:105:10)
[debug] [AppiumDriver@5898] at /Users/timur/.appium/node_modules/appium-xcuitest-driver/lib/driver.js:833:7
[HTTP] <-- POST /wd/hub/session 500 29409 ms - 744

#```

I assume you may want to try out https://appium.github.io/appium-xcuitest-driver/4.32/run-prebuilt-wda/#how-to-use-appiumusexctestrunfile-and-appiumbootstrappath-capabilities

As https://appium.github.io/appium-xcuitest-driver/4.32/capabilities/ 's description for prebuiltWDAPath, it is for real devices only.

The path to a WebDriverAgentRunner application package to be installed with appium:usePreinstalledWDA capability for real devices. The package's bundle id will be used over appium:updatedWDABundleId.

@KazuCocoa Thank you for quick response.
I checked this info and yes it can be work around for me, it feels not handy but ok.
I faced with another one problem.
After creating wda and xcui test file appium cannot recognize the test file and gives the following log

[debug] [XCUITestDriver@eea1 (8d92d744)] Unable to launch WebDriverAgent because of xcodebuild failure: If you are using 'useXctestrunFile' capability then you need to have a xctestrun file (expected: '/Users/timur/.appium/node_modules/appium-xcuitest-driver/node_modules/appium-webdriveragent/wda_build/Build/Products/WebDriverAgentRunner_iphonesimulator16.4-x86_64.xctestrun

actually wda_build/Build/Products dir contain WebDriverAgentRunner_iphonesimulator16.4-arm64.xctestrun

However after renaming
mv WebDriverAgentRunner_iphonesimulator16.4-arm64.xctestrun WebDriverAgentRunner_iphonesimulator16.4-x86_64.xctestrun
WDA was correctly installed and after that near was created new file with such name FF88F575-44E1-4929-A714-367DA115B062_16.4.xctestrun

They depend on xcodebuild. Usually x86_64/arm64 depends on arch argument for xcodebuild or running environment. The generated file is used by xcodebuild to manage the app. Appium simply provide possible arguments to the xcodebuild. (You can see more details about the xcodebuild with man command)

@KazuCocoa It works, but not reduce session startup time dramatically. I tried parallel testing for 3 sim on one mac, and WDA for each was installed after...: WebDriverAgent successfully started after 82502ms. It is strange because "undertest.app" install took a couple seconds.
Anyway thank you for your time

yea, xcodebuild does something, so to make optimize the time further, perhaps we could do something like real devices
https://appium.github.io/appium-xcuitest-driver/4.32/run-preinstalled-wda/

But I don't know much about it for simulators right now