Index: ssts-web/src/test/java/test/forgon/disinfectsystem/selenium/tools/Utils.java =================================================================== diff -u -r18772 -r18785 --- ssts-web/src/test/java/test/forgon/disinfectsystem/selenium/tools/Utils.java (.../Utils.java) (revision 18772) +++ ssts-web/src/test/java/test/forgon/disinfectsystem/selenium/tools/Utils.java (.../Utils.java) (revision 18785) @@ -22,22 +22,21 @@ import org.openqa.selenium.StaleElementReferenceException; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; -import org.openqa.selenium.remote.RemoteWebDriver; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.chrome.ChromeOptions; import org.openqa.selenium.ie.InternetExplorerDriver; import org.openqa.selenium.remote.DesiredCapabilities; +import org.openqa.selenium.remote.RemoteWebDriver; import org.openqa.selenium.support.ui.ExpectedCondition; import org.openqa.selenium.support.ui.Wait; import org.openqa.selenium.support.ui.WebDriverWait; - -import com.fasterxml.jackson.core.JsonParser.Feature; -import com.fasterxml.jackson.databind.ObjectMapper; - import org.testng.Assert; import test.forgon.disinfectsystem.selenium.factory.WaitFactory; +import com.fasterxml.jackson.core.JsonParser.Feature; +import com.fasterxml.jackson.databind.ObjectMapper; + /** * @author Terry Date : 2016-02-29 23:17 工具类 */ @@ -50,6 +49,20 @@ public static final String ACTION_SWITCH_TO_FRAME = "switchToFrame"; public static final String ACTION_CLEAR = "clear"; public static final String ACTION_NOP = "nop"; + + /* + * 本地运行测试用例 + */ + public static final int RUN_MODE_LOCAL = 0; + /* + * 远程运行测试用例 + */ + public static final int RUN_MODE_REMOTE = 1; + + /* + * 测试用例的运行模式 + */ + private static int testRunMode = RUN_MODE_REMOTE; // public static Wait wait; @@ -180,14 +193,20 @@ ieCapabilities.setCapability("version", browserVersion); try { - String seleniumHubURL = - Utils.settings.get("seleniumHubURL").toString(); - driver = new RemoteWebDriver(new URL( seleniumHubURL), - ieCapabilities); -// driver = new InternetExplorerDriver(ieCapabilities); -// String cap = ((InternetExplorerDriver) driver).getCapabilities() -// .toString(); -// System.out.println("my cap = " + cap); + String seleniumHubURL = Utils.settings.get("seleniumHubURL") + .toString(); + + // 远程运行 + if (testRunMode == RUN_MODE_REMOTE) { + driver = new RemoteWebDriver(new URL(seleniumHubURL), + ieCapabilities); + } else { + driver = new InternetExplorerDriver(ieCapabilities); + String cap = ((InternetExplorerDriver) driver) + .getCapabilities().toString(); + System.out.println("my cap = " + cap); + } + if (cleanTime == 0) { Utils.driver.manage().deleteAllCookies(); Utils.waitPageLoaded(); @@ -933,6 +952,7 @@ // 先等待页面加载完成,然后再等待Ext4.onReady执行完 waitPageLoaded(); // 先等待portalPage.js的Ext4.onReady执行完 + // windowOnLoaded是自定义的JS变量 waitPageLoaded("return windowOnLoaded == false ? true : false;", 10000, 350); Wait wait = WaitFactory.createDefaultWait(); @@ -941,17 +961,46 @@ // .visibilityOfElementLocated(By // .xpath("//div/span[contains(text(),'满意度调查表')]"))); // 获取警告信息对话框的集合 + By warningWindows = By + .cssSelector("div[class='x-tool x-tool-close']"); + List closeBtns = wait.until(driver -> { // waitPageLoaded(); - return driver.findElements(By - .cssSelector("div[class='x-tool x-tool-close']")); + return driver.findElements(warningWindows); }); int size = closeBtns.size(); - System.out.println("closeBtns.size() = " + size); + logger.info("closeBtns.size() = " + size); // 逐个关闭对话框,先关闭最外层的。如果没关闭最外层的,里面的对话框无法关闭 + for (int i = size - 1; i >= 0; i--) { - closeBtns.get(i).click(); + + // 尝试关闭对话框,关闭后判断是否真正关闭,如果没有关闭,则再次循环点击关闭按钮 + try { + int count = 5; + for (int j = count; j > 0; j--) { + closeBtns.get(i).click(); + Thread.sleep(200); + List btns = driver + .findElements(warningWindows); + if (btns != null && (btns.size() - i) >= 1) { + continue; + } + else{ + j = 0; + } + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + List btns = driver + .findElements(warningWindows); + if (btns != null){ + logger.info("after click close button, closeBtns.size() = " + btns.size()); + } + } catch (Exception e) { e.printStackTrace(); Assert.fail(e.getMessage());