简体   繁体   English

有没有办法检查Web控制台(例如FireBug)是否以java语言打开?

[英]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.

相关问题 在Azure中使用Java以任何方式打开自定义入站防火墙端口,例如8077 - Open custom inbound firewall ports e.g. 8077 by any way using java in azure 有没有办法将Java方法标记(例如注释)为永不返回? - Is there a way to mark (e.g. annotate) a Java method as never returning? 以非完全编译语言(例如Java)存储在堆还是堆栈中的变量? - Variables stored on heap vs. stack in a non-fully compiled language (e.g. Java)? 如何使用eclipse中编写的Java代码在远程桌面中导航(例如,打开Mozilla)? - How can i navigate (e.g. open Mozilla) in a Remote Desktop by using java code written in eclipse? Java中有没有一种方法可以基于java.lang基本类型(例如String)构建自定义类型? - Is there a way in Java to build custom types based on java.lang base Types (e.g. String)? 有没有办法在Tomcat中以编程方式将SSL设置为必需(例如,不通过web.xml)? - Is there a way to programmatically set SSL as mandatory in Tomcat (e.g. not via web.xml)? Java LibGDX 如何检查精灵是否站在特定的瓷砖上,例如门? - Java LibGDX how to check if sprite stands on specific tile e.g. door? 使用Java检查Git存储库是私有的还是公共的(例如GitHub) - Check if Git repository is private or public (e.g. for GitHub) using Java 一个Java线程如何检查另一个Java线程的状态,例如另一个是否被阻止? - How can one Java thread check the state of another one, e.g. whether the other one is blocked? 使用嵌入式Web浏览器(例如Chrome)作为Java桌面应用程序的GUI工具包? - Use embedded web browser (e.g. Chrome) as GUI toolkit for Java desktop applications?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM