selenium icon indicating copy to clipboard operation
selenium copied to clipboard

[🐛 Bug]: running Builder() always opens 4 instances of Firefox

Open AdamDSherman opened this issue 1 year ago • 2 comments

What happened?

I hope this is the right place to post this.

I am running Selenium Webdriver 4.14.0 on Node 20.4.0 (on MacOS) and using Firefox as my browser.

All is well but for one thing: when I run new Builder() 4 instances of Firefox open.

How can we reproduce the issue?

I have stripped back my code to the following fundamentals. Running this code reproduces the issue for me.


const { Builder, By, until, Key } = require('selenium-webdriver');
const firefox = require('selenium-webdriver/firefox');

let options = new firefox.Options();
    options.setPreference('geo.enabled', false);
    options.setAlertBehavior('dismiss');

const driver = new Builder()
    .forBrowser('firefox')
    .setFirefoxOptions(options)
    .build();


### Relevant log output

```shell
NA

Operating System

macOS Monterey 12.4

Selenium version

4.14.0

What are the browser(s) and version(s) where you see this issue?

Firefox 104.0 (64-bit)

What are the browser driver(s) and version(s) where you see this issue?

Geckdriver 0.34.0

Are you using Selenium Grid?

NA

AdamDSherman avatar Jan 31 '24 06:01 AdamDSherman

@AdamDSherman, thank you for creating this issue. We will troubleshoot it as soon as we can.


Info for maintainers

Triage this issue by using labels.

If information is missing, add a helpful comment and then I-issue-template label.

If the issue is a question, add the I-question label.

If the issue is valid but there is no time to troubleshoot it, consider adding the help wanted label.

If the issue requires changes or fixes from an external project (e.g., ChromeDriver, GeckoDriver, MSEdgeDriver, W3C), add the applicable G-* label, and it will provide the correct link and auto-close the issue.

After troubleshooting the issue, please add the R-awaiting answer label.

Thank you!

github-actions[bot] avatar Jan 31 '24 06:01 github-actions[bot]

I used version 4.17.0 to reproduce this, but I could not.

I notice you are not quitting the browser. Maybe that is the issue.

This is the code I used:

const { Builder, By, until, Key } = require('selenium-webdriver');
const firefox = require('selenium-webdriver/firefox');

let options = new firefox.Options();
    options.setPreference('geo.enabled', false);
    options.setAlertBehavior('dismiss');

const driver = new Builder()
    .forBrowser('firefox')
    .setFirefoxOptions(options)
    .build();

driver.quit();

diemol avatar Feb 05 '24 13:02 diemol

I will close this for now, as we have not gotten any updates. I can reopen as soon as more information is provided.

diemol avatar Feb 28 '24 17:02 diemol

Hi, sorry @diemol,

I did find the issue. It was not to do with Selenium but with Cucumber JS which amalgamated all my tests into 1 JS file. Hence, if I had 4 test .js files that had

const driver = new Builder()
    .forBrowser('firefox')
    .build();

in them, they would run 4 times and Firefox would open 4 times.

The work around is to put the driver build for each in your tests first Cucumber functions, eg:

Do this:

Given('I am on the About Us page', async function () {
    this.driver = new Builder()
        .forBrowser('firefox')
        .build();
        this.driver.wait(until.elementLocated(By.className('h1')));

    await this.driver.get('https://www.mywebsite.com/about');
});

Don't do this:

const driver = new Builder()
    .forBrowser('firefox')
    .build();

Given('I am on the About Us page', async function () {
        driver.wait(until.elementLocated(By.className('h1')));
        await driver.get('https://www.mywebsite.com/about');
});

Alternatively, I'm sure there is a way to implement

const driver = new Builder()
    .forBrowser('firefox')
    .build();

once for all test files, but I have not done that yet.

AdamDSherman avatar Feb 29 '24 00:02 AdamDSherman

@AdamDSherman, thank you for creating this issue. We will troubleshoot it as soon as we can.


Info for maintainers

Triage this issue by using labels.

If information is missing, add a helpful comment and then I-issue-template label.

If the issue is a question, add the I-question label.

If the issue is valid but there is no time to troubleshoot it, consider adding the help wanted label.

If the issue requires changes or fixes from an external project (e.g., ChromeDriver, GeckoDriver, MSEdgeDriver, W3C), add the applicable G-* label, and it will provide the correct link and auto-close the issue.

After troubleshooting the issue, please add the R-awaiting answer label.

Thank you!

github-actions[bot] avatar Mar 08 '24 23:03 github-actions[bot]

This issue has been automatically locked since there has not been any recent activity since it was closed. Please open a new issue for related bugs.

github-actions[bot] avatar May 17 '24 22:05 github-actions[bot]