我看到其他人一直有这个问题,我觉得有点不同于任何人,因为它只是在我运行一个完整的套件时出现(像测试20那样失败)。
如果我运行单个测试或只进行一些测试,代码就可以正常运行。
否则,我得到以下堆栈跟踪:
org.openqa.selenium.remote.UnreachableBrowserException: Error communicating with the remote browser. It may have died.
我在本地运行我的代码,我不知道它为什么不尝试创建新的浏览器。相反,它只是跳过所有剩余的黄瓜步骤。
有谁知道为什么会这样?
以下是我的设置和拆卸步骤:
public class Setup_Teardown_steps extends BaseStepClass {
@Before("@selenium")
public void selenium_before_step(Scenario scenario) { //Function responsible for setting the scenario start and global end condition
//Selenium setup
//initialize_selenium_elements();
driver = WebDriver_Singleton.getNewDriver(); //Creates a new Webdriver instance.
driver.manage().window().setSize(new Dimension(1280, 800));
startTime = System.currentTimeMillis();
testData.ClearTestData(); //Clears saved test data
testData.current_scenario = scenario;
}
/**
* After each scenario Hook (except report scenarios) - public cause it has to be.
*/
@After("@selenium")
public void selenium_after_step(Scenario scenario) throws IOException {
endTime = System.currentTimeMillis();
scenario.write("Run time = " + (endTime - startTime)/1000 + " seconds");
if (scenario.isFailed()){
String html_link = driver.getCurrentUrl();
scenario.write("\n");
scenario.write("URL = " + html_link);
try {
byte[] screenshot = ((TakesScreenshot) driver).getScreenshotAs(OutputType.BYTES);
scenario.embed(screenshot, "image/png");
} catch (WebDriverException wde) {
System.err.println(wde.getMessage());
} catch (ClassCastException cce) {
cce.printStackTrace();
}
}
driver.close(); //Clears cache and cookies
testData.ClearTestData(); //Clears saved test data
}
}
//WebDriver_Singleton Function below
private static WebDriver create_driver(){
if (driver != null){
driver.close();
}
assign_base_urls();
String browser = System.getProperty("browser") == null ? "ff" : System.getProperty("browser");
switch(browser.toLowerCase()){
case "ff":
case "firefox":
case "mozilla":
driver = new FirefoxDriver();
break;
case "ie":
case "internet explorer":
case "internet_explorer":
driver = new InternetExplorerDriver();
break;
case "chrome":
case "google":
driver = new ChromeDriver();
break;
default:
System.out.println("Defaulting to Firefox browser");
driver = new FirefoxDriver();
}
driver.manage().timeouts().implicitlyWait(implicit_wait_timeouts, TimeUnit.SECONDS);
driver.manage().timeouts().pageLoadTimeout(page_load_timeouts, TimeUnit.SECONDS);
driver.manage().timeouts().setScriptTimeout(script_timeouts, TimeUnit.SECONDS);
return driver;
}
答案 0 :(得分:0)
我查看了堆栈跟踪,很难找到,但jenkins服务器的内存不足。