AWS Device Farm は、Selenium を使用したリモートブラウザテストを可能にするクラウドテストプラットフォームの 1 つです。いくつかの調整を自動生成された設定ファイル nightwatch.conf.js に加えることで、Nightwatch を AWS と共に使用できます。

AWS Device Farm で新しいプロジェクトを作成する

AWS のアカウントをお持ちの場合は、コンソールにアクセスして Device Farm ダッシュボードに移動します。ダッシュボードから *デスクトップブラウザテスト > プロジェクト* を選択し、そこで新しいプロジェクトを作成します。プロジェクトを設定したら、*プロジェクト ARN* を書き留めてください。

aws-cli の設定

まだインストールしていない場合は、aws-cli をインストールし、cli を使用して AWS にログインします。これにより、設定で使用される Node.js ライブラリに必要な資格情報ディレクトリが設定されます。

aws configure

aws-sdk のインストール

Nightwatch が設定されているのと同じフォルダーに aws-node sdk をインストールします。

npm install  aws-sdk

AWS の設定

AWS Device Farm に接続するためのテンプレートとしてこの設定を使用します。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.dokyumento.jp',
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 } } } } })();