[AWS Device Farm][Nightwatchjs][Appium] Nightwatch 驱动程序无法连接到



尝试使用设备场在移动设备中进行 Web 应用测试自动化。源代码测试是在 Nightwatch.js 中编写的。

以下是守夜人的配置:

{
custom_assertions_path: 'custom-assertions',
test_settings: {
default: {
selenium: {
start_process: false,
port: 4723,
host: "localhost",
silent: true,
},
android: {
desiredCapabilities = {
browserName: "Chrome",
platformName: "Android",
platformVersion: "7.0",
device: "Android",
deviceName: "Pixel 2",
avd: "Pixel_2_API_24",
}
}
}

使用模拟器测试在本地运行良好

但是在设备场中出现以下错误。夜巡无法连接到Appium(ECONNREFUSED(。

Starting automation...
Done processing feature files.
Done killing webdriver processes.
Running cucumber...
- [0;36mConnecting to localhost on port 4723...
[0m
[1;31m   POST  /wd/hub/session - ECONNREFUSED
Error: connect ECONNREFUSED 127.0.0.1:4723[0m
⚠ [0;31mError connecting to localhost on port 4723.[0m
VError: a BeforeAll hook errored on slave 0, process exiting: dist/src/cucumber.conf.js:64: An error occurred while retrieving a new session: "Connection refused to 127.0.0.1:4723". If the Webdriver/Selenium service is managed by Nightwatch, check if "start_process" is set to "true".
at _bluebird.default.each (/tmp/scratch9MGzGQ.scratch/test-package4sST7I/node_modules/bitcentralqa-base-nightwatch-framework/node_module 

下面是设备场中的测试日志。

[DEVICEFARM] Setting up your device. This usually takes 2-3 minutes.
[DEVICEFARM] ########### Start executing testspec ###########

[DEVICEFARM] ########### Entering phase install ###########
[DeviceFarm] echo "Navigate to test package directory"
Navigate to test package directory
[DeviceFarm] cd $DEVICEFARM_TEST_PACKAGE_PATH
[DeviceFarm] npm install *.tgz
npm WARN deprecated core-js@2.6.11: core-js@<3 is no longer maintained and not recommended for usage due to the number of issues. Please, upgrade your dependencies to the actual version of core-js@3.
> core-js@2.6.11 postinstall /tmp/scratch9MGzGQ.scratch/test-package4sST7I/node_modules/core-js
> node -e "try{require('./postinstall')}catch(e){}"
[96mThank you for using core-js ([94m https://github.com/zloirock/core-js [96m) for polyfilling JavaScript standard library![0m
[96mThe project needs your help! Please consider supporting of core-js on Open Collective or Patreon: [0m
[96m>[94m https://opencollective.com/core-js [0m
[96m>[94m https://www.patreon.com/zloirock [0m
[96mAlso, the author of core-js ([94m https://github.com/zloirock [96m) is looking for a good job -)[0m
npm WARN saveError ENOENT: no such file or directory, open '/tmp/scratch9MGzGQ.scratch/test-package4sST7I/package.json'
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN enoent ENOENT: no such file or directory, open '/tmp/scratch9MGzGQ.scratch/test-package4sST7I/package.json'
npm WARN bitcentralqa-base-nightwatch-framework@0.1.6 requires a peer of cucumber@^6.0.5 but none is installed. You must install peer dependencies yourself.
npm WARN bitcentralqa-base-nightwatch-framework@0.1.6 requires a peer of nightwatch@^1.3.6 but none is installed. You must install peer dependencies yourself.
npm WARN bitcentralqa-base-nightwatch-framework@0.1.6 requires a peer of nightwatch-api@^3.0.1 but none is installed. You must install peer dependencies yourself.
npm WARN bitcentralqa-base-nightwatch-framework@0.1.6 requires a peer of selenium-server@^3.141.59 but none is installed. You must install peer dependencies yourself.
npm WARN bitcentralqa-base-nightwatch-framework@0.1.6 requires a peer of selenium-server-standalone-jar@^3.141.59 but none is installed. You must install peer dependencies yourself.
npm WARN cucumber-pretty@6.0.0 requires a peer of cucumber@>=6.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN test-package4sST7I No description
npm WARN test-package4sST7I No repository field.
npm WARN test-package4sST7I No README data
npm WARN test-package4sST7I No license field.
+ bitcentralqa-base-nightwatch-framework@0.1.6
added 127 packages from 111 contributors and audited 127 packages in 37.515s
found 1 low severity vulnerability
run `npm audit fix` to fix them, or `npm audit` for details
[DeviceFarm] export APPIUM_VERSION=1.14.2
[DeviceFarm] avm $APPIUM_VERSION
/usr/bin/avm: line 261: appium: command not found
[36m    exists[0m : [90m[0m
[DeviceFarm] ln -s /usr/local/avm/versions/$APPIUM_VERSION/node_modules/.bin/appium  /usr/local/avm/versions/$APPIUM_VERSION/node_modules/appium/bin/appium.js
[DeviceFarm] if [ $(echo $APPIUM_VERSION | cut -d "." -f2) -ge 15 ]; then
DEVICEFARM_DEVICE_UDID_FOR_APPIUM=$(echo $DEVICEFARM_DEVICE_UDID | tr -d "-");
DEVICEFARM_WDA_DERIVED_DATA_PATH=$DEVICEFARM_WDA_DERIVED_DATA_PATH_V2;
else
DEVICEFARM_DEVICE_UDID_FOR_APPIUM=$DEVICEFARM_DEVICE_UDID;
DEVICEFARM_WDA_DERIVED_DATA_PATH=$DEVICEFARM_WDA_DERIVED_DATA_PATH_V1;
fi
[DEVICEFARM] ########### Entering phase pre_test ###########
[DeviceFarm] if [ $DEVICEFARM_DEVICE_PLATFORM_NAME = "Android" ]; then echo "Start appium server for android"; (appium --log-timestamp --default-capabilities "{"deviceName": "$DEVICEFARM_DEVICE_NAME", "platformName":"$DEVICEFARM_DEVICE_PLATFORM_NAME", "app":"$DEVICEFARM_APP_PATH", "udid":"$DEVICEFARM_DEVICE_UDID", "platformVersion":"$DEVICEFARM_DEVICE_OS_VERSION", "browserName":"Chrome", "chromedriverExecutable":"$DEVICEFARM_CHROMEDRIVER_EXECUTABLE"}" >> $DEVICEFARM_LOG_DIR/appiumlog.txt 2>&1 &); fi
Start appium server for android
[DeviceFarm] if [ $DEVICEFARM_DEVICE_PLATFORM_NAME = "iOS" ]; then echo "Start appium server for iOS"; (appium --log-timestamp --default-capabilities "{"usePrebuiltWDA": true, "derivedDataPath":"$DEVICEFARM_WDA_DERIVED_DATA_PATH", "deviceName": "$DEVICEFARM_DEVICE_NAME", "platformName":"$DEVICEFARM_DEVICE_PLATFORM_NAME", "app":"$DEVICEFARM_APP_PATH", "automationName":"XCUITest", "udid":"$DEVICEFARM_DEVICE_UDID_FOR_APPIUM", "platformVersion":"$DEVICEFARM_DEVICE_OS_VERSION", "browserName":"Safari"}" >> $DEVICEFARM_LOG_DIR/appiumlog.txt 2>&1 &); fi
[DeviceFarm] start_appium_timeout=0; while [ true ]; do
if [ $start_appium_timeout -gt 60 ];
then
echo "appium server never started in 60 seconds. Exiting";
exit 1;
fi;
grep -i "Appium REST http interface listener started on 0.0.0.0:4723" $DEVICEFARM_LOG_DIR/appiumlog.txt >> /dev/null 2>&1;
if [ $? -eq 0 ];
then
echo "Appium REST http interface listener started on 0.0.0.0:4723";
break;
else
echo "Waiting for appium server to start. Sleeping for 1 second";
sleep 1;
start_appium_timeout=$((start_appium_timeout+1));
fi;
done;
Waiting for appium server to start. Sleeping for 1 second
Waiting for appium server to start. Sleeping for 1 second
Waiting for appium server to start. Sleeping for 1 second
Waiting for appium server to start. Sleeping for 1 second
Waiting for appium server to start. Sleeping for 1 second
Waiting for appium server to start. Sleeping for 1 second
Waiting for appium server to start. Sleeping for 1 second
Waiting for appium server to start. Sleeping for 1 second
Waiting for appium server to start. Sleeping for 1 second
Waiting for appium server to start. Sleeping for 1 second
Waiting for appium server to start. Sleeping for 1 second
Waiting for appium server to start. Sleeping for 1 second
Waiting for appium server to start. Sleeping for 1 second
Waiting for appium server to start. Sleeping for 1 second
Waiting for appium server to start. Sleeping for 1 second
Waiting for appium server to start. Sleeping for 1 second
Appium REST http interface listener started on 0.0.0.0:4723
[DEVICEFARM] ########### Entering phase test ###########
[DeviceFarm] echo "Navigate to test source code"
Navigate to test source code
[DeviceFarm] cd $DEVICEFARM_TEST_PACKAGE_PATH/node_modules/bitcentralqa-base-nightwatch-framework
[DeviceFarm] echo "Start Appium Node test"
Start Appium Node test
[DeviceFarm] npm install && npm run e2e-build-test -- --env chrome_android_qa --tags accessFuelVideoTesterWebpagePass
> chromedriver@83.0.0 install /tmp/scratch9MGzGQ.scratch/test-package4sST7I/node_modules/bitcentralqa-base-nightwatch-framework/node_modules/chromedriver
> node install.js
(node:4046) ExperimentalWarning: The fs.promises API is experimental
Current existing ChromeDriver binary is unavailable, proceeding with download and extraction.
Downloading from file:  https://chromedriver.storage.googleapis.com/83.0.4103.39/chromedriver_linux64.zip
Saving to file: /tmp/83.0.4103.39/chromedriver/chromedriver_linux64.zip
Received 1040K...
Received 2080K...
Received 3120K...
Received 4160K...
Received 5099K total.
Extracting zip contents to /tmp/83.0.4103.39/chromedriver.
Copying to target path /tmp/scratch9MGzGQ.scratch/test-package4sST7I/node_modules/bitcentralqa-base-nightwatch-framework/node_modules/chromedriver/lib/chromedriver
Fixing file permissions.
Done. ChromeDriver binary available at /tmp/scratch9MGzGQ.scratch/test-package4sST7I/node_modules/bitcentralqa-base-nightwatch-framework/node_modules/chromedriver/lib/chromedriver/chromedriver
> edgedriver@4.17134.1 install /tmp/scratch9MGzGQ.scratch/test-package4sST7I/node_modules/bitcentralqa-base-nightwatch-framework/node_modules/edgedriver
> node install.js
downloadUrl: 
invalid config loglevel="notice"
NOTE: Cannot find Microsoft WebDriver for the current OS: linux x64 3.13.0-139-generic
> iedriver@3.14.2 install /tmp/scratch9MGzGQ.scratch/test-package4sST7I/node_modules/bitcentralqa-base-nightwatch-framework/node_modules/iedriver
> node install.js

Downloading 64 bit Windows IE driver server
-----
invalid config loglevel="notice"
Downloading https://selenium-release.storage.googleapis.com/3.14/IEDriverServer_x64_3.14.0.zip
tmp/iedriver64/IEDriverServer_x64_3.14.0.zip extracted to tmp/iedriver64
copying tmp/iedriver64 to /tmp/scratch9MGzGQ.scratch/test-package4sST7I/node_modules/bitcentralqa-base-nightwatch-framework/node_modules/iedriver/lib/iedriver64
Success! IEDriverServer binary available at /tmp/scratch9MGzGQ.scratch/test-package4sST7I/node_modules/bitcentralqa-base-nightwatch-framework/node_modules/iedriver/lib/iedriver64IEDriverServer.exe
Downloading 32 bit Windows IE driver server
-----
Downloading https://selenium-release.storage.googleapis.com/3.14/IEDriverServer_Win32_3.14.0.zip
tmp/iedriver/IEDriverServer_Win32_3.14.0.zip extracted to tmp/iedriver
copying tmp/iedriver to /tmp/scratch9MGzGQ.scratch/test-package4sST7I/node_modules/bitcentralqa-base-nightwatch-framework/node_modules/iedriver/lib/iedriver
Success! IEDriverServer binary available at /tmp/scratch9MGzGQ.scratch/test-package4sST7I/node_modules/bitcentralqa-base-nightwatch-framework/node_modules/iedriver/lib/iedriverIEDriverServer.exe
> core-js@2.6.11 postinstall /tmp/scratch9MGzGQ.scratch/test-package4sST7I/node_modules/bitcentralqa-base-nightwatch-framework/node_modules/core-js
> node -e "try{require('./postinstall')}catch(e){}"

> core-js-pure@3.6.5 postinstall /tmp/scratch9MGzGQ.scratch/test-package4sST7I/node_modules/bitcentralqa-base-nightwatch-framework/node_modules/core-js-pure
> node -e "try{require('./postinstall')}catch(e){}"

> ejs@2.7.4 postinstall /tmp/scratch9MGzGQ.scratch/test-package4sST7I/node_modules/bitcentralqa-base-nightwatch-framework/node_modules/ejs
> node ./postinstall.js
Thank you for installing [35mEJS[0m: built with the [32mJake[0m JavaScript build tool ([32mhttps://jakejs.com/[0m)

> geckodriver@1.19.1 postinstall /tmp/scratch9MGzGQ.scratch/test-package4sST7I/node_modules/bitcentralqa-base-nightwatch-framework/node_modules/geckodriver
> node index.js
Downloading geckodriver... Extracting... Complete.
added 526 packages from 996 contributors and audited 528 packages in 91.837s
found 1 low severity vulnerability
run `npm audit fix` to fix them, or `npm audit` for details
> bitcentralqa-base-nightwatch-framework@0.1.6 e2e-build-test /tmp/scratch9MGzGQ.scratch/test-package4sST7I/node_modules/bitcentralqa-base-nightwatch-framework
> npm run clean && npm run build && npm run e2e-test -- "--env" "chrome_android_qa" "--tags" "accessFuelVideoTesterWebpagePass"

> bitcentralqa-base-nightwatch-framework@0.1.6 clean /tmp/scratch9MGzGQ.scratch/test-package4sST7I/node_modules/bitcentralqa-base-nightwatch-framework
> rimraf dist/**/*

> bitcentralqa-base-nightwatch-framework@0.1.6 build /tmp/scratch9MGzGQ.scratch/test-package4sST7I/node_modules/bitcentralqa-base-nightwatch-framework
> tsc --build ./tsconfig.json

> bitcentralqa-base-nightwatch-framework@0.1.6 e2e-test /tmp/scratch9MGzGQ.scratch/test-package4sST7I/node_modules/bitcentralqa-base-nightwatch-framework
> node dist/index.js "--env" "chrome_android_qa" "--tags" "accessFuelVideoTesterWebpagePass"
Starting automation...
Done processing feature files.
Done killing webdriver processes.
Running cucumber...
- [0;36mConnecting to localhost on port 4723...
[0m
[1;31m   POST  /wd/hub/session - ECONNREFUSED
Error: connect ECONNREFUSED 127.0.0.1:4723[0m
⚠ [0;31mError connecting to localhost on port 4723.[0m
VError: a BeforeAll hook errored on slave 0, process exiting: dist/src/cucumber.conf.js:64: An error occurred while retrieving a new session: "Connection refused to 127.0.0.1:4723". If the Webdriver/Selenium service is managed by Nightwatch, check if "start_process" is set to "true".
at _bluebird.default.each (/tmp/scratch9MGzGQ.scratch/test-package4sST7I/node_modules/bitcentralqa-base-nightwatch-framework/node_modules/cucumber/lib/runtime/parallel/slave.js:143:49)
caused by: Error: An error occurred while retrieving a new session: "Connection refused to 127.0.0.1:4723". If the Webdriver/Selenium service is managed by Nightwatch, check if "start_process" is set to "true".
at Selenium2Protocol.handleSessionCreateError (/tmp/scratch9MGzGQ.scratch/test-package4sST7I/node_modules/bitcentralqa-base-nightwatch-framework/node_modules/nightwatch/lib/transport/transport.js:103:15)
at HttpRequest.request.on.err (/tmp/scratch9MGzGQ.scratch/test-package4sST7I/node_modules/bitcentralqa-base-nightwatch-framework/node_modules/nightwatch/lib/transport/transport.js:158:32)
at HttpRequest.emit (events.js:189:13)
at ClientRequest.originalIssuer.on.args (/tmp/scratch9MGzGQ.scratch/test-package4sST7I/node_modules/bitcentralqa-base-nightwatch-framework/node_modules/nightwatch/lib/http/request.js:131:19)
at ClientRequest.emit (events.js:194:15)
at Socket.socketErrorListener (_http_client.js:399:9)
at Socket.emit (events.js:189:13)
at emitErrorNT (internal/streams/destroy.js:82:8)
at emitErrorAndCloseNT (internal/streams/destroy.js:50:3)
at process.internalTickCallback (internal/process/next_tick.js:72:19)
0 scenarios
0 steps
0m00.000s
Done running cucumber...
Done killing webdriver processes.
Cucumber HTML report /tmp/scratch9MGzGQ.scratch/test-package4sST7I/node_modules/bitcentralqa-base-nightwatch-framework/dist/reports/cucumber-chrome_android_qa-report.html generated successfully.
Finished running automation.
[DEVICEFARM] ########### Entering phase post_test ###########

[DEVICEFARM] ########### Finish executing testspec ###########
[DEVICEFARM] ########### Setting upload permissions ###########

[DEVICEFARM] Tearing down your device. Your tests report will come shortly.

夜巡和设备场是否缺少任何配置

您可以尝试使用 start_process:True 重新运行它并验证端口是否尚未使用。

问题是由于一段代码在测试运行开始之前杀死了 chrome 网络驱动程序进程。破坏网络驱动程序不会在本地引起模拟器的任何问题,所以在设备场运行测试时,必须禁用杀死网络驱动程序进程。

最新更新