【发布时间】:2016-08-02 23:15:36
【问题描述】:
我有一个应用程序自动化框架,其中应用程序实际上被视为浏览器。现在,这是我的功能。
通常它总是启动登录页面。现在我的测试用例要求我先使应用程序崩溃,然后重新启动它,这将指向一些“错误报告”页面,而不是这次启动登录页面。
如果我从命令提示符执行此操作,则此功能可以正常工作,因为每个命令提示符窗口都是一个会话,所以基本上它会在同一个会话中崩溃并重新打开。
现在这在通过 webdriver 运行时不起作用,因为每次 @BeforeClass 运行时,它都会创建应用程序的一个新实例,因此 i 再次定向到登录页面而不是定向到错误页面。
任何有关如何在同一会话中实现应用程序崩溃和重新启动的建议都会有很大帮助。我只提供了调用驱动程序的一小部分代码。
protected void setupChromeRemoteDriver(String hubUrl, String platformName) throws IOException {
Platform platform = (platformName != null) ? Platform.valueOf(platformName) : Platform.ANY;
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setBrowserName("chrome");
capabilities.setPlatform(platform);
capabilities.setCapability(CapabilityType.TAKES_SCREENSHOT, true);
Set<Cookie> cookies = driver.manage().getCookies();
for(Cookie cookie : cookies){
driver.manage().addCookie(cookie);
}
driver = new CustomRemoteWebDriver(new URL(hubUrl), capabilities);
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(Constants.ELEMENT_TIMEOUT_SECONDS, TimeUnit.SECONDS);
}
CrashApplication.java
public void crashUTAApp(){
String filePath = Constants.CRASHAPP_BATCHFILE_LOCATION;
try{
Process process = Runtime.getRuntime().exec(filePath);
if(null != process && process.waitFor() == 0 && process.exitValue() == 0){
Reporter.log("App Crashed");
}else{
Reporter.log("Failed to crash app");
}
}catch(Exception e){
e.printStackTrace();
}
}
【问题讨论】: