Aws 设备农场 是允许用户使用 Selenium 进行远程浏览器测试的云测试平台之一。可以通过对自动生成的配置文件 nightwatch.conf.js 进行一些调整,将 Nightwatch 与 AWS 结合使用。

在 AWS 设备农场中创建一个新项目

拥有 AWS 帐户后,可以转到控制台并导航到设备农场仪表板。从仪表板中选择桌面浏览器测试>项目,并在那里创建一个新项目。设置项目后,记下项目 ARN

设置 aws-cli

如果还没有,请安装 aws-cli 并使用 cli 登录到 aws。这将设置凭据目录,该目录将由配置中使用的 node.js 库需要。

aws configure

安装 aws-sdk

在 Nightwatch 设置的同一文件夹中安装 aws-node sdk。

npm install  aws-sdk

配置 AWS

使用此配置作为连接到 AWS 设备农场的模板。确保更新 PROJECT_ARN

nightwatch.conf.js
let AWS = require("aws-sdk");
let PROJECT_ARN = "<PROJECT_ARN>";
let devicefarm = new AWS.DeviceFarm({ region: "us-west-2" });


module.exports = (async function() { const testGridUrlResult = await devicefarm.createTestGridUrl({ projectArn: PROJECT_ARN, expiresInSeconds: 86400 }).promise(); const testGridUrl = new URL(testGridUrlResult.url);
return { // An array of folders (excluding subfolders) where your tests are located; // if this is not specified, the test source must be passed as the second argument to the test runner. src_folders: [],
// See /guide/working-with-page-objects/using-page-objects.html page_objects_path: ['node_modules/nightwatch/examples/pages/'],
// See /guide/extending-nightwatch/custom-commands.html custom_commands_path: ['node_modules/nightwatch/examples/custom-commands/'],
// See /guide/extending-nightwatch/custom-assertions.html custom_assertions_path: '',
// See /guide/extending-nightwatch/plugin-api.html plugins: [],
// See /guide/#external-globals globals_path : '',
webdriver: {},
test_settings: { default: { disable_error_log: false, launch_url: 'https://nightwatch.node.org.cn',
screenshots: { enabled: false, path: 'screens', on_failure: true },
desiredCapabilities: { browserName : 'chrome' }, },
awsDeviceFarm: { selenium: { host: testGridUrl.host, default_path_prefix: testGridUrl.pathname, port: 443 },
webdriver: { timeout_options: { timeout: 150000, retry_attempts: 3 }, ssl: true, keep_alive: true, start_process: false } } } } })();