1

I am creating automated test cases with Selenium WebDriver 2. My code is set up, so that FireBug automatically is opened when Selenium WebDriver opens FireFox. A few seconds later I ask Selenium to close it again. For some reason, if I don't do this, sometimes FireBug won't be available to me at a later stage.

My problem: When I use the TestNG suite to run my test suite, some of the test cases end up opening FireBug but not closing it again. My guess is, that this is due to existing browser windows already being open. The "close FireBug code" is then misused to open FireBug instead of closing it.

For this reason, I would like to make a check to see if FireBug is open, and if so, I would like to close it.

Opening code:

String firebugPath = TO_Constant.fireBug();
FirefoxProfile profile = new FirefoxProfile();       
profile.addExtension(new File(firebugPath));
profile.setPreference("extensions.firebug.showFirstRunPage", false);
profile.setPreference("extensions.firebug.allPagesActivation", "on");
driver = new FirefoxDriver(profile);

Code to close FireBug:

Actions action = new Actions(driver);
action.sendKeys(Keys.F12).build().perform();

I can find ways to do this in javascript, using window.console. Is there any way to do something similar in java?

1 Answers1

0
console.log('is DevTools open?', window.devtools.open);

You can also listen to an event:

window.addEventListener('devtoolschange', function (e) {
    console.log('is DevTools open?', e.detail.open);
});

It doesn't work when DevTools is undocked. However, works with the Chrome/Safari/Firefox DevTools and Firebug.

The answer is by Sindre Sorhus and has been taken from here! Find out whether Chrome console is open

Community
  • 1
  • 1
Xwris Stoixeia
  • 1,831
  • 21
  • 22