3
3

More than 5 years have passed since last update.

[Nightwatch.js]configファイルを設定する

Posted at

configファイルを設定する

<課題>
下記のような課題に対して有効です
* テスト実行する上でテキストフォームに設定する値などリクエストする値を運用上のことも考えて一元管理したい
* テストコード開発中にあちこちで同じ値を使いまわすのを避けたい

<手順>
1. nightwatch.jsonに設定ファイルのパスを指定
2. 設定ファイルをjsonで作成
3. アクセス

1.nightwatch.jsonに設定ファイルのパスを指定

  • globals_pathに設定ファイルのパスを書く ※今回はsetting.jsonというファイルにする
nightwatch.json
{
  "src_folders" : ["./examples/tests"],
  "output_folder" : "./examples/reports",
  "custom_commands_path" : "./examples/custom-commands",
  "custom_assertions_path" : "",
  "globals_path" : "./setting.json",
  "live_output" : false,

2.設定ファイルをjsonで作成

setting.json
{
    "hoge" : "fuga"
}

3.アクセス

  • hogeにアクセスする
testsample.js
module.exports = {
  'Demo test Google' : function (client) {
    // hogeにアクセス&testにfugaがセット
    var test = client.globals.hoge

    client
      .url('http://www.google.com')
      .windowMaximize()

      // fuga がフォームにセットされる
      .setValue('input[type=text]', test)
      .waitForElementVisible('button[name=btnG]', 1000)
      .click('button[name=btnG]')
      .pause(1000)
      .end();
  }
};
3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3