Nightwatchは、BrowserStackやSauce LabsなどのリモートSeleniumグリッドまたはクラウドプロバイダーで実行するように設定できます。

BrowserStackでの実行

CLIユーティリティを使用してNightwatchをインストールし、BrowserStackリモートマシンで実行することを選択した場合、`nightwatch.conf.js`の`test_settings`プロパティにBrowserStack設定ブロックが自動生成されます。

既存のプロジェクトでBrowserStackでNightwatchを実行しようとしている場合は、`nightwatch.conf.js`ファイルに`browserstack`ブロックを`test_settings`の子プロパティとして追加する必要があります。

nightwatch.conf.js
module.exports = {
    ...,
    test_settings: {
        ...,
        browserstack: {
            selenium: {
                host: 'hub.browserstack.com',
                port: 443
            },
            // More info on configuring capabilities can be found on:
            // https://www.browserstack.com/automate/capabilities?tag=selenium-4
            desiredCapabilities: {
                'bstack:options': {
                    userName: '${BROWSERSTACK_USERNAME}',
                    accessKey: '${BROWSERSTACK_ACCESS_KEY}'
                }
            },
            
disable_error_log: true, webdriver: { timeout_options: { timeout: 15000, retry_attempts: 3 }, keep_alive: true, start_process: false } },
'browserstack.local': { extends: 'browserstack', desiredCapabilities: { 'browserstack.local': true } },
'browserstack.firefox': { extends: 'browserstack', desiredCapabilities: { browserName: 'firefox' } },
'browserstack.local_firefox': { extends: 'browserstack.local', desiredCapabilities: { browserName: 'firefox' } }, ... } }

BrowerStackブロックがNightwatch設定ファイルに存在したら、BrowserStackのユーザー名とアクセスキーを自分の資格情報に置き換えれば、BrowserStackインフラストラクチャでテストを実行する準備が整います。

LambdaTestでの実行

既存のプロジェクトでLambdaTestでNightwatchを実行しようとしている場合は、`nightwatch.conf.js`ファイルに`lambdatest`ブロックを`test_settings`の子プロパティとして追加する必要があります。

nightwatch.conf.js
module.exports = {
    ...,
    test_settings: {
        ...,
        lambdatest: {
            selenium: {
                host: 'hub.lambdatest.com',
                port: 443
            },
            'username': '${LAMBDATEST_USERNAME}',
            'access_key': '${LAMBDATEST_ACCESS_KEY}',
        },
        // More info on configuring capabilities can be found on:
        // https://www.lambdatest.com/capabilities-generator/
        'lambdatest.chrome': {
            extends: 'lambdatest',
            desiredCapabilities: {
                browserName: 'chrome',
                'LT:Options': {
                    'platformName': 'Windows 10',
                    'browserVersion': '108.0',
                    'project': 'Project',
                }
            }
        },
        
'lambdatest.firefox': { extends: 'lambdatest', desiredCapabilities: { browserName: 'firefox', 'LT:Options': { 'platformName': 'Windows 10', 'browserVersion': '108.0', 'project': 'Untitled', } } }, ... } }

`nightwatch.conf.js`にLambdaTestの設定を追加したら、LambdaTestのユーザー名とaccess_keyを自分の資格情報に置き換えれば、LambdaTestクラウドグリッドでテストを実行する準備が整います。

自動化機能ジェネレーターを使用して、必要な機能を設定および追加することもできます。

Sauce Labsでの実行

CLIユーティリティを使用してNightwatchを設定するときにクラウドプロバイダーとしてSauce Labsを選択すると、テスト設定が自動的に追加されます。

既存のプロジェクトでSauce LabsでNightwatchを実行しようとしている場合は、以下に示すように、`nightwatch.conf.js`ファイルに次のブロックを追加する必要があります。

nightwatch.conf.js
module.exports = {
    ...,
    test_settings: {
        ...,
        saucelabs: {
            selenium: {
                host: 'ondemand.saucelabs.com',
                port: 443
            },
            // More info on configuring capabilities can be found on:
            // https://wiki.saucelabs.com/display/DOCS/Test+Configuration+Options
            desiredCapabilities: {
                'sauce:options': {
                username: '${SAUCE_USERNAME}',
                accessKey: '${SAUCE_ACCESS_KEY}',
                screenResolution: '1280x1024'
                // https://docs.saucelabs.com/dev/cli/sauce-connect-proxy/#--region
                // region: 'us-west-1'
                // https://docs.saucelabs.com/dev/test-configuration-options/#tunnelidentifier
                // parentTunnel: '',
                // tunnelIdentifier: '',
                },
                javascriptEnabled: true,
                acceptSslCerts: true,
                // https://docs.saucelabs.com/dev/test-configuration-options/#timezone
                timeZone: 'London'
            },
            disable_error_log: false,
            webdriver: {
                start_process: false
            }
        },
        
'saucelabs.firefox': { extends: 'saucelabs', desiredCapabilities: { browserName: 'firefox', browserVersion: 'latest', platformName: 'Windows 10' } }, ... } }

Sauce LabsブロックがNightwatch設定ファイルに存在したら、Sauce Labsのユーザー名とアクセスキーを自分の資格情報に置き換えます。

TestingBotでの実行

TestingBotを使用して、クラウド内のブラウザでNightwatchテストを実行できます。 `nightwatch.conf.js`ファイルに`testingbot`ブロックを`test_settings`の子プロパティとして追加する必要があります。

nightwatch.conf.js
module.exports = {
    ...,
    test_settings: {
        ...,
        testingbot: {
            selenium: {
                host: 'hub.testingbot.com',
                port: 443
            },
            'username': '${TB_KEY}',
            'access_key': '${TB_SECRET}',
        },
        'testingbot.chrome': {
            extends: 'testingbot',
            desiredCapabilities: {
                browserName: 'chrome',
                'tb:options': {
                    'platformName': 'Windows 10',
                    'version': 'latest',
                    'name': 'First Nightwatch test',
                }
            }
        },
        
'testingbot.firefox': { extends: 'testingbot', desiredCapabilities: { browserName: 'firefox', 'tb:options': { 'platformName': 'Windows 10', 'version': 'latest', 'name': 'First Nightwatch test', } } }, ... } }

`nightwatch.conf.js`にTestingBotの設定を追加したら、TestingBotのユーザー名とaccess_keyをTestingBotメンバーエリアで入手できる自分の資格情報に置き換えてください。

TestingBotでのテストをカスタマイズするために使用できる他の機能があります。

リモートSeleniumサーバーでの実行

`create-nightwatch`ユーティリティを使用してNightwatchをインストールし、リモートセレンサーバーまたは他のクラウドプロバイダーに対して実行することを選択した場合、リモートホスト設定はプレースホルダー値とともに`test_settings`に自動的に追加されます。

既存のプロジェクトでこれを設定しようとしている場合は、以下に示すように、`nightwatch.conf.js`ファイルの`test_settings`プロパティに次のブロックを追加する必要があります。

nightwatch.conf.js
module.exports = {
    ...,
    test_settings : {
        ...,
        remote: {
            // Info on all the available options with "selenium":
            // /guide/configuration/settings.html#selenium-server-settings
            selenium: {
                start_process: false,
                server_path: '',
                host: '<remote-hostname>',
                port: 4444
            },
            
username: '${REMOTE_USERNAME}', access_key: '${REMOTE_ACCESS_KEY}',
webdriver: { keep_alive: true, start_process: false } },
'remote.firefox': { extends: 'remote', desiredCapabilities: { browserName: 'firefox', 'moz:firefoxOptions': { args: [ // '-headless', // '-verbose' ] } } }, ... } }

設定ブロックが追加されたら、リモートホスト、ポート、および資格情報を自分のものと置き換えて、開始してください!

さらにサポートが必要な場合は、Discordサーバーにご参加ください。