You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When I call the this.api.elementIdElements() in a custom command, called from the sync function, on the second call it returns the NightwatchAPI object instead of the actual result.
So, the first call of result = this.api.elementIdElements() returns the array of elements, but when doing the same call a second time - it suddenly returns the NigthwatchAPI object instead!
If I do the same from the async function - all work well.
See the test code below on how to reproduce.
Steps to reproduce
Create a custom Nigthwatch command that calls the function this.api.elementIdElements() multiple times.
Call this command from a Nightwatch test from an async function - all will work well.
Call this command from a Nightwatch test from a sync function - the second call will return the NigthwatchAPI object instead of the expected result.
Sample test
// A test file to call the custom command: Nightwatch/Tests/test1.jsmodule.exports={'Test thFindNested in async mode': async(browser)=>{awaitbrowser.url('http://google.com');constresult=awaitbrowser.thFindNested();console.log('result',result);},'Test thFindNested in sync mode': (browser)=>{browser.url('http://google.com').thFindNested(result=>{console.log('result',result);});},}// A custom command file: Nightwatch/Commands/thFindNested.jsmodule.exports=classthFindNested{asynccommand(callback){constel1=awaitthis.api.findElement('body');console.log('el1',el1);constel1Id=el1.getId();console.log('el1Id',el1Id);constels2=awaitthis.api.elementIdElements(el1Id,'css selector','div')console.log('els2',els2);constel2=els2[0];console.log('el2',el2);// The function elementIdElements() returns elements without the getId() method.constel2Id=Object.values(el2)[0];console.log('el2Id',el2Id);constels3=awaitthis.api.elementIdElements(el2Id,'css selector','div')console.log('els3',els3);constel3=els3[0];console.log('el3',el3);// The function elementIdElements() returns elements without the getId() method.constel3Id=Object.values(el3)[0];console.log('el3Id',el3Id);if(typeofcallback==='function'){constself=this;constresult={status: 0,value: el3Id}callback.call(self,result);}}};
module.exports={// An array of folders (excluding subfolders) where your tests are located;// if this is not specified, the test source must be passed as the second argument to the test runner.src_folders: [],// See https://nightwatchjs.org/guide/concepts/page-object-model.htmlpage_objects_path: ['node_modules/nightwatch/examples/pages/'],// See https://nightwatchjs.org/guide/extending-nightwatch/adding-custom-commands.htmlcustom_commands_path: ['node_modules/nightwatch/examples/custom-commands/'],// See https://nightwatchjs.org/guide/extending-nightwatch/adding-custom-assertions.htmlcustom_assertions_path: '',// See https://nightwatchjs.org/guide/extending-nightwatch/adding-plugins.htmlplugins: [],// See https://nightwatchjs.org/guide/concepts/test-globals.html#external-test-globalsglobals_path : '',webdriver: {},test_workers: {enabled: true,workers: 'auto'},test_settings: {default: {disable_error_log: false,launch_url: 'https://nightwatchjs.org',screenshots: {enabled: false,path: 'screens',on_failure: true},desiredCapabilities: {browserName : 'firefox'},webdriver: {start_process: true,server_path: ''}},firefox: {desiredCapabilities : {browserName : 'firefox',acceptInsecureCerts: true,'moz:firefoxOptions': {args: [// '-headless',// '-verbose']}},webdriver: {start_process: true,server_path: '',cli_args: [// very verbose geckodriver logs// '-vv']}},chrome: {desiredCapabilities : {browserName : 'chrome','goog:chromeOptions' : {// More info on Chromedriver: https://sites.google.com/a/chromium.org/chromedriver///// w3c:false tells Chromedriver to run using the legacy JSONWire protocol (not required in Chrome 78)w3c: true,args: [//'--no-sandbox',//'--ignore-certificate-errors',//'--allow-insecure-localhost',//'--headless']}},webdriver: {start_process: true,server_path: '',cli_args: [// --verbose]}},edge: {desiredCapabilities : {browserName : 'MicrosoftEdge','ms:edgeOptions' : {w3c: true,// More info on EdgeDriver: https://docs.microsoft.com/en-us/microsoft-edge/webdriver-chromium/capabilities-edge-optionsargs: [//'--headless']}},webdriver: {start_process: true,// Download msedgedriver from https://docs.microsoft.com/en-us/microsoft-edge/webdriver-chromium/// and set the location below:server_path: '',cli_args: [// --verbose]}},//////////////////////////////////////////////////////////////////////////////////// Configuration for when using cucumber-js (https://cucumber.io) |// |// It uses the bundled examples inside the nightwatch examples folder; feel free |// to adapt this to your own project needs |//////////////////////////////////////////////////////////////////////////////////'cucumber-js': {src_folders: ['examples/cucumber-js/features/step_definitions'],test_runner: {// set cucumber as the runnertype: 'cucumber',// define cucumber specific optionsoptions: {//set the feature pathfeature_path: 'node_modules/nightwatch/examples/cucumber-js/*/*.feature',// start the webdriver session automatically (enabled by default)// auto_start_session: true// use parallel execution in Cucumber// workers: 2 // set number of workers to use (can also be defined in the cli as --workers=2}}},//////////////////////////////////////////////////////////////////////////////////// Configuration for when using the browserstack.com cloud service |// |// Please set the username and access key by setting the environment variables: |// - BROWSERSTACK_USERNAME |// - BROWSERSTACK_ACCESS_KEY |// .env files are supported |//////////////////////////////////////////////////////////////////////////////////browserstack: {selenium: {host: 'hub.browserstack.com',port: 443},// More info on configuring capabilities can be found on:// https://www.browserstack.com/automate/capabilities?tag=selenium-4desiredCapabilities: {'bstack:options' : {userName: '${BROWSERSTACK_USERNAME}',accessKey: '${BROWSERSTACK_ACCESS_KEY}',}},disable_error_log: true,webdriver: {timeout_options: {timeout: 15000,retry_attempts: 3},keep_alive: true,start_process: false}},'browserstack.local': {extends: 'browserstack',desiredCapabilities: {'browserstack.local': true}},'browserstack.chrome': {extends: 'browserstack',desiredCapabilities: {browserName: 'chrome',chromeOptions : {w3c: true}}},'browserstack.firefox': {extends: 'browserstack',desiredCapabilities: {browserName: 'firefox'}},'browserstack.ie': {extends: 'browserstack',desiredCapabilities: {browserName: 'internet explorer',browserVersion: '11.0'}},'browserstack.safari': {extends: 'browserstack',desiredCapabilities: {browserName: 'safari'}},'browserstack.local_chrome': {extends: 'browserstack.local',desiredCapabilities: {browserName: 'chrome'}},'browserstack.local_firefox': {extends: 'browserstack.local',desiredCapabilities: {browserName: 'firefox'}},//////////////////////////////////////////////////////////////////////////////////// Configuration for when using the SauceLabs cloud service |// |// Please set the username and access key by setting the environment variables: |// - SAUCE_USERNAME |// - SAUCE_ACCESS_KEY |//////////////////////////////////////////////////////////////////////////////////saucelabs: {selenium: {host: 'ondemand.saucelabs.com',port: 443},// More info on configuring capabilities can be found on:// https://docs.saucelabs.com/dev/test-configuration-options/desiredCapabilities: {'sauce:options' : {username: '${SAUCE_USERNAME}',accessKey: '${SAUCE_ACCESS_KEY}',screenResolution: '1280x1024'// https://docs.saucelabs.com/dev/cli/sauce-connect-proxy/#--region// region: 'us-west-1'// https://docs.saucelabs.com/dev/test-configuration-options/#tunnelidentifier// parentTunnel: '',// tunnelIdentifier: '',}},disable_error_log: false,webdriver: {start_process: false}},'saucelabs.chrome': {extends: 'saucelabs',desiredCapabilities: {browserName: 'chrome',browserVersion: 'latest',javascriptEnabled: true,acceptSslCerts: true,timeZone: 'London',chromeOptions : {w3c: true}}},'saucelabs.firefox': {extends: 'saucelabs',desiredCapabilities: {browserName: 'firefox',browserVersion: 'latest',javascriptEnabled: true,acceptSslCerts: true,timeZone: 'London'}},//////////////////////////////////////////////////////////////////////////////////// Configuration for when using the Selenium service, either locally or remote, |// like Selenium Grid |//////////////////////////////////////////////////////////////////////////////////selenium_server: {// Selenium Server is running locally and is managed by Nightwatch// Install the NPM package @nightwatch/selenium-server or download the selenium server jar file from https://github.com/SeleniumHQ/selenium/releases/, e.g.: selenium-server-4.1.1.jarselenium: {start_process: true,port: 4444,server_path: '',// Leave empty if @nightwatch/selenium-server is installedcommand: 'standalone',// Selenium 4 onlycli_args: {//'webdriver.gecko.driver': '',//'webdriver.chrome.driver': ''}},webdriver: {start_process: false,default_path_prefix: '/wd/hub'}},'selenium.chrome': {extends: 'selenium_server',desiredCapabilities: {browserName: 'chrome',chromeOptions : {w3c: true}}},'selenium.firefox': {extends: 'selenium_server',desiredCapabilities: {browserName: 'firefox','moz:firefoxOptions': {args: [// '-headless',// '-verbose']}}}}};
Nightwatch.js Version
3.8.0
Node Version
18.20.4
Browser
Chrome 101.0.4951.41
Operating System
Ubuntu Linux, the test run in the docker container
Additional Information
No response
The text was updated successfully, but these errors were encountered:
The interesting thing is that if I do this inside the Nightwath test directly - it works well! The issue appears only if I put it into the Nightwatch command and call it from the sync function.
Example of the working tests without the custom function:
module.exports={'Test thFindNested in async mode': async(browser)=>{awaitbrowser.url('http://google.com');constel1=awaitbrowser.findElement('body');constel1Id=el1.getId();console.log('el1Id',el1Id);constels2=awaitbrowser.elementIdElements(el1Id,'css selector','div')constel2=els2[0];console.log('el2',el2);constel2Id=Object.values(el2)[0];console.log('el2Id',el2Id);constels3=awaitbrowser.elementIdElements(el2Id,'css selector','div')console.log('els3',els3);constel3=els3[0];console.log('el3',el3);constel3Id=Object.values(el3)[0];console.log('el3Id',el3Id);},'Test thFindNested in sync mode': (browser)=>{browser.url('http://google.com').findElement('body',(result)=>{constel1=result.value;constel1Id=el1.getId();console.log('el1Id',el1Id);browser.elementIdElements(el1Id,'css selector','div',function(result){constels2=result.value;constel2=els2[0];console.log('el2',el2);constel2Id=Object.values(el2)[0];console.log('el2Id',el2Id);browser.elementIdElements(el2Id,'css selector','div',function(result){constels3=result.value;console.log('els3',els3);constel3=els3[0];console.log('el3',el3);constel3Id=Object.values(el3)[0];console.log('el3Id',el3Id);});});}).end();},};
Description of the bug/issue
When I call the
this.api.elementIdElements()
in a custom command, called from thesync
function, on the second call it returns theNightwatchAPI
object instead of the actual result.So, the first call of
result = this.api.elementIdElements()
returns the array of elements, but when doing the same call a second time - it suddenly returns theNigthwatchAPI
object instead!If I do the same from the
async
function - all work well.See the test code below on how to reproduce.
Steps to reproduce
this.api.elementIdElements()
multiple times.NigthwatchAPI
object instead of the expected result.Sample test
Command to run
Verbose Output
Nightwatch Configuration
Nightwatch.js Version
3.8.0
Node Version
18.20.4
Browser
Chrome 101.0.4951.41
Operating System
Ubuntu Linux, the test run in the docker container
Additional Information
No response
The text was updated successfully, but these errors were encountered: