nightwatchjs / nightwatch

Integrated end-to-end testing framework written in Node.js and using W3C Webdriver API. Developed at @browserstack
https://nightwatchjs.org
MIT License
11.79k stars 1.31k forks source link

Testing NTLM-enabled page with custom Firefox profile #1368

Closed tSte closed 7 years ago

tSte commented 7 years ago

I want to test NTLM-enabled website. I have successfully tested it using the IE and Chrome, but Firefox proved to be problematic. When I run Nightwatch, it opens Firefox with the modal dialog window that requires credentials (user name and password). Each test expects a <body> to be present => it fails instantly.

I know I can supply credentials, but that's something I'd rather avoid.

So I've created custom Firefox profile and changed some flags (about:config). It worked correctly, so I've updated nightwatch.conf.js to use that profile. I tried:

Without success.

My nightwatch.config.js exports an object like this:

{
  "src_folders": "./testcases",
  "output_folder": "./.reports",
  "page_objects_path": "./pages",
  "custom_commands_path": "./commands",
  "custom_assertions_path": "./assertions",
  "skip_testcases_on_fail": false,
  "detailed_output": false,
  "selenium": {
    "start_process": true,
    "server_path": ".bin\\2.53-selenium.jar",
    "host": "127.0.0.1",
    "port": 4444,
    "log_path": "./.reports",
    "cli_args": {
      "webdriver.gecko.driver": ".bin\\0.11.1-geckodriver.exe",
      "webdriver.firefox.profile": "nightwatch"
    }
  },
  "test_workers": {
    "enabled": true,
    "workers": "auto"
  },
  "test_settings": {
    "firefox:javascript": {
      "javascriptEnabled": true,
      "silent": true,
      "launch_url": "http://my.app.com",
      "screenshots": {
        "enabled": true,
        "on_failure": true,
        "on_error": false,
        "path": "./.screenshots"
      },
      "acceptSslCerts": true,
      "desiredCapabilities": {
        "browserName": "firefox",
        "marionette": true,
        "acceptSslCerts": true
      },
      "cli_args": {
        "webdriver.firefox.profile": "nightwatch"
      }
    }
  }
}

My sample test looks like this:

const FirefoxProfile = require('firefox-profile');

const test = {

  beforeEach(client, callback) {

    client.page.home().navigate();

    const iamProfile = new FirefoxProfile();
    iamProfile.setPreference('network.automatic-ntlm-auth.allow-non-fqdn', true);
    iamProfile.setPreference('network.automatic-ntlm-auth.trusted-uris', 'http://my.app.com');

    iamProfile.encoded((encodedProfile) => {
      client.options.desiredCapabilities['firefox_profile'] = encodedProfile;
      callback();
    });
  },

  'Page is available'(client) {

    const page = client.page.home();
    page.expect.element('body').to.be.present;
  }
};

Am I missing something? Did you manage to fix this problem? Thanks.

tSte commented 7 years ago

I updated selenium standalone server and it works as desired. Pls close...

beatfactor commented 7 years ago

Just so you know, you can also close...

NightwatchTele commented 7 years ago

Hi, Am experiencing a very similar issue. Am in the need of starting the firefox browser with a specific profile which i already configured and named "nightwatch" My system pref: win 10 64bit java version "1.8.0_121" npm -version 3.10.10 geckodriver-v0.18.0-win64 Selenium standalone 3.5.0 Firefox developer edition 56.0b5 (64-bit)

My nightwatch.json file is:

{
  "src_folders" : ["nw/tests"],
  "output_folder" : "nw/reports",
  "globals_path" : "nightwatch.globals.js",
  "test_workers": {
    "enabled": true,
    "workers": "auto"
  },
  "selenium" : {
    "start_process" : true,
    "server_path" : "./node_modules/selenium-server-standalone-jar/jar/selenium-server-standalone-3.5.0.jar",
    "log_path" : "nw/logs",
    "host" : "127.0.0.1",
    "port" : 4444,
    "cli_args" : {
      "webdriver.chrome.driver" : "./node_modules/chromedriver/lib/chromedriver/chromedriver.exe",
      "webdriver.ie.driver" : "",
      "webdriver.gecko.driver": "geckoDriver/geckodriver.exe"
    }
  },
  "test_settings" : {
    "default" : {
      "launch_url" : "http://google.com",
      "selenium_port"  : 4444,
      "selenium_host"  : "localhost",
      "silent": true,
      "screenshots" : {
        "enabled" : true,
        "path" : ""
      },
      "desiredCapabilities": {
        "browserName": "firefox",
        "javascriptEnabled": true,
        "acceptSslCerts": true,
    "marionette": false
      }
    }

  }
}

I have tried adding "webdriver.firefox.profile": "nightwatch" in both the selenium and test settings. The browser is started with the needed profile but the url from my test (example: http://mytestdomain.com) is never entered thus my test always fails.

If i put "marionette":true as described in the issue above Firefox is not started with the desired "nightwatch" profile and additionally my test is always failing at the 1st line .waitForElementVisible("body", 1000)

I have been search and reading a lot on the issue and didn't found something that will help me. I understood that the gecko driver has the possibility on receiving arguments in which the firefox profile can be specified, however my knowledge is very limited on the subject (4 days into nightwatch) and i simply can't resolve it at this moment. I don't know if i should post new issue due to my limited knowledge on the subject, so i decided to post a comment, as the above issue was resolved with an update to selenium, but i currently use all the latest versions to date.