Index: ssts-selenium-test/src/test/java/test_4_1/tools/Utils.java =================================================================== diff -u -r17682 -r17686 --- ssts-selenium-test/src/test/java/test_4_1/tools/Utils.java (.../Utils.java) (revision 17682) +++ ssts-selenium-test/src/test/java/test_4_1/tools/Utils.java (.../Utils.java) (revision 17686) @@ -196,7 +196,13 @@ .pollingEvery(250, TimeUnit.MILLISECONDS) .ignoring(NoSuchElementException.class) .ignoring(StaleElementReferenceException.class); - element = driver.findElement(by); + element = wait + .until(new Function() { + public WebElement apply(WebDriver driver) { + return driver.findElement(by); + } + }); +// driver.findElement(by); Thread.sleep(1000); break; } catch (Exception e) { @@ -205,7 +211,71 @@ } return element; } + + public static WebElement retryingFindAndClick(By by) { + WebElement element = null; + int attempts = 0; + while (attempts < 3) { + try { + // Collection types = new HashSet(); + // types.add(NoSuchElementException.class); + // types.add(StaleElementReferenceException.class); + Wait wait = new FluentWait(Utils.driver) + .withTimeout(5000, TimeUnit.MILLISECONDS) + .pollingEvery(250, TimeUnit.MILLISECONDS) + .ignoring(NoSuchElementException.class) + .ignoring(StaleElementReferenceException.class); + element = wait + .until(new Function() { + public WebElement apply(WebDriver driver) { + return driver.findElement(by); + } + }); +// driver.findElement(by); +// Thread.sleep(1000); + + element.click(); + break; + } catch (Exception e) { + } + attempts++; + } + return element; + } + + public static WebElement retryingFindAndSendKeys(By by, String keys) { + WebElement element = null; + int attempts = 0; + while (attempts < 3) { + try { + + // Collection types = new HashSet(); + // types.add(NoSuchElementException.class); + // types.add(StaleElementReferenceException.class); + Wait wait = new FluentWait(Utils.driver) + .withTimeout(5000, TimeUnit.MILLISECONDS) + .pollingEvery(250, TimeUnit.MILLISECONDS) + .ignoring(NoSuchElementException.class) + .ignoring(StaleElementReferenceException.class); + element = wait + .until(new Function() { + public WebElement apply(WebDriver driver) { + return driver.findElement(by); + } + }); +// driver.findElement(by); +// Thread.sleep(1000); + + element.sendKeys(keys); + break; + } catch (Exception e) { + } + attempts++; + } + return element; + } + /** * 重复查找和click,html表格的第一个单元格对象 * Index: ssts-selenium-test/src/test/resources/test_4_1/config/all/settings.json =================================================================== diff -u -r17680 -r17686 --- ssts-selenium-test/src/test/resources/test_4_1/config/all/settings.json (.../settings.json) (revision 17680) +++ ssts-selenium-test/src/test/resources/test_4_1/config/all/settings.json (.../settings.json) (revision 17686) @@ -6,7 +6,7 @@ "系统管理员": {"工号": "admin","条码": "0100001008","姓名": "admin全名","密码": "1"}, "临床科室": {"条码": "310000120","科室编码": "testNeike","名称": "测试内科"}, "一级供应室器械包": {"固定条码": "","名称": "Test缝合包"}, - "一级供应室器械包1": {"固定条码": "","标识牌条码1": "010316310","标识牌条码2": "010316320","标识牌条码2id":"37","标识牌条码3": "010316330","标识牌条码3id":"38","名称": "Test开颅包"}, + "一级供应室器械包1": {"固定条码": "","标识牌条码1": "010316310","标识牌条码2": "010316320","标识牌条码2id":"1","标识牌条码3": "010316330","标识牌条码3id":"2","名称": "Test开颅包"}, "一级供应室器械包2": {"固定条码": "","名称": "Test开口包"}, "一级供应室器械包3": {"固定条码": "","名称": "Test开胸包"}, "一级供应室自定义器械包": {"名称": ""}, Index: ssts-selenium-test/src/test/java/test_4_1/Assemble.java =================================================================== diff -u -r17683 -r17686 --- ssts-selenium-test/src/test/java/test_4_1/Assemble.java (.../Assemble.java) (revision 17683) +++ ssts-selenium-test/src/test/java/test_4_1/Assemble.java (.../Assemble.java) (revision 17686) @@ -1,17 +1,23 @@ package test_4_1; +import java.util.NoSuchElementException; +import java.util.concurrent.TimeUnit; +import java.util.function.Function; + +import org.testng.annotations.AfterMethod; +import org.testng.annotations.Test; +import org.testng.annotations.BeforeMethod; +import org.testng.AssertJUnit; import org.openqa.selenium.Alert; import org.openqa.selenium.By; import org.openqa.selenium.JavascriptExecutor; import org.openqa.selenium.Keys; +import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.interactions.Actions; import org.openqa.selenium.support.ui.ExpectedConditions; -import org.openqa.selenium.support.ui.WebDriverWait; -import org.testng.AssertJUnit; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; +import org.openqa.selenium.support.ui.FluentWait; +import org.openqa.selenium.support.ui.Wait; import test_4_1.tools.Utils; @@ -111,10 +117,10 @@ Utils.retryingFind(By .xpath("//div/ul/li[contains(text(), '" + name + "')]"))).perform(); - - //Thread.sleep(1000); - - WebDriverWait wait = new WebDriverWait(Utils.driver, 10); + Wait wait = new FluentWait(Utils.driver) + .withTimeout(5000, TimeUnit.MILLISECONDS) + .pollingEvery(250, TimeUnit.MILLISECONDS) + .ignoring(NoSuchElementException.class); wait.until(ExpectedConditions.alertIsPresent()); Alert alertBox = Utils.driver.switchTo().alert(); @@ -163,12 +169,18 @@ click.click(Utils.retryingFind(By.id("packageType-triggerWrap"))) .perform(); - name = Utils.settings.getJSONObject("包装类型").getString("名称2"); + name = Utils.settings.getJSONObject("包装类型").getString("名称1"); click.click( Utils.retryingFind(By .xpath("//div/ul/li[contains(text(), '" + name + "')]"))).perform(); + Wait wait = new FluentWait(Utils.driver) + .withTimeout(5000, TimeUnit.MILLISECONDS) + .pollingEvery(250, TimeUnit.MILLISECONDS) + .ignoring(NoSuchElementException.class); + wait.until(ExpectedConditions.alertIsPresent()); + Alert alertBox = Utils.driver.switchTo().alert(); alertBox.accept(); Utils.retryingFind(By.id("save_print")).click(); @@ -230,7 +242,11 @@ Utils.retryingFind( By.xpath("//div/ul/li[contains(text(), '" + name + "')]")) .click(); - + Wait wait = new FluentWait(Utils.driver) + .withTimeout(5000, TimeUnit.MILLISECONDS) + .pollingEvery(250, TimeUnit.MILLISECONDS) + .ignoring(NoSuchElementException.class); + wait.until(ExpectedConditions.alertIsPresent()); Alert alertBox = Utils.driver.switchTo().alert(); alertBox.accept(); Utils.retryingFind(By.id("save_print")).click(); @@ -311,7 +327,11 @@ Utils.retryingFind( By.xpath("//div/ul/li[contains(text(), '" + name + "')]")) .click(); - + Wait wait = new FluentWait(Utils.driver) + .withTimeout(5000, TimeUnit.MILLISECONDS) + .pollingEvery(250, TimeUnit.MILLISECONDS) + .ignoring(NoSuchElementException.class); + wait.until(ExpectedConditions.alertIsPresent()); Alert alertBox = Utils.driver.switchTo().alert(); alertBox.accept(); Utils.retryingFind(By.id("save_print")).click(); @@ -434,22 +454,22 @@ a = Integer.valueOf(id).intValue(); boolean displayed = false; WebElement element = Utils.retryingFind(By - .cssSelector("tr[data-recordid='" + a + "']")); + .cssSelector("tr[data-recordindex='" + a + "']")); String b = null; if (element != null) { displayed = element.isDisplayed(); if (displayed) { Utils.retryingFind( - By.cssSelector("tr[data-recordid='" + a + "']")) + By.cssSelector("tr[data-recordindex='" + a + "']")) .click(); Utils.retryingFind( - By.cssSelector("tr[data-recordid='" + a + "']")) + By.cssSelector("tr[data-recordindex='" + a + "']")) .sendKeys(Keys.DOWN); id = Utils.settings.getJSONObject("一级供应室器械包1").getString( "标识牌条码3id"); a = Integer.valueOf(id).intValue(); Utils.retryingFind( - By.cssSelector("tr[data-recordid='" + a + "']")) + By.cssSelector("tr[data-recordindex='" + a + "']")) .click(); currentwindowhandle = Utils.driver.getWindowHandle(); Utils.driver.switchTo().window(currentwindowhandle); @@ -472,7 +492,7 @@ "标识牌条码3id"); a = Integer.valueOf(id).intValue(); WebElement ab = Utils.retryingFind(By - .cssSelector("tr[data-recordid='" + a + "']")); + .cssSelector("tr[data-recordindex='" + a + "']")); ab.click(); b = ab.getText(); b = b.trim(); @@ -567,11 +587,15 @@ .click(); name = Utils.settings.getJSONObject("包装类型") - .getString("名称2"); + .getString("名称1"); Utils.retryingFind( By.xpath("//div/ul/li[contains(text(), '" + name + "')]")).click(); - + Wait wait = new FluentWait(Utils.driver) + .withTimeout(5000, TimeUnit.MILLISECONDS) + .pollingEvery(250, TimeUnit.MILLISECONDS) + .ignoring(NoSuchElementException.class); + wait.until(ExpectedConditions.alertIsPresent()); Alert alertBox = Utils.driver.switchTo().alert(); alertBox.accept(); Utils.retryingFind(By.id("save_print")).click(); @@ -736,7 +760,11 @@ Utils.retryingFind(By .xpath("//div/ul/li[contains(text(), '" + name + "')]"))).perform(); - + Wait wait = new FluentWait(Utils.driver) + .withTimeout(5000, TimeUnit.MILLISECONDS) + .pollingEvery(250, TimeUnit.MILLISECONDS) + .ignoring(NoSuchElementException.class); + wait.until(ExpectedConditions.alertIsPresent()); Alert alertBox = Utils.driver.switchTo().alert(); alertBox.accept(); Utils.retryingFind(By.id("save_print")).click(); @@ -1054,7 +1082,11 @@ Utils.retryingFind(By .xpath("//div/ul/li[contains(text(), '" + name + "')]"))).perform(); - + Wait wait = new FluentWait(Utils.driver) + .withTimeout(5000, TimeUnit.MILLISECONDS) + .pollingEvery(250, TimeUnit.MILLISECONDS) + .ignoring(NoSuchElementException.class); + wait.until(ExpectedConditions.alertIsPresent()); Alert alertBox = Utils.driver.switchTo().alert(); alertBox.accept(); Utils.retryingFind(By.id("save_print")).click(); @@ -1204,7 +1236,11 @@ Utils.retryingFind(By .xpath("//div/ul/li[contains(text(), '" + name + "')]"))).perform(); - + Wait wait = new FluentWait(Utils.driver) + .withTimeout(5000, TimeUnit.MILLISECONDS) + .pollingEvery(250, TimeUnit.MILLISECONDS) + .ignoring(NoSuchElementException.class); + wait.until(ExpectedConditions.alertIsPresent()); Alert alertBox = Utils.driver.switchTo().alert(); alertBox.accept(); Utils.retryingFind(By.id("save_print")).click(); Index: ssts-selenium-test/src/test/java/test_4_1/ALL.java =================================================================== diff -u -r17680 -r17686 --- ssts-selenium-test/src/test/java/test_4_1/ALL.java (.../ALL.java) (revision 17680) +++ ssts-selenium-test/src/test/java/test_4_1/ALL.java (.../ALL.java) (revision 17686) @@ -192,6 +192,7 @@ recyle.recyle_Foreign(); /** 判断消毒物品申请单是否存在 */ Utils.retryingFind(By.tagName("body")); +// WebElement element = Utils.retryingFindForthCellOfTable(By .id("awaitForRecycleTable")); if (element != null) { @@ -238,6 +239,7 @@ Utils.retryingFind( By.linkText(Utils.settings.getJSONObject("一级供应室装配组") .getString("名称3"))).click(); +// WebElement frame = Utils.retryingFind(By.id("iframe_reviewPacking")); Utils.driver.switchTo().frame(frame); Review review = new Review(); Index: ssts-selenium-test/src/test/java/test_4_1/Recyle.java =================================================================== diff -u -r17680 -r17686 --- ssts-selenium-test/src/test/java/test_4_1/Recyle.java (.../Recyle.java) (revision 17680) +++ ssts-selenium-test/src/test/java/test_4_1/Recyle.java (.../Recyle.java) (revision 17686) @@ -20,8 +20,10 @@ import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.interactions.Actions; +import org.openqa.selenium.support.ui.ExpectedConditions; import org.openqa.selenium.support.ui.FluentWait; import org.openqa.selenium.support.ui.Wait; +import org.openqa.selenium.support.ui.WebDriverWait; import test_4_1.tools.Utils; @@ -144,10 +146,12 @@ @Test public void recyle_oneSupplyRoomSignboard() { try { - WebElement bodyElement = Utils.retryingFind(By.tagName("body")); + String barcode = Utils.settings.getJSONObject("临床科室").getString( + "条码"); + // 输入临床科室条码,只显示临床科室的申请单 - bodyElement.sendKeys(Utils.settings.getJSONObject("临床科室") - .getString("条码") + "\n"); + Utils.retryingFindAndSendKeys(By.tagName("body"), barcode + "\n"); + Utils.retryingFindClickFirstCellOfTable(By .id("awaitForRecycleTable")); @@ -605,7 +609,7 @@ Thread.sleep(1000); String a = Utils.settings.getJSONObject("一级供应室清洗篮筐2").getString( "条码"); - + tousseItemTable.sendKeys(a + "\n"); WebElement element = Utils.retryingFind(By @@ -726,14 +730,16 @@ @Test public void recyle_Foreign() { try { + String a = Utils.settings.getJSONObject("临床科室").getString("条码"); boolean displayed = false; // for (String winHandle : Utils.driver.getWindowHandles()) { // Utils.driver.switchTo().window(winHandle); // } - WebElement bodyElement = Utils.retryingFind(By.tagName("body")); // 输入临床科室条码,只显示临床科室的申请单 + Utils.retryingFindAndSendKeys(By.tagName("body"), a + "\n"); + - bodyElement.sendKeys(Utils.settings.getJSONObject("临床科室").getString("条码") + "\n"); +// bodyElement.sendKeys(); WebElement element = Utils.retryingFind(By.id("tousseItemTable")); if (element != null) { @@ -785,6 +791,12 @@ Utils.driver.switchTo().frame(frame); Utils.retryingFind(By.cssSelector("a[class='submit']")).click(); + wait = new FluentWait(Utils.driver) + .withTimeout(5000, TimeUnit.MILLISECONDS) + .pollingEvery(250, TimeUnit.MILLISECONDS) + .ignoring(NoSuchElementException.class); + wait.until(ExpectedConditions.alertIsPresent()); + Alert alertBox = Utils.driver.switchTo().alert(); alertBox.accept(); @@ -797,7 +809,7 @@ } Utils.retryingFind(By.cssSelector(".btn-e")).click(); - Thread.sleep(1500); + Thread.sleep(1500); } catch (Exception e) { System.out.println("异常信息:"); e.printStackTrace(); @@ -869,7 +881,11 @@ frame = Utils.retryingFind(By.id("xubox_iframe")); Utils.driver.switchTo().frame(frame); Utils.retryingFind(By.cssSelector("a[class='submit']")).click(); - + wait = new FluentWait(Utils.driver) + .withTimeout(5000, TimeUnit.MILLISECONDS) + .pollingEvery(250, TimeUnit.MILLISECONDS) + .ignoring(NoSuchElementException.class); + wait.until(ExpectedConditions.alertIsPresent()); Alert alertBox = Utils.driver.switchTo().alert(); alertBox.accept(); @@ -969,7 +985,11 @@ String recyclingFormWindowhandle = Utils.driver.getWindowHandle(); Utils.driver.switchTo().window(recyclingFormWindowhandle); Utils.retryingFind(By.cssSelector(".btn-d")).click(); - + wait = new FluentWait(Utils.driver) + .withTimeout(5000, TimeUnit.MILLISECONDS) + .pollingEvery(250, TimeUnit.MILLISECONDS) + .ignoring(NoSuchElementException.class); + wait.until(ExpectedConditions.alertIsPresent()); Alert alertBox = Utils.driver.switchTo().alert(); alertBox.accept(); } catch (Exception e) {