Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to not load Nightwatch APIs while launching browser. #4358

Merged
merged 2 commits into from
Jan 16, 2025

Conversation

garg3133
Copy link
Member

If we try to quit and relaunch the browser in between a testsuite while using Cucumber runner or Nightwatch's programmatic APIs, we cannot do so because of the below error:

TypeError: Error while loading the API commands: the command .acceptAlert() is already defined.
    at CommandLoader.validateMethod (/Users/priyansh/Projects/nightwatch/lib/api/_loaders/_command-loader.js:54:19)
    at CommandLoader.define (/Users/priyansh/Projects/nightwatch/lib/api/_loaders/_base-loader.js:330:10)
    at ApiLoader.addCommandDefinitionSync (/Users/priyansh/Projects/nightwatch/lib/api/index.js:338:8)
    at /Users/priyansh/Projects/nightwatch/lib/api/index.js:457:20
    at /Users/priyansh/Projects/nightwatch/lib/utils/index.js:407:7
    at Array.forEach (<anonymous>)
    at Utils.readFolderRecursively (/Users/priyansh/Projects/nightwatch/lib/utils/index.js:391:15)
    at ApiLoader.__loadCommandsSync (/Users/priyansh/Projects/nightwatch/lib/api/index.js:456:13)
    at /Users/priyansh/Projects/nightwatch/lib/api/index.js:312:14
    at Array.forEach (<anonymous>) {
  displayed: false,
  detailedErr: 'Source: /Users/priyansh/Projects/nightwatch/lib/api/protocol/acceptAlert.js',
  showTrace: false
}

This happens because whenever we try to call .launchBrowser() on the existing client, it tries to load all the Nightwatch APIs onto the client again. But since the APIs are already loaded, Nightwatch throws the above error.

To solve this, we've added a new param (loadNightwatchApis) that can be passed to the .launchBrowser() set as false if we don't want to load the APIs while launching the browser.

Fixes: #4357

Usage

// load Nightwatch APIs like normal
client.launchBrowser(); // no need to pass any param
client.launchBrowser({loadNightwatchApis: true});

// do not load Nightwatch APIs while launching the browser
client.launchBrowser({loadNightwatchApis: false});

Copy link

Status

  • ❌ No modified files found in the types directory.
    Please make sure to include types for any changes you have made. Thank you!.

@garg3133 garg3133 merged commit e4e259d into nightwatchjs:main Jan 16, 2025
17 checks passed
@garg3133 garg3133 deleted the close-reopen-browser-cucumber branch January 16, 2025 12:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Can't open a browser after closing it in cucumber step implementation without initialising a new client
1 participant