这是我的Selenium 浏览器测试类(派生类,但应该不难理解它在做什么)。当我运行测试用例时,所有交互都按预期发生。但最终测试用例的结果显示失败。
package dmswebui.CR;
import org.infineta.webui.selenium4j.MainTestCase;
public class TestLogin extends MainTestCase {
@Override
public void setUp() throws Exception {
super.setUp();
startSeleniumSession("ChromeDriver", "http://192.168.8.207/");
}
public void testMethod() throws Exception {
session().open("/");
session().type("name=user","admin");
session().type("name=password","infineta123");
session().click("id=btnLogin-button"); session().waitForPageToLoad("30000");
session().click("id=btnUserLogout-button");
session().click("id=yui-gen0-button"); session().waitForPageToLoad("30000");
}
public void tearDown() throws Exception {
super.tearDown();
closeSeleniumSession();
}
}
我得到的错误是:
Testcase: testMethod took 13.939 sec
Caused an ERROR
Error communicating with the remote browser. It may have died.
最佳答案
这通常发生在您尝试多次关闭同一个 webdriver 实例时。你知道 super.teardown()
发生了什么吗?当我检查 selenium4j 源代码时,它扩展了 junit Testcase。您的 super.tearDown
将调用 jUnitTeardown 并在调用 closeSeleniumSession()
之前终止浏览器实例。
您可以将 closeSeleniumSession()
放在 super.tearDown()
之前。
关于java - Selenium WebDriver : Error communicating with the remote browser. 它可能已经死了,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11058948/