我目前正在开发一项功能,即在编辑帖子时自动保存内容。该功能预计即使在浏览器崩溃时也能正常工作。我的问题是有一种方法可以自动化(selenium 或类似的)并测试浏览器崩溃。
最佳答案
我会注入(inject)异常以使窗口崩溃并在新窗口中工作以检查恢复情况。这不完全是浏览器崩溃,而是关闭:
WebDriver driver = new FirefoxDriver();
driver.get("https://www.google.co.uk");
// crash the window
((JavascriptExecutor)driver).executeScript(
"window.open();" +
"window.stop();" +
"setTimeout(function(){" +
"document.open();" +
"document.write('<script>throw new Error();</script>');" +
"document.close();},0);");
// close the window
Object[] handles = driver.getWindowHandles().toArray();
driver.close();
// switch to the new window and reload the page
driver.switchTo().window(handles[1].toString());
driver.get("https://www.google.co.uk");
关于selenium - 如何复制浏览器崩溃以进行自动化测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36033271/