AWS Device Farm 設定
AWS Device Farm 是一個雲端測試平台,可讓使用者使用 Selenium 執行遠端瀏覽器測試。可以透過對自動產生的設定檔 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.dev.org.tw',
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
}
}
}
}
})();