selenium - DOM Element behaving differently in Nightwatch -
i have following nightwatch test:
edititem.js
var config = require('../../nightwatch.conf.js'); module.exports = { 'open login screen': function (browser) { browser .url('http://localhost:8080') .waitforelementvisible('body', 1000) .waitforelementvisible('#sign-up') }, 'open sign-up screen': function (browser) { browser .click('#sign-up') .waitforelementvisible('#name') }, 'sign up': function (browser) { browser .setvalue('#name', 'nuper') .setvalue('#last-name', 'app') .setvalue('#email', 'tests@nuper.club') .setvalue('#password', 'rnd12;ran') .setvalue('#confirm-password', 'rnd12;ran') .click('#create-user') }, 'load list screen': function (browser) { browser .waitforelementvisible('#mylist-add-item') }, 'insert new item': function (browser) { browser .setvalue('#mylist-add-item', 'caparra') .click('.autocomplete-suggestions > div:nth-child(1)') }, 'load edit item screen': function (browser) { browser .assert.visible('.selected-tag') }, 'load correct measurement unit default units': function (browser) { browser .assert.containstext('.selected-tag','gramas') } };
whenever testing behavior manually, on load edit item screen following view:
but, during automated tests, <span class=selected-tag>
never loaded , whole dropdown containing <div>
remains empty, failing test:
nightwatch.conf.js
file reference:
const screenshot_path = "./screenshots/"; const binpath = './node_modules/nightwatch/bin/'; // use nightwatch.conf.js file can include comments , helper functions module.exports = { "src_folders": [ "test/e2e"// storing nightwatch e2e tests ], "output_folder": "./reports", // reports (test outcome) output nightwatch "selenium": { // downloaded selenium-download module (see readme) "start_process": true, // tells nightwatch start/stop selenium process "server_path": "./node_modules/nightwatch/bin/selenium.jar", "host": "127.0.0.1", "port": 4444, // standard selenium port "cli_args": { // chromedriver downloaded selenium-download (see readme) "webdriver.chrome.driver" : "./node_modules/nightwatch/bin/chromedriver" } }, "test_settings": { "default": { "screenshots": { "enabled": true, // if want keep screenshots "path": screenshot_path // save screenshots here }, "globals": { "waitforconditiontimeout": 5000 // internet slow wait. }, "desiredcapabilities": { // use chrome default browser tests "browsername": "chrome" } }, "chrome": { "desiredcapabilities": { "browsername": "chrome", "javascriptenabled": true // turn off test progressive enhancement } } } } /** * selenium-download it's name suggests; * downloads (or updates) version of selenium (& chromedriver) * on localhost used nightwatch. /the following code checks existence of `selenium.jar` before trying run our tests. */ require('fs').stat(binpath + 'selenium.jar', function (err, stat) { // got it? if (err || !stat || stat.size < 1) { require('selenium-download').ensure(binpath, function(error) { if (error) throw new error(error); // no point continuing exit! console.log('✔ selenium & chromedriver downloaded to:', binpath); }); } }); function padleft (count) { // theregister.co.uk/2016/03/23/npm_left_pad_chaos/ return count < 10 ? '0' + count : count.tostring(); } var filecount = 0; // "global" screenshot file count /** * default save screenshots root of project though * there screenshots path in config object above! ... need * function returns correct path storing our screenshots. * while we're @ it, adding meta-data filename, * platform/browser test run , test (file) name. */ function imgpath (browser) { var = browser.options.desiredcapabilities; var meta = [a.platform]; meta.push(a.browsername ? a.browsername : 'any'); meta.push(a.version ? a.version : 'any'); meta.push(a.name); // test filename exists. var metadata = meta.join('~').tolowercase().replace(/ /g, ''); return screenshot_path + metadata + '_' + padleft(filecount++) + '_'; } module.exports.imgpath = imgpath; module.exports.screenshot_path = screenshot_path;
why system behave differently during integration tests? or, more specifically, how can fix this?
kudos dwyl/learn nightwatch github repo got working me :)
Comments
Post a Comment