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

Issue: No browser object is available for BeforeAll hooks when using Cucumber #4228

Open
SDETQATestAutomation opened this issue Jul 3, 2024 · 0 comments

Comments

@SDETQATestAutomation
Copy link

Description

I am encountering an issue where the browser object is not accessible within the BeforeAll or Before hooks when using Nightwatch.js with Cucumber.

Suggested solution

Scenario:

In my test setup, I need to fetch the user agent from the browser and update it before starting the test execution. To achieve this, I intend to use the execute command to retrieve the user agent. However, since the browser object is not available in the BeforeAll or Before hooks, I am unable to perform this operation.

Steps to Reproduce:

Set up a Nightwatch.js project with Cucumber integration.
Try to access the browser object within a BeforeAll or Before hook.
Attempt to use the execute command to fetch the user agent.
Expected Behavior:

The browser object should be accessible within the BeforeAll or Before hooks, allowing the use of the execute command to retrieve and update the user agent before the test execution begins.

Actual Behavior:

The browser object is not available in the BeforeAll or Before hooks, preventing the execution of commands that require the browser object.

Example Code:

const { BeforeAll, Before } = require('cucumber');

BeforeAll(async function() {
// Attempt to access the browser object and execute a command
const userAgent = await browser.execute(function() {
return navigator.userAgent;
});

// Update the user agent or perform other necessary actions
console.log('User Agent:', userAgent);
});
Request:

It would be highly beneficial if the browser object could be made available in the BeforeAll or Before hooks when using Nightwatch.js with Cucumber. This would enable pre-test setup tasks such as fetching and updating the user agent or other necessary configurations.

Thank you for your attention to this issue. I look forward to any suggestions or potential fixes.

Alternatives / Workarounds

No response

Additional Information

#3038

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant