dari0h
dari0h

Reputation: 897

Basic test fails on nightwatch phantomjs browser

I am using selenium server, nightwatch on node.js and phantomjs for selenium. I use phantomjs just for headless browser (with it selenium doesn't open browser visually when running tests).

My basic test passes when I use firefox as the browser but fails when I use phantomjs browser.

I setup basic google test:

module.exports = {
  'Demo test Google' : 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', 'Night Watch')
      .end();
  }
};

And setup phantomjs server. This is my nightwatch.json:

{
  "src_folders" : ["tests"],
  "output_folder" : "reports",
  "custom_commands_path" : "",
  "custom_assertions_path" : "",
  "page_objects_path" : "",
  "globals_path" : "",

  "selenium" : {
    "start_process" : false,
    "server_path" : "selenium-server-standalone-2.53.1.jar",
    "log_path" : "",
    "host" : "127.0.0.1",
    "port" : 3001,
    "cli_args" : {
      "webdriver.chrome.driver" : "",
      "webdriver.ie.driver" : ""
    }
  },

  "test_settings" : {
    "default" : {
      "launch_url" : "http://localhost",
      "selenium_port"  : 3001,
      "selenium_host"  : "localhost",
      "silent": true,
      "screenshots" : {
        "enabled" : false,
        "path" : ""
      },
      "desiredCapabilities": {
        "browserName": "phantomjs",
        "javascriptEnabled": true,
        "acceptSslCerts": true,
        "phantomjs.binary.path" : "phantomjs.exe"       
      }
    }
  }
}

When I set browserName to "firefox", test passes, "OK. 3 assertions passed.". But when it is "phantomjs", one passes, one fails, and one error during execution: " TEST FAILURE: 1 error during execution, 1 assertions failed, 1 passed. (3.511s)".

With errors:

  1. Timed out while waiting for element to be present for 1000 milliseconds. - expected "visible" but got: "not found"

  2. ERROR: Unable to locate element: "input[type=text]" using: css selector

I start server manually.

I tested with latest version of phantomjs (2.1.1) and with 1.9.8

EDIT:

Selenium server also reports this error when using phantomjs:

WebElementLocator - _handleLocateCommand - Element(s) NOT Found: GAVE UP.

Upvotes: 1

Views: 927

Answers (2)

Rohit Vatta
Rohit Vatta

Reputation: 31

Yes, resizing the browser window may solve this problem. We are running our test suite in Phantom JS and we have set this in code when we initialize the browser window:

client.maximizeWindow();

Upvotes: 0

Shri
Shri

Reputation: 81

I encoutnered something like this in the past and observed that Default size of phantomjs browser was very small. Could you please try resizing browser and check what happens.

Something like below,

module.exports = { 'Demo test Google' : function (browser) { browser .url('http://www.google.com') .resizeWindow(1000, 800); .waitForElementVisible('body', 1000) .setValue('input[type=text]', 'nightwatch') .waitForElementVisible('button[name=btnG]', 1000) .click('button[name=btnG]') .pause(1000) .assert.containsText('#main', 'Night Watch') .end(); } };

Upvotes: 2

Related Questions