[英]Is there a way to check if web console (e.g. FireBug) is open in java language?
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. 我正在使用Selenium WebDriver 2创建自动化测试用例。我的代码已设置好,以便在Selenium WebDriver打开FireFox时自动打开FireBug。 A few seconds later I ask Selenium to close it again.
几秒钟后,我要求Selenium再次关闭它。 For some reason, if I don't do this, sometimes FireBug won't be available to me at a later stage.
出于某种原因,如果我不这样做,有时FireBug将在稍后阶段无法使用。
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. 我的问题:当我使用TestNG套件运行我的测试套件时,一些测试用例最终会打开FireBug但不会再次关闭它。 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.
然后,“关闭FireBug代码”被误用来打开FireBug而不是关闭它。
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. 出于这个原因,我想检查FireBug是否打开,如果是,我想关闭它。
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: 关闭FireBug的代码:
Actions action = new Actions(driver);
action.sendKeys(Keys.F12).build().perform();
I can find ways to do this in javascript, using window.console. 我可以使用window.console找到在javascript中执行此操作的方法。 Is there any way to do something similar in java?
有没有办法在java中做类似的事情?
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. 当DevTools未对接时它不起作用。 However, works with the Chrome/Safari/Firefox DevTools and Firebug.
但是,适用于Chrome / Safari / Firefox DevTools和Firebug。
The answer is by Sindre Sorhus and has been taken from here! 答案是Sindre Sorhus,已经从这里开始了! Find out whether Chrome console is open
了解Chrome控制台是否已打开
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.