EzDevInfo.com

nightwatch

Automated testing and continous integration framework based on node.js and selenium webdriver Nightwatch.js | Node.js powered End-to-End testing framework browser automated testing done easy. write efficient and straightforward javascript end-to-end tests in node.js which run against a selenium server.

Save console messages for debugging in nightwatch.js

How can I get all console messages on nightwatch.js debugging?

At phantom it's possible to use page.onError handler. Can I do the same with nightwatch?

I know about window.onerror but is there way to save all console messages?

Can anyone share working config / code ?


Source: (StackOverflow)

How to run a single test in nightwatch

I have test:

module.exports = {
  'Test 1':function(){},
  'Test 2':function(){}
  'Test 3':function(){}
}

I want to run Test 3 and not all the others. How can I do so?


Source: (StackOverflow)

Advertisements

Right Click with Nightwatch

I am trying to test my GUI with Nightwatch. I can not seem to find how to simulate a right click. I went through the API Reference page(http://nightwatchjs.org/api) and searched everywhere. Am I missing something here? Because I believe that right clicking should be one of the most basic functionalities.


Source: (StackOverflow)

Unable to execute nightwatch tests on chrome using Linux

Here's the bit in question from my nightwatch.json file :

 "selenium" : {
   "start_process" : true,
   "server_path" : "lib/selenium-server-standalone.jar",
   "log_path" : "test_logs"
 },

 "test_settings" : {
   "jenkins" : {
     "launch_url" : "url not disclosed",
     "selenium_port"  : 4444,
     "selenium_host"  : "jenkins.undisclosed-cloud.com",
     "cli_args" : {
       "webdriver.chrome.driver" : "/usr/local/bin/chromedriver"
     },
     "desiredCapabilities": {
       "browserName": "chrome",
       "javascriptEnabled": true,
       "acceptSslCerts": true,
       "platform" : "LINUX"
     }
   }
 }

If I change the browserName to firefox then the test runs fine in the specified linux server, which is running on a DOCKER CONTAINER.

But when i choose chrome, i am getting the error:

Connection refused! Is selenium server started?

I've seen this error before on my local machine and managed to fix it by adding chromedriver to the path. I thought it would be the same issue on this linux server but it did not resolve it. I went on to the linux box and verified I can start the chromedriver directly in

"/usr/local/bin/chromedriver" 

By the way I have verified I'm on 64-bit linux machine and the symlinks are all set.

Linux version: Linux 3.11.0-26-generic  |  v2.43.1  |  r5163bce

ERROR LOG AFTER RUNNING TEST WITH --verbose

INFO Request: POST /wd/hub/session 
 - data:  {"desiredCapabilities":    {"browserName":"chrome","javascriptEnabled":true,"acceptSslCerts":true,"platform":    "LINUX","name":"Free Resource Download Test"}} 
 - headers:  {"Content-Type":"application/json; charset=utf-8","Content-    Length":151}
ERROR Response 500 POST /wd/hub/session{ status: 13,
  sessionId: null,
  value: 
   { message: 'chrome not reachable\n 

Source: (StackOverflow)

What are some best practices for structuring e2e tests?

I'm a bit confused as to the best way to structure end to end tests.

Most tests tests that I write depend on other tests.

i.e

  • User needs to log in
  • User needs to create Foo
  • User can now create Bar
  • Bar needs to exist, in order to edit it obviously.

How would you structure your tests to take this into account?


Source: (StackOverflow)

When starting Nightwatch with Grunt, the website server is not started

I am using Nightwatch.js to run system tests for a website. I want to automate the tests by running them via grunt. My Gruntfile contains these lines:

...
var nightwatch = require('nightwatch');
nightwatch.initGrunt(grunt);
...
nightwatch: {
    options: {
        standalone: true,
        test_settings: {
            "default": {
                "launch_url": "http://localhost",
                "selenium_port": 4444,
                "selenium_host": "localhost",
                "silent": true,
                "screenshots": {
                    "enabled": false,
                    "path": ""
                },
                "desiredCapabilities": {
                    "browserName": "firefox",
                    "javascriptEnabled": true,
                    "acceptSslCerts": true
                }
            }
        },
        "chrome" : {
            "desiredCapabilities": {
                "browserName": "chrome",
                "javascriptEnabled": true,
                "acceptSslCerts": true
            }
        }
    }
},
...
grunt.loadNpmTasks('grunt-nightwatch');

When I run nightwatch in the terminal with grunt nightwatch it starts the selenium server and tries to run the tests, but the website server is not being started. Why? The browser is being opened, but it just says, that a connection is not possible. I googled about it but I could not find anything. What do I have to add to make grunt run the server?

This is my nightwatch.json file:

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

"selenium" : {
    "start_process" : false,
    "server_path" : "",
    "log_path" : "",
    "host" : "127.0.0.1",
    "port" : 4444,
    "cli_args" : {
        "webdriver.chrome.driver" : "",
        "webdriver.ie.driver" : ""
    }
},

"test_settings" : {
    "default" : {
        "launch_url" : "http://localhost",
        "selenium_port"  : 4444,
        "selenium_host"  : "localhost",
        "silent": true,
        "screenshots" : {
            "enabled" : false,
            "path" : ""
      },
      "desiredCapabilities": {
          "browserName": "firefox",
          "javascriptEnabled": true,
          "acceptSslCerts": true
      }
},

"chrome" : {
    "desiredCapabilities": {
        "browserName": "chrome",
        "javascriptEnabled": true,
        "acceptSslCerts": true
    }
}
}

Source: (StackOverflow)

Assert text value of list of webelements using nightwatch.js

I am new to using nightwatch.js. I want to get a list of elements and verify text value of each and every element with a given string. I have tried :

function iter(elems) {
      elems.value.forEach(function(element) {
        client.elementIdValue(element.ELEMENT)
      })
    };
    client.elements('css selector', 'button.my-button.to-iterate', iter);

For another stackoverflow question But what I am using right now is

waitForElementPresent('elementcss', 5000).assert.containsText('elementcss','Hello')

and it is returning me the output

Warn: WaitForElement found 5 elements for selector "elementcss". Only the first one will be checked.

So I want that it should verify text value of each and every element of list.


Source: (StackOverflow)

Set proxy in nightwatch.js

I'm writing Integration Tests using nightwatch.js in a Node.js application. For a particular test case, I want nightwatch to connect via a proxy. What would be the right way to do this? I can't find anything from its official documentation, or from its Google Group.

The Selenium documentation suggests setting it on the webdriver instance as described here. I'm not sure how to do this via nightwatch.


Source: (StackOverflow)

Unable to iterate elements using elements in nightwatch

I am trying to iterate through elements, I have tried several things pointed out in many spaces. Here is my code

printTotalPriceInEachCard: function(client) {
    client.elements('css selector','.price-container',function(result){
        result.value.forEach(function(element){
            console.log(element);
        })
    });
}

When I call this function nightwatch does not identify elements function

TypeError: Cannot read property 'elements' of undefined at Object.pageAction.printTotalPriceInEachCard (/Users/shjain/NightsWatch/pageobjects/searchListPage.js:16:15)

I am not sure if this is incorrect way of calling elements.


Source: (StackOverflow)

Why won't my Nightwatch test work with selenium?

I am using nightwatch.js and selenium to test my site on a remote server. My nightwatch test works with my site on my local machine. When I check the tests into the remote server using SVN it fails. I get this Error message but I am not sure what it means

 Error retrieving a new session from the selenium server:
 { state: 'unhandled error',
sessionId: null,
hCode: 548388426,
value:
    { localizedMessage: 'Unable to connect to host 127.0.0.1 on port 7055  after 45000 ms. Firefox console output:\nedSave.extensions.json\tDEBUG\tStarting write\r\n1429642526359\taddons.manager\tDEBUG\tshutdown\r\n1429642526360\taddons.manager\tDEBUG\tCalling shutdown blocker for XPIProvider\r\n1429642526360\taddons.xpi\tDEBUG\tshutdown\r\n1429642526360\taddons.xpi-utils\tDEBUG\tshutdown\r\n1429642526361\taddons.manager\tDEBUG\tCalling shutdown blocker for LightweightThemeManager\r\n1429642526361\taddons.manager\tDEBUG\tCalling shutdown blocker for GMPProvider\r\n1429642526362\taddons.manager\t
DEBUG\tCalling shutdown blocker for PluginProvider\r\n1429642526439\tDeferredSave.extensions.json\tDEBUG\tWrite succeeded\r\n1429642526440\taddons.xpi
-utils\tDEBUG\tXPI Database saved, setting schema version preference to 16\r\n1429642526440\taddons.xpi\tDEBUG\tNotifying XPI shutdown observers\r\n14
29642526443\taddons.manager\tDEBUG\tAsync provider shutdown done\r\n1429642526618\taddons.manager\tDEBUG\tLoaded provider scope for resource://gre/mod
ules/addons/XPIProvider.jsm: ["XPIProvider"]\r\n1429642526620\taddons.manager\tDEBUG\tLoaded provider scope for resource://gre/modules/LightweightThem
eManager.jsm: ["LightweightThemeManager"]\r\n1429642526623\taddons.xpi\tDEBUG\tstartup\r\n1429642526624\taddons.xpi\tINFO\tMapping fxdriver@googlecode
.com to C:\\Users\\Thuy\\AppData\\Local\\Temp\\2\\anonymous1373176543885734633webdriver-profile\\extensions\\fxdriver@googlecode.com\r\n1429642526624\
taddons.xpi\tDEBUG\tIgnoring file entry whose name is not a valid add-on ID: C:\\Users\\Thuy\\AppData\\Local\\Temp\\2\\anonymous1373176543885734633web
driver-profile\\extensions\\webdriver-staging\r\n1429642526625\taddons.xpi\tINFO\tMapping {972ce4c6-7e08-4474-a285-3208198ce6fd} to C:\\Program Files
(x86)\\Mozilla Firefox\\browser\\extensions\\{972ce4c6-7e08-4474-a285-3208198ce6fd}\r\n1429642526625\taddons.xpi\tDEBUG\tSkipping unavailable install
location app-system-share\r\n1429642526625\taddons.xpi\tDEBUG\tSkipping unavailable install location app-system-local\r\n1429642526626\taddons.xpi\tDE
BUG\tcheckForChanges\r\n1429642526626\taddons.xpi\tDEBUG\tLoaded add-on state from prefs: {"app-profile":{"fxdriver@googlecode.com":{"d":"C:\\\\Users\
\\\Thuy\\\\AppData\\\\Local\\\\Temp\\\\2\\\\anonymous1373176543885734633webdriver-profile\\\\extensions\\\\fxdriver@googlecode.com","e":true,"v":"2.44
.0","st":1429642525598,"mt":1429642525568}},"app-global":{"{972ce4c6-7e08-4474-a285-3208198ce6fd}":{"d":"C:\\\\Program Files (x86)\\\\Mozilla Firefox\
\\\browser\\\\extensions\\\\{972ce4c6-7e08-4474-a285-3208198ce6fd}","e":true,"v":"37.0.1","st":1428245410334,"mt":1428245410318}}}\r\n1429642526627\ta
ddons.xpi\tDEBUG\tgetModTime: Recursive scan of fxdriver@googlecode.com\r\n1429642526634\taddons.xpi\tDEBUG\tgetModTime: Recursive scan of {972ce4c6-7
e08-4474-a285-3208198ce6fd}\r\n1429642526634\taddons.xpi\tDEBUG\tgetInstallState changed: false, state: {"app-profile":{"fxdriver@googlecode.com":{"d"
:"C:\\\\Users\\\\Thuy\\\\AppData\\\\Local\\\\Temp\\\\2\\\\anonymous1373176543885734633webdriver-profile\\\\extensions\\\\fxdriver@googlecode.com","e":
true,"v":"2.44.0","st":1429642525598,"mt":1429642525568}},"app-global":{"{972ce4c6-7e08-4474-a285-3208198ce6fd}":{"d":"C:\\\\Program Files (x86)\\\\Mo
zilla Firefox\\\\browser\\\\extensions\\\\{972ce4c6-7e08-4474-a285-3208198ce6fd}","e":true,"v":"37.0.1","st":1428245410334,"mt":1428245410318}}}\r\n14
29642526635\taddons.xpi\tDEBUG\tNo changes found\r\n1429642526639\taddons.manager\tDEBUG\tRegistering shutdown blocker for XPIProvider\r\n142964252663
9\taddons.manager\tDEBUG\tRegistering shutdown blocker for LightweightThemeManager\r\n1429642526641\taddons.manager\tDEBUG\tRegistering shutdown block
er for GMPProvider\r\n1429642526641\taddons.manager\tDEBUG\tRegistering shutdown blocker for PluginProvider\r\nJavaScript error: file:///C:/Users/Thuy
/AppData/Local/Temp/2/anonymous1373176543885734633webdriver-profile/extensions/fxdriver@googlecode.com/components/driver-component.js, line 11487: Typ
eError: this.server_ is undefined\r\nJavaScript error: chrome://fxdriver/content/server.js, line 38: NS_ERROR_XPC_CI_RETURNED_FAILURE: Component retur
ned failure code: 0x80570015 (NS_ERROR_XPC_CI_RETURNED_FAILURE) [nsIJSCID.createInstance]\r\n*** Blocklist::_preloadBlocklistFile: blocklist is disabl
ed\r\n1429642527403\taddons.manager\tDEBUG\tRegistering shutdown blocker for <unnamed-provider>\r\n',

it continues for a while but it appears to be the same text repeated


Source: (StackOverflow)

Data driven test in Nightwatch.js

How to create data driven test using Nightwatch.js? I am using data.js file as global. The content is:

module.exports={
    username:'xyz@gmail.com',
    password:'12345',
    urls: {
        login: 'http://www.asdf.com'
    }
};

Source: (StackOverflow)

Can I create reusable test steps in nightwatch.js?

I am looking to create reusable components within my nightwatch.js tests.

ie. login to the web app, logout of the web app

What is the best method / pattern for creating these steps in a reusable way?


Source: (StackOverflow)

Using XPath in Nightwatch.js commands to select Polymer Element's child?

I'm trying to use XPath selectors to target children of Polymer custom elements through nightwatch.js commands. For example:

browser
.getAttribute('//th-compare-chart/svg', 'width', function(svgWidth) {

...
})

Yields:

ERROR: Unable to locate element: "//th-compare-balance-chart/svg" using: css selector

The documentation for getAttribute, and other commands, states that you can provide a string selector of either a css selector or xpath: http://nightwatchjs.org/api#getAttribute

Yet I have not been able to get any xpath selector to work. Does anyone know how to get this to work?

### Update

This is the XML markup, using HTML 5 doctype. The element is built using polymer and according to the inspector is nested inside a strange "#shadow-root". Perhaps it's not possible to access elements inside the shadow-root?

<th-compare-balance-chart class="element ">
  #shadow-root
    <core-style>...</core-style>
    <svg id="chart">...</svg>
  #shadow-root
</th-compare-balance-chart>

Source: (StackOverflow)

nightwatch selenium command "elements" returns error about first parameter, even when I pass in a css selector or xpath expression

I'm using nightwatch with selenium for automation testing. I'm trying to use the selenium command 'elements' which takes a css selector or xpath as the first parameter, but keep getting the following error :

Error while running elements command: Please provide any of the following using strings as the first parameter: class name, css selector, id, name, link text, partial link text, tag name or xpath

My use is like this:

module.exports = {
    "My test" : function (browser) {
       ...  
       // want to get all the input elements from the document
       browser.elements('input','name', function(els){
       // of xpath like this
       browser.elements('//input','name', function(els){
       });
    }

}

Any ideas why I'm getting this error? Thanks!


Source: (StackOverflow)

File Upload Testing in Nightwatch.js

I'd like to reopen the question posed here and here about testing file uploading within Nightwatch.js which uses selenium.

Both links have the recommended solution of setting the value of the file input element as the url. In my use case, I've been unable to get this to work. Even setting the value tag manually, outside of nightwatch, of the input where type="file", does not change the url. I've tried this on Chrome, Firefox, and IE10, within the dev tools.

An alternative solution I've looked at was trying to emulate the entire file upload process keystrokes. This would follow the path of clicking the file upload button, typing the path, and typing enter. This would be done through the .click and .key methods. However, you lose focus of the actual file upload window, which delays the keystrokes until that window is closed. Other developers have seemed to be able to fix this solution directly in selenium using the .findElement and .sendKeys methods in java, but I could not figure out how to do this within javascript and nightwatch itself.

Any ideas?

// My test
      module.exports = {
      "Standard File Upload" : function (browser) {
        browser
          .url("http://localhost:3000")
          .waitForElementVisible('body', 1000)
          .waitForElementVisible('input[type="file"]', 1000)
          .setValue('input[type="file"]','http://localhost:3000/testfile.txt')
          .click('#submit')
          .pause(1000)
          .assert.containsText('h3', 'File Uploaded Successfully')
          .end();
      }
    };

// http://localhost:3000/testfile.txt was tested manually in the file upload window and worked successfully

<!-- My input tag --> 
<input id="fileUpload" type="file" name="textfile"/>

Source: (StackOverflow)