人工学院进游戏后电脑总是白屏屏

1528人阅读
& & & WebDriver启动的时候很容易无限挂起,直到外围框架设定的超时时间达到而退出运行,给测试运行带来很大的困扰。而实际上WebDriver有一组timeout的设置方法,启动时的挂起属于页面加载的范畴,所以可以考虑用timeouts().pageLoadTimeout()来重新启动一个有效的实例来执行测试。
* Description: catch page load timeout Exception and restart a new session.&/BR&
* 内容描述:通过页面跳转是否超时来测试WebDriver启动时是否发生挂死异常。
* @param driver RemoteWebDriver object.
* @param browser the browser mode.
* @param testUrl the url used to navigate by the driver.get method.
* @throws Exception
private boolean hasLoadPageSucceeded(RemoteWebDriver driver, String browser, String testUrl) throws Exception {
driver.manage().timeouts().pageLoadTimeout(5, TimeUnit.SECONDS);
driver.get(testUrl);
} catch (TimeoutException te) {
LOG.error(&******************本次启动WebDriver异常挂起******************&);
setBuildEnvChoice(browser);
driverObjectInitalize();
* Description: catch page load timeout Exception and restart a new session.&/BR&
* 内容描述:循环一定次数测试WebDriver启动是否挂死。
* @param driver RemoteWebDriver object.
* @param browser the browser mode.
* @param testUrl the url used to navigate by the driver.get method.
* @param repeatTimes retry times.
* @throws Exception
private void driverStatusTest(RemoteWebDriver driver, String browser, String testUrl, int repeatTimes) throws Exception {
int index = 0;
boolean suspended =
while (index & repeatTimes && suspended){
suspended = !hasLoadPageSucceeded(driver, browser, testUrl);
if (index == repeatTimes && suspended){
throw new RuntimeException(&can not start webdriver successfully, it's suspended!&);
* Description: start webdirver after capability settings completed.&/BR&
* 内容描述:在做好配置之后创建WebDriver实例。
* @throws Exception
private String driverObjectInitalize() throws Exception{
if (USE_DRIVERSERVER){//是否使用IEDirverServer
driver = new RemoteWebDriver(service.getUrl(), capability);
return service.getUrl().toString();
URL url = new URL(&http://localhost:& + server.getPort() + &/wd/hub&);
driver = new RemoteWebDriver(url, capability);
return &http://localhost:& + server.getPort() + &/wd/hub&;
* Description: start webdirver&/BR&
* 内容描述:启动WebDriver实例。
* @param browser the browser mode
* @throws RuntimeException
protected void startWebDriver(String browser) {
setBrowserMode(browser);
String url = driverObjectInitalize();//about:blank is useless on some machines.
driverStatusTest(driver, browser, url, 2);
driver.manage().timeouts().implicitlyWait(maxWaitfor, TimeUnit.SECONDS);
driver.manage().timeouts().setScriptTimeout(maxWaitfor, TimeUnit.SECONDS);
driver.manage().timeouts().pageLoadTimeout(maxLoadTime, TimeUnit.SECONDS);
} catch (Exception e) {
LOG.error(e);
throw new RuntimeException(e);
* Description: set browser mode on local machines: do not close browsers already opened.&/BR&
* 内容描述:选择在本机执行,有人工干预,无需杀掉浏览器进程。
* @throws Exception
private void setBrowserMode(String browser) throws Exception{
if (browser.toLowerCase().contains(&ie&) || browser.toLowerCase().contains(&internetexplorer&)) {
capability = DesiredCapabilities.internetExplorer();
} else if (browser.toLowerCase().contains(&ff&) || browser.toLowerCase().contains(&firefox&)) {
capability = DesiredCapabilities.firefox();
} else if (browser.toLowerCase().contains(&chrome&)) {
capability = DesiredCapabilities.chrome();
} else if (browser.toLowerCase().contains(&safari&)) {
capability = DesiredCapabilities.safari();
} else if (browser.toLowerCase().contains(&opera&)) {
capability = DesiredCapabilities.opera();
} else if (browser.toLowerCase().contains(&htmlunit&)) {
capability = DesiredCapabilities.htmlUnit();
throw new IllegalArgumentException(&you are using wrong mode of browser paltform!&);
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:42260次
排名:千里之外
原创:21篇
评论:28条
(1)(1)(1)(2)(2)(2)(1)(6)(8)

我要回帖

更多关于 电脑总是白屏 的文章

 

随机推荐