selenium - Invalid session ID when using Page Object on nightwatch cucumber -
update: problem solved, check comment
i trying convert use test page object , have following pg.js:
var mycommands ={ security:function(username){ this.click('@logon') .waitforelementvisible('@id',20000) .click('@id') .setvalue('@id',username) .click('@device') }, password:function(username){ console.log(this) return this.usexpath() .navigate() .assert.elementpresent('@logon', 20000) .click('@logon') .waitforelementvisible('@id',20000) .click('@id') .setvalue('@id',username) .click('@password') .waitforelementvisible('//input[@name="answer"]', 20000); } }; module.exports={ url : 'https://mywebsite', commands :[mycommands], elements:{ logon:{ locatestrategy: 'xpath', selector:'//a[@title="log on"]' }, id:{ locatestrategy: 'xpath', selector:'//input[@name="userid"]' }, device:{ locatestrategy: 'xpath', selector:'//a[text() = "login pin"]' }, password:{ locatestrategy: 'xpath', selector:'//a[text() = "login passwords"]' } } };
from console.log(this), can see session id , context null :
and in test.js ,i have 2 lines:
var logon=client.page.pg() .... logon.password(username)
when run test, shows
error: creating screenshot not successful. response was: { status: -1, value: { error: 'invalid session id', message: 'no active session id null', stacktrace: '' }, errorstatus: 6, error: '' }
my question why session null? , if there problem how set page object in either pg.js or test.js.
do have nightwatch.conf.js file set show page objects structure?
i using nightwatch-cucumber page object model , structure follows:
//nightwatch.conf.js const seleniumserver = require('selenium-server') const phantomjs = require('phantomjs-prebuilt') const chromedriver = require('chromedriver') require('nightwatch-cucumber')({ cucumberargs: ['--require', 'hooks.js', '--require', 'features/step_definitions', '--format', 'pretty', '--format', 'json:reports/cucumber.json', 'features'] }) module.exports = { output_folder: 'reports', live_output: false, disable_colors: false, page_objects_path: 'pages', test_workers: false, selenium: { start_process: true, server_path: seleniumserver.path, log_path: '', host: '127.0.0.1', port: 4444 }, test_settings: { default: { launch_url: 'whatevertheurlis.com', selenium_port: 4444, selenium_host: '127.0.0.1', globals: { base_url: 'baseurl.com' }, desiredcapabilities: { browsername: 'chrome', javascriptenabled: true, acceptsslcerts: true }, selenium: { cli_args: { 'webdriver.chrome.driver': chromedriver.path } }, screenshots: { enabled : true, on_failure : true, path : 'screenshots/default' } } } }
this loginpage:
//pages/loginpage.js module.exports = { url: function() { return this.api.globals.base_url + '/#/login'; }, elements: { body: 'body', error: 'div.error', header: '.header-title', emailinput: '#field_email', passwordinput: '#field_password', submitbutton: '.btn-success' }, commands: [{ goto: function() { return this.navigate() .waitforelementvisible('@body', 3000); } }] }
and loginsteps:
//features/step_definitions/loginsteps.js const { client } = require('nightwatch-cucumber') const { definesupportcode } = require('cucumber') const loginpage = client.page.loginpage(); const navbar = client.page.navbar(); const resetpasswordpage = client.page.resetpasswordpage(); const shared = client.page.shared(); definesupportcode(({ given, then, when }) => { given(/^i go login page$/, () => { return loginpage .goto(); }) })
we using different method of doing helps see layout of tests.
Comments
Post a Comment