Index: ssts-selenium-test/src/test/java/test_4_1/tools/Utils.java =================================================================== diff -u -r17606 -r17618 --- ssts-selenium-test/src/test/java/test_4_1/tools/Utils.java (.../Utils.java) (revision 17606) +++ ssts-selenium-test/src/test/java/test_4_1/tools/Utils.java (.../Utils.java) (revision 17618) @@ -72,23 +72,27 @@ /** 打开浏览器 */ public static void webDriverInit() { -// System.setProperty("webdriver.ie.driver", -// "C:\\IEDriverServer_Win32_3.3.0\\IEDriverServer.exe"); + // System.setProperty("webdriver.ie.driver", + // "C:\\IEDriverServer_Win32_3.3.0\\IEDriverServer.exe"); // 解决ie兼容模式设置导致无法启动问题 DesiredCapabilities ieCapabilities = DesiredCapabilities .internetExplorer(); ieCapabilities .setCapability( InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true); -// driver = new InternetExplorerDriver(ieCapabilities); - + + ieCapabilities.setCapability("applicationName", "cherry"); + ieCapabilities.setCapability("version", "11.0"); + // driver = new InternetExplorerDriver(ieCapabilities); + try { - driver = new RemoteWebDriver(new URL("http://home.forgon.com:4444/wd/hub"), ieCapabilities); + driver = new RemoteWebDriver(new URL( + "http://192.168.2.18:4444/wd/hub"), ieCapabilities); } catch (MalformedURLException e) { e.printStackTrace(); } - + driver.get(Utils.settings.get("服务器地址").toString()); } @@ -120,7 +124,6 @@ yesbutton.click(); } - /** 获取当前日期 */ public static void DateTime() { Date now = new Date(); @@ -163,7 +166,7 @@ int attempts = 0; while (attempts < 2) { try { - driver.findElement(by).click(); + retryingFind(by).click(); result = true; break; } catch (StaleElementReferenceException e) { @@ -185,10 +188,11 @@ while (attempts < 3) { try { Wait wait = new FluentWait(Utils.driver) - .withTimeout(30, TimeUnit.SECONDS) - .pollingEvery(3, TimeUnit.SECONDS) + .withTimeout(5000, TimeUnit.MILLISECONDS) + .pollingEvery(100, TimeUnit.MILLISECONDS) .ignoring(NoSuchElementException.class); element = driver.findElement(by); + Thread.sleep(1000); break; } catch (Exception e) { } @@ -209,7 +213,7 @@ int attempts = 0; while (attempts < 2) { try { - WebElement table = driver.findElement(by); + WebElement table = retryingFind(by); if (table != null) { WebElement cell = getFirstCellOfTable(table); cell.click(); @@ -241,7 +245,7 @@ int attempts = 0; while (attempts < 2) { try { - WebElement table = driver.findElement(by); + WebElement table = retryingFind(by); if (table != null) { WebElement cell = getforthCellOfTable(table); if (cell != null) { @@ -357,8 +361,7 @@ try { // 主窗口 String mainWindow = Utils.driver.getWindowHandle(); - Utils.driver.findElement(By.id("recyclingRecordTouchScreen")) - .click(); + Utils.retryingFind(By.id("recyclingRecordTouchScreen")).click(); Utils.waitForWindowToOpen(2, 5000); // 遍历所有窗口,切换至新窗口(回收清点窗口) Set handles = Utils.driver.getWindowHandles(); @@ -390,22 +393,23 @@ public static void tryToCloseWarningWindow() { try { Wait wait = new FluentWait(Utils.driver) - .withTimeout(30, TimeUnit.SECONDS) - .pollingEvery(3, TimeUnit.SECONDS) + .withTimeout(5000, TimeUnit.MILLISECONDS) + .pollingEvery(100, TimeUnit.MILLISECONDS) .ignoring(NoSuchElementException.class); // 等待对话框弹出 Thread.sleep(1000); // wait.until(ExpectedConditions // .visibilityOfElementLocated(By // .xpath("//div/span[contains(text(),'满意度调查表')]"))); // 获取警告信息对话框的集合 - List closeBtns = wait.until(new Function>() { - public List apply(WebDriver driver) { - return driver.findElements(By - .cssSelector("div[class='x-tool x-tool-close']")); - } - }); - + List closeBtns = wait + .until(new Function>() { + public List apply(WebDriver driver) { + return driver.findElements(By + .cssSelector("div[class='x-tool x-tool-close']")); + } + }); + if (closeBtns.size() == 0) { return; } @@ -429,8 +433,7 @@ try { // 回收窗口 String mainWindow = Utils.driver.getWindowHandle(); - Utils.driver.findElement(By.cssSelector("div[class='add2']")) - .click(); + Utils.retryingFind(By.cssSelector("div[class='add2']")).click(); Utils.waitForWindowToOpen(3, 5000); // 遍历所有窗口,切换至新窗口(自定义入筐窗口) Set handles = Utils.driver.getWindowHandles(); @@ -465,15 +468,15 @@ */ public static void waitUntilUrlChange(final String newUrl, int seconds) { Wait wait = new FluentWait(Utils.driver) - .withTimeout(30, TimeUnit.SECONDS) - .pollingEvery(3, TimeUnit.SECONDS) + .withTimeout(5000, TimeUnit.MILLISECONDS) + .pollingEvery(100, TimeUnit.MILLISECONDS) .ignoring(NoSuchElementException.class); wait.until(new Function() { public Boolean apply(WebDriver d) { return d.getCurrentUrl().startsWith(newUrl); } }); - + } /** @@ -496,24 +499,25 @@ // 获取Selenium自动化测试的配置信息 - InputStream instream1 = Utils.class.getClassLoader().getResourceAsStream( - "test_4_1/config/" + projectName + "/config.js"); - + InputStream instream1 = Utils.class.getClassLoader() + .getResourceAsStream( + "test_4_1/config/" + projectName + "/config.js"); + Scanner scanner1 = new Scanner(instream1); String content = scanner1.useDelimiter("\\Z").next(); - + content = content.replaceAll("var sstsConfig = ", ""); jsonObj = mapper.readValue(content, JSONObject.class); - -// String testConfigFilename = seleniumTestConfigPath + "/" -// + projectName + "/settings.json"; - - - InputStream instream2 = Utils.class.getClassLoader().getResourceAsStream( - "test_4_1/config/" + projectName + "/settings.json"); + // String testConfigFilename = seleniumTestConfigPath + "/" + // + projectName + "/settings.json"; + InputStream instream2 = Utils.class + .getClassLoader() + .getResourceAsStream( + "test_4_1/config/" + projectName + "/settings.json"); + Scanner scanner2 = new Scanner(instream2); String testConfigFileContent = scanner2.useDelimiter("\\Z").next(); @@ -522,13 +526,12 @@ // 合并到jsonObj jsonObj.putAll(jsonObjTestSettings); - + instream1.close(); scanner1.close(); - + instream2.close(); scanner2.close(); - } catch (IOException e) { e.printStackTrace();