Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request redirection uses 127.0.0.1 instead of server host when location header is relative #3096

Closed
mdeclercq-ukg opened this issue Mar 10, 2022 · 0 comments · Fixed by #3265
Labels

Comments

@mdeclercq-ukg
Copy link
Contributor

Describe the bug

When launching a test on Saucelabs, if the maximum number of sessions is already reached, the test is put in a queue.
In such a case, the request on /wd/hub/session responds with a status 303 and the headers:

  {
     location: '/wd/hub/session/123-sessionId...',
     'content-length': ‘0’,
    //  ...
  }

Notice that the location header is a relative url, it does not contain the hostname.

The problem

Instead of sending the next request to the Saucelabs server, it sends it to 127.0.0.1 and fails.
See the last line of the attached logs:

Connection refused to 127.0.0.1:443

Analysis from local debugging

The location header is parsed with require("url").parse() in request.js#L228 which returns { hostname: null, port:null }.
This sets the hostname of the following requests to null and later defaults to 127.0.0.1 in the following requests.

According to https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Location#directives, the location header can be relative or absolute.

Below are the files I used to reproduce, but one really needs a Saucelabs instance with all its sessions busy to reproduce.
The redirection worked fine in versions 1.7.x.

Sample test

sampleTest.js

describe('Ecosia.org Demo', function() {

    before(browser => browser.navigateTo('https://www.ecosia.org/'));
  
    it('Demo test ecosia.org', function(browser) {
      browser
        .waitForElementVisible('body')
        .assert.titleContains('Ecosia')
        .assert.visible('input[type=search]')
        .setValue('input[type=search]', 'nightwatch')
        .assert.visible('button[type=submit]')
        .click('button[type=submit]')
        .assert.textContains('.mainline-results', 'Nightwatch.js');
    });
  
    after(browser => browser.end());
  });

Run with command

$ nightwatch -c config.js --verbose src/sampleTest.js

Verbose output

debug.log

[Ecosia.org Demo] Test Suite
────────────────────────────────────────────────────────
⠋ Connecting to ondemand.eu-central-1.saucelabs.com on port 443...
   Request POST https://ondemand.eu-central-1.saucelabs.com/wd/hub/session
   { desiredCapabilities:
      { browserName: 'chrome',
        'sauce:options': { ... },
        name: 'Ecosia.org Demo',
        'goog:chromeOptions': {} },
     capabilities: { ... }
⠴ Connecting to ondemand.eu-central-1.saucelabs.com on port 443...
   Response 303 POST https://ondemand.eu-central-1.saucelabs.com/wd/hub/session (45452ms)
{}
   Request GET https://ondemand.eu-central-1.saucelabs.com/wd/hub/session/123-sessionId
   { desiredCapabilities:
      { browserName: 'chrome',
        'sauce:options': { ... },
        name: 'Ecosia.org Demo',
        'goog:chromeOptions': {} },
     capabilities: { ... }
    GET https://ondemand.eu-central-1.saucelabs.com /wd/hub/session/123-sessionId - ECONNREFUSED
⠦ Connecting to ondemand.eu-central-1.saucelabs.com on port 443...
   Request GET https://ondemand.eu-central-1.saucelabs.com/wd/hub/session/123-sessionId  (retry 1)

    ...

     TEST FAILURE (45.849s):
   - 1 error during execution;
   - 0 tests failed;
   - 0/NA tests passed


  Error: An error occurred while creating a new Selenium Server session: Connection refused to 127.0.0.1:443. If the Webdriver/Selenium service is managed by Nightwatch, check if "start_process" is set to "true".

Configuration

config.js

module.exports = {
  src_folders: ["src"],
  test_settings: {
    default: {
      selenium: {
        host: "ondemand.eu-central-1.saucelabs.com",
        port: 443
      },
      desiredCapabilities: {
        browserName: 'chrome',
        'sauce:options': {
          username: '${SAUCELABS_USER}',
          accessKey: '${SAUCELABS_KEY}',,
          seleniumVersion: '4.1.2',
        }
      }
    },
  }
};

Your Environment

Executable Version
nightwatch --version 2.0.10
npm --version 8.3.1
node --version v16.14.0
Browser driver Version
chromedriver 76
Selenium 4.1.2
OS Version
macOS BigSur 11.6.2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants