AWS设备农场][Nightwatchjs][Appium]Nightwatch驱动无法连接到在AWS设备农场中运行的Appium。

问题描述 投票:0回答:1

试图在移动设备中使用设备农场来实现Web应用测试自动化。源代码测试是用nightwatch.js编写的。

以下是nightwatch的配置。

{
  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",
      }
    }
  }

使用模拟器,测试在本地运行正常

但在设备农场中得到以下错误信息。Nightwatch not able to connect to 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 [email protected]: 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.

> [email protected] 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 [email protected] requires a peer of cucumber@^6.0.5 but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of nightwatch@^1.3.6 but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of nightwatch-api@^3.0.1 but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of selenium-server@^3.141.59 but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of selenium-server-standalone-jar@^3.141.59 but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] 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.

+ [email protected]
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

> [email protected] 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

> [email protected] 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

> [email protected] 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/iedriver64\IEDriverServer.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/iedriver\IEDriverServer.exe

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


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


> [email protected] 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)


> [email protected] 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

> [email protected] 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"


> [email protected] clean /tmp/scratch9MGzGQ.scratch/test-package4sST7I/node_modules/bitcentralqa-base-nightwatch-framework
> rimraf dist/**/*


> [email protected] build /tmp/scratch9MGzGQ.scratch/test-package4sST7I/node_modules/bitcentralqa-base-nightwatch-framework
> tsc --build ./tsconfig.json


> [email protected] 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.

是否有遗漏的Nightwatch和设备场的配置?

appium nightwatch.js appium-android aws-device-farm
1个回答
0
投票

你能不能尝试用start_process.True重新运行它,并验证一下端口是否没有被打开。True的情况下重新运行,并检查端口是否还没有被使用。


0
投票

问题是由于一段代码在测试开始前杀死了chrome webdriver进程,杀死webdriver不会在模拟器上造成任何问题,所以在设备农场中运行测试时,必须禁止杀死webdriver进程。

© www.soinside.com 2019 - 2024. All rights reserved.