Index: ssts-selenium-test/src/test/java/test_4_1/Recyle.java =================================================================== diff -u -r17892 -r17893 --- ssts-selenium-test/src/test/java/test_4_1/Recyle.java (.../Recyle.java) (revision 17892) +++ ssts-selenium-test/src/test/java/test_4_1/Recyle.java (.../Recyle.java) (revision 17893) @@ -216,13 +216,7 @@ WebElement bodyElement = Utils.retryingFindAndSendKeys( By.tagName("body"), Utils.settings.getJSONObject("临床科室") .getString("条码") + "\n"); - // 断言临床科室的填写成功 - WebElement retryingFind = Utils - .retryingFind(By.id("depart")); - Utils.wait.until(ExpectedConditions.attributeContains(By.id("depart"), "value", Utils.settings.getJSONObject("临床科室") - .getString("名称"))); - // displayed = Utils.retryingFindClickFirstCellOfTable(By // .id("awaitForRecycleTable")); WebElement element = Utils.retryingFind(By.id("tousseItemTable")); @@ -488,8 +482,15 @@ Utils.retryingFindAndSendKeys(By.id("tousseItemTable"), Utils.settings.getJSONObject("临床科室") .getString("条码") + "\n"); + Wait wait = new FluentWait(Utils.driver) + .withTimeout(5000, TimeUnit.MILLISECONDS) + .pollingEvery(250, TimeUnit.MILLISECONDS) + .ignoring(NoSuchElementException.class) + .ignoring(StaleElementReferenceException.class) + .ignoring(NullPointerException.class); + // 断言临床科室的填写成功 - Utils.wait.until(ExpectedConditions.attributeContains( + wait.until(ExpectedConditions.attributeContains( By.id("depart"), "value", Utils.settings.getJSONObject("临床科室").getString("名称"))); Index: ssts-selenium-test/src/test/java/test_4_1/tools/Utils.java =================================================================== diff -u -r17890 -r17893 --- ssts-selenium-test/src/test/java/test_4_1/tools/Utils.java (.../Utils.java) (revision 17890) +++ ssts-selenium-test/src/test/java/test_4_1/tools/Utils.java (.../Utils.java) (revision 17893) @@ -27,6 +27,7 @@ import org.openqa.selenium.ie.InternetExplorerDriver; import org.openqa.selenium.remote.DesiredCapabilities; import org.openqa.selenium.support.ui.ExpectedCondition; +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; @@ -51,7 +52,7 @@ public static final String ACTION_SWITCH_TO_FRAME = "switchToFrame"; public static final String ACTION_CLEAR = "clear"; - public static Wait wait; +// public static Wait wait; /** * 项目设置对象 @@ -141,11 +142,12 @@ // driver = new RemoteWebDriver(new URL( "http://192.168.2.18:4444/wd/hub"), ieCapabilities); driver = new InternetExplorerDriver(ieCapabilities); - wait = new FluentWait(driver) - .withTimeout(5000, TimeUnit.MILLISECONDS) - .pollingEvery(250, TimeUnit.MILLISECONDS) - .ignoring(NoSuchElementException.class) - .ignoring(StaleElementReferenceException.class); +// wait = new FluentWait(driver) +// .withTimeout(5000, TimeUnit.MILLISECONDS) +// .pollingEvery(250, TimeUnit.MILLISECONDS) +// .ignoring(NoSuchElementException.class) +// .ignoring(StaleElementReferenceException.class) +// .ignoring(NullPointerException.class); } catch (Exception e) { e.printStackTrace(); @@ -249,12 +251,23 @@ public static WebElement retryingFindAndDoAction(By by , String actionType , CharSequence... keys) { WebElement element = null; int attempts = 0; - while (attempts < 5) { + while (attempts < 3) { try { element = fluentWaitUntilFind(by); if (ACTION_CLICK.equalsIgnoreCase(actionType)){ + + // 等待元素变为可点击状态 +// Wait wait = new FluentWait(driver) +// .withTimeout(5000, TimeUnit.MILLISECONDS) +// .pollingEvery(250, TimeUnit.MILLISECONDS) +// .ignoring(NoSuchElementException.class) +// .ignoring(StaleElementReferenceException.class) +// .ignoring(NullPointerException.class); +// +// wait.until(ExpectedConditions.elementToBeClickable(element)); + element.click(); } else if (ACTION_SENDKEYS.equalsIgnoreCase(actionType)){ @@ -322,6 +335,8 @@ element = fluentWaitUntilFind(by); element.sendKeys(keys); + + // TODO:下面的sleep代码,要改为判断Ext.store是否加载完成,然后点击下拉框,而不是睡眠方式 Thread.sleep(1500); //等待页面状态加载完成 // JavascriptExecutor js=(JavascriptExecutor)driver; @@ -353,12 +368,14 @@ */ public static WebElement fluentWaitUntilFind(By by) { WebElement element; - Wait wait = new FluentWait(Utils.driver) - .withTimeout(5000, TimeUnit.MILLISECONDS) - .pollingEvery(250, TimeUnit.MILLISECONDS) - .ignoring(NoSuchElementException.class) - .ignoring(StaleElementReferenceException.class) - .ignoring(NullPointerException.class); + + Wait wait = new FluentWait(driver) + .withTimeout(5000, TimeUnit.MILLISECONDS) + .pollingEvery(250, TimeUnit.MILLISECONDS) + .ignoring(NoSuchElementException.class) + .ignoring(StaleElementReferenceException.class) + .ignoring(NullPointerException.class); + element = wait .until(new Function() { public WebElement apply(WebDriver driver) { @@ -571,12 +588,8 @@ result = true; break; } - } catch (StaleElementReferenceException e) { -// System.out.println("发生了异常:StaleElementReferenceException"); + } catch (Exception e) { // e.printStackTrace(); - } catch (NoSuchElementException e) { -// System.out.println("发生了异常:NoSuchElementException"); -// e.printStackTrace(); } attempts++; } @@ -861,4 +874,19 @@ return jsonObj; } + + /** + * 为ExtJS4的组合框输入文字 + * @param comboBoxName ExtJS4的组合框名字 + * @param text 要输入的文字 + */ + public static void extJS4comboBoxInput(String comboBoxName, String text){ + String script = "return Ext4.getCmp('" + comboBoxName + "').getStore().isLoading();"; + //输入前先等待,看看是否已经加载完,因为处理科室改变物品会重新加载 + Utils.waitPageLoaded(script); + Utils.findByAwaitAndSend(By.cssSelector("input[name='" + comboBoxName + "']"), text); + //输入完等待加载完毕,加载完毕后才能点 + Utils.waitPageLoaded(script); + Utils.findByAwaitAndClick(By.xpath("//div/ul/li[contains(text(), '" + text + "')]")); + } } Index: ssts-selenium-test/src/test/java/test_4_1/apply/helper/ApplyHelper.java =================================================================== diff -u -r17869 -r17893 --- ssts-selenium-test/src/test/java/test_4_1/apply/helper/ApplyHelper.java (.../ApplyHelper.java) (revision 17869) +++ ssts-selenium-test/src/test/java/test_4_1/apply/helper/ApplyHelper.java (.../ApplyHelper.java) (revision 17893) @@ -3,10 +3,16 @@ import org.apache.commons.lang3.BooleanUtils; import org.apache.commons.lang3.ObjectUtils; import org.openqa.selenium.By; +import org.openqa.selenium.StaleElementReferenceException; +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.slf4j.Logger; import org.slf4j.LoggerFactory; + import test_4_1.Constants; import test_4_1.SettingConstants; import test_4_1.apply.applyConstants.ApplyEnum; @@ -18,6 +24,8 @@ import test_4_1.tools.Utils; import java.util.Map; +import java.util.NoSuchElementException; +import java.util.concurrent.TimeUnit; import static org.testng.Assert.assertNotNull; @@ -44,6 +52,18 @@ Utils.findByAwaitAndSend(By.cssSelector("input[id='handleDepart-inputEl']"), handleRoomName); // Utils.findByAwaitAndSend(By.cssSelector("input[id='handleDepart-inputEl']"), Keys.DOWN); Utils.findByAwaitAndClick(By.xpath("//div/div/ul/li[contains(text(), '" + handleRoomName + "')]")); + + // 断言处理科室填写成功 + Wait wait = new FluentWait(Utils.driver) + .withTimeout(5000, TimeUnit.MILLISECONDS) + .pollingEvery(250, TimeUnit.MILLISECONDS) + .ignoring(NoSuchElementException.class) + .ignoring(StaleElementReferenceException.class) + .ignoring(NullPointerException.class); + + wait.until(ExpectedConditions.attributeContains( + By.id("handleDepart-inputEl"), "value", + handleRoomName)); } @@ -72,20 +92,21 @@ */ private static void setAmount(String goodName, int amount) { // String script = "return Ext4.getCmp('package1').getStore().isLoading() || Ext4.getCmp('handleDepart').getStore().isLoading()"; - String script = "return Ext4.getCmp('package1').getStore().isLoading();"; - //输入前先等待,看看是否已经加载完,因为处理科室改变物品会重新加载 - Utils.waitPageLoaded(script); - Utils.findByAwaitAndSend(By.cssSelector("input[name='package1']"), goodName); - //输入完等待加载完毕,加载完毕后才能点 - Utils.waitPageLoaded(script); - Utils.findByAwaitAndClick(By.xpath("//div/ul/li[contains(text(), '" + goodName + "')]")); +// String script = "return Ext4.getCmp('package1').getStore().isLoading();"; +// //输入前先等待,看看是否已经加载完,因为处理科室改变物品会重新加载 +// Utils.waitPageLoaded(script); +// Utils.findByAwaitAndSend(By.cssSelector("input[name='package1']"), goodName); +// //输入完等待加载完毕,加载完毕后才能点 +// Utils.waitPageLoaded(script); + + Utils.extJS4comboBoxInput("package1", goodName); + Utils.findByAwaitAndSend(By.cssSelector("input[name='count1']"), amount + "\n"); //因为send之前已经清空了该输入框的数据,所以这里就不需要再执行清空了 // Utils.findByAwaitAndClear(By.cssSelector("input[name='package1']")); // Utils.findByAwaitAndClear(By.cssSelector("input[name='count1']")); } - /** * 切换到对应的申请窗口(非省医环境) * @@ -184,8 +205,12 @@ } String name = Utils.settings.getJSONObject("一级供应室外来器械").optString(SettingConstants.名称, null); assertNotNull(name); - Utils.findByAwaitAndSend(By.cssSelector("input[name='foreignTousseName1']"), name); - Utils.findByAwaitAndClick(By.xpath("//div/ul/li[contains(text(), '" + name + "')]")); + +// Utils.findByAwaitAndSend(By.cssSelector("input[name='foreignTousseName1']"), name); +// Utils.findByAwaitAndClick(By.xpath("//div/ul/li[contains(text(), '" + name + "')]")); + + Utils.extJS4comboBoxInput("foreignTousseName1", name); + Utils.findByAwaitAndClick(By.cssSelector("a[id='addTousseBt']")); ApplyHelper.doSubmitForm(By.id("commitBtn")); // ApplyHelper.doSubmitForm(By.xpath("//span/span/span[contains(text(), '提交')]"));