5

私は selenium-webdriver を使用していましたが、nightwatch.js を試して使いやすいかどうかを確認したかったのです。こちらの指示に従いました。Nightwatch に自動的に Selenium サーバーを起動させることにしたので、上記のリンクに基づいて適切な構成であると思われることを行いました。理解できないエラーが発生し、出力には次のように表示されます。

Starting selenium server... started - PID:  1760

[Test] Test Suite
=================

Running:  demoTestGoogle

Error retrieving a new session from the selenium server
Error: connect ECONNREFUSED 127.0.0.1:8080
    at Object.exports._errnoException (util.js:856:11)
    at exports._exceptionWithHostPort (util.js:879:20)
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1053:14)


Connection refused! Is selenium server started?


Process finished with exit code 1

セレンのデバッグログファイルはこれを言います

13:43:03.394 INFO - Launching a standalone Selenium Server
13:43:03.474 INFO - Java: Oracle Corporation 25.73-b02
13:43:03.474 INFO - OS: Windows 7 6.1 amd64
13:43:03.483 INFO - v2.52.0, with Core v2.52.0. Built from revision 4c2593c
13:43:03.530 INFO - Driver class not found: com.opera.core.systems.OperaDriver
13:43:03.530 INFO - Driver provider com.opera.core.systems.OperaDriver is not registered
13:43:03.536 INFO - Driver provider org.openqa.selenium.safari.SafariDriver registration is skipped:
registration capabilities Capabilities [{browserName=safari, version=, platform=MAC}] does not match the current platform VISTA
13:43:03.665 INFO - RemoteWebDriver instances should connect to: http://127.0.0.1:4444/wd/hub
13:43:03.665 INFO - Selenium Server is up and running

これは私の nightwatch.json ファイルです

{
  "src_folders": [ "tests" ],
  "output_folder": "reports",
  "custom_commands_path": "",
  "custom_assertions_path": "",
  "page_objects_path": "",
  "globals_path": "",
  "selenium": {
    "start_process": true,
    "server_path": "./bin/selenium-server-standalone-jar/jar/selenium-server-standalone-2.52.0.jar",
    "start_session" : true,
    "log_path": "",
    "host": "",
    "port": 4444,
    "cli_args": {
      "webdriver.chrome.driver": "",
      "webdriver.ie.driver": ""
    }
  },
  "test_settings": {
    "default": {
      "launch_url": "http://localhost",
      "selenium_port": 8080,
      "selenium_host": "localhost",
      "silent": true,
      "screenshots": {
        "enabled": false,
        "path": ""
      },
      "desiredCapabilities": {
        "browserName": "firefox",
        "javascriptEnabled": true,
        "acceptSslCerts": true
      }
    },
    "chrome": {
      "desiredCapabilities": {
        "browserName": "chrome",
        "javascriptEnabled": true,
        "acceptSslCerts": true
      }
    }
  }
}

編集: demoTestGoogle を追加しました。実行する nightwatch.js ファイルがあり、demoTestGoogle 関数を実行します。

demoTestGoogle を実行する nightwatch.js

require('nightwatch/bin/runner.js');

別の JS ファイルの demoTestGoogle 関数

this.demoTestGoogle = function (browser) {
    browser
        .url('http://www.google.com')
        .waitForElementVisible('body', 1000)
        .setValue('input[type=text]', 'nightwatch')
        .waitForElementVisible('button[name=btnG]', 1000)
        .click('button[name=btnG]')
        .pause(1000)
        .assert.containsText('#main', 'The Night Watch')
        .end();
};
4

1 に答える 1