Skip to content

Instantly share code, notes, and snippets.

@mrroot5
Last active March 11, 2019 11:27
Show Gist options
  • Save mrroot5/2c0e2bbf7ad22ad13458c68e530f01d5 to your computer and use it in GitHub Desktop.
Save mrroot5/2c0e2bbf7ad22ad13458c68e530f01d5 to your computer and use it in GitHub Desktop.
Nigthwatchjs chromedriver configuration

Versions

  • Nightwatch: 1.0.18.
  • Selenium standalone: 3.141.59.
  • Chromedriver: 2.46.

Step by step

  • Install chromedriver:
# Inside project
npm install chromedriver --save-dev
# Globally
# npm install -g chromedriver --save-dev
  • Create the nightwatch's config file:
{
    "src_folders" : ["./tests"],
    "output_folder": "./tests/reports",
    "selenium": {
        "start_process": true,
        "server_path": "./bin/selenium-server-standalone-3.141.59.jar",
        "cli_args" : {
            "webdriver.chrome.driver" : "./node_modules/.bin/chromedriver"
          }
    },
    "test_settings" : {
        "default" : {
            "webdriver": {
                "start_process": false,
                "start_session": false,
                "host": "127.0.1.1",
                "port": 9515,
                "server_path": "./node_modules/.bin/chromedriver",
                "log_path": "./browser-test/logs/"
            },
            "screenshots" : {
                "enabled" : true,
                "on_failure" : true,
                "on_error" : false,
                "path" : ""
            },
            "desiredCapabilities" : {
                "browserName" : "chrome",
                "javascriptEnabled" : true,
                "acceptSslCerts" : true,
                "chromeOptions": {
                    "args": [
                        "start-maximized"
                    ]
                }
            }
        }
    }
}

EXPLANATION

  • We configure selenium to use npm chromedriver.

  • Inside test_settings we add all settings to default because we will only use Chrome.

  • Now, we configure webdriver for Chrome. It's important that start_process and start_session was false to avoid conflicts with selenium server. host has our local ip (localhost), in addition, with port we configure the chromedriver port 9515 by default. Important, If you installed chromedriver globally change the server_path and type only chromedriver instead of the full path.

  • In desiredCapabilities you can configure how Chrome works. In this example we enabled javascript, the ssl certs and we start Chrome maximized.

Documentación

Versiones

  • Nightwatch: 1.0.18.
  • Selenium standalone: 3.141.59.
  • Chromedriver: 2.46.

Paso a paso

  • Instala chromedriver:
# En proyecto
npm install chromedriver --save-dev
# Globalmente
# npm install -g chromedriver --save-dev
  • Crea el fichero de configuración de nigthwatch:
{
    "src_folders" : ["./tests"],
    "output_folder": "./tests/reports",
    "selenium": {
        "start_process": true,
        "server_path": "./bin/selenium-server-standalone-3.141.59.jar",
        "cli_args" : {
            "webdriver.chrome.driver" : "./node_modules/.bin/chromedriver"
          }
    },
    "test_settings" : {
        "default" : {
            "webdriver": {
                "start_process": false,
                "start_session": false,
                "host": "127.0.1.1",
                "port": 9515,
                "server_path": "./node_modules/.bin/chromedriver",
                "log_path": "./browser-test/logs/"
            },
            "screenshots" : {
                "enabled" : true,
                "on_failure" : true,
                "on_error" : false,
                "path" : ""
            },
            "desiredCapabilities" : {
                "browserName" : "chrome",
                "javascriptEnabled" : true,
                "acceptSslCerts" : true,
                "chromeOptions": {
                    "args": [
                        "start-maximized"
                    ]
                }
            }
        }
    }
}

EXPLICACIÓN

  • Configuramos selenium para usar el chromedriver de npm.

  • En test_settings agregamos todas las configuraciones a un default ya que solamente usaremos Chrome.

  • Configuramos el webdriver para Chrome. Es importante indicar que start_process y start_session estén a false o podríamos tener conflictos con selenium server. host tiene nuestra ip local (localhost) y con port configuramos el puerto de chromedriver 9515 por defecto. Importante, si instalaste chromedriver globalmente cambia el server_path y pon solamente chromedriver.

  • En desiredCapabilities puedes configurar cómo funciona Chrome. En este ejemplo se ha habilitado javascript, los certificados ssl y se inicia maximizado.

Documentation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment