Index: ssts-selenium-test/src/test/java/test_4_1/tools/Utils.java =================================================================== diff -u -r17905 -r17910 --- ssts-selenium-test/src/test/java/test_4_1/tools/Utils.java (.../Utils.java) (revision 17905) +++ ssts-selenium-test/src/test/java/test_4_1/tools/Utils.java (.../Utils.java) (revision 17910) @@ -71,9 +71,22 @@ */ public static WebDriverWait confirmWaitSetting; // public static Wait waitSetting; + /** + * 单次装配后产生的条码 + */ public static List barcodes; + /** + * 用于代理灭菌二次发货的条码 + */ public static List resendout; + /** + * 所有装配产生的条码 + */ public static List reBarcodes = new ArrayList(); + /** + * 单次一次性物品入库后产生的条码 + */ + public static List disposableGoodsBatchBarcodesAfterEntry = new ArrayList(); /** * 根据项目名称,初始化项目的配置对象 @@ -218,6 +231,38 @@ Utils.reBarcodes.addAll(barcodes); return barcodes; } + + /** + * 获取一次性物品入库后的条码集合对象 + * + */ + public static List getDisposableGoodsBatchBarcodesAfterEntry() { + int count = 0; + List barcodes = new ArrayList(); + while(count <= 10){ + try{ + JavascriptExecutor js = (JavascriptExecutor) driver; + Object entryItemStr = js.executeScript("return JSON.stringify(entryItemJsonArray)"); + JSONArray array = JSONArray.fromObject(entryItemStr); + if (array != null) { + for (int i = 0; i < array.size(); i++) { + JSONObject entryItem = array.optJSONObject(i); + barcodes.add(entryItem.optString("barcode")); + } + break; + } + }catch(Exception e){ + e.printStackTrace(); + } + try{ + Thread.sleep(1000); + }catch(Exception e){ + e.printStackTrace(); + } + count++; + } + return barcodes; + } /** * 重复查找,当出现引用的element过时后,重新查找该element Index: ssts-selenium-test/src/test/java/test_4_1/One_use.java =================================================================== diff -u -r17884 -r17910 --- ssts-selenium-test/src/test/java/test_4_1/One_use.java (.../One_use.java) (revision 17884) +++ ssts-selenium-test/src/test/java/test_4_1/One_use.java (.../One_use.java) (revision 17910) @@ -6,10 +6,17 @@ import org.testng.AssertJUnit; import java.text.SimpleDateFormat; import java.util.Date; +import java.util.NoSuchElementException; +import java.util.concurrent.TimeUnit; import org.openqa.selenium.By; import org.openqa.selenium.Keys; +import org.openqa.selenium.StaleElementReferenceException; +import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.ui.ExpectedConditions; +import org.openqa.selenium.support.ui.FluentWait; +import org.openqa.selenium.support.ui.Wait; import test_4_1.tools.Utils; @@ -51,12 +58,22 @@ Utils.retryingFindAndClick( By.xpath("//div/a/span[contains(text(), '入库单管理')]")); - WebElement frame = Utils.retryingFindAndSwitchToFrame(By.id("mainFrame")); + Utils.retryingFindAndSwitchToFrame(By.id("mainFrame")); Utils.retryingFindAndClick(By.xpath("//button[contains(text(), '添加')]")); String currentwindowhandle = Utils.driver.getWindowHandle(); Utils.driver.switchTo().window(currentwindowhandle); String name = Utils.settings.getJSONObject("一级供应室一次性物品").getString( "名称"); + //要等待物品名称下拉框由disable变成enable后即可以被点击后再进行以下操作 + Wait wait = new FluentWait(Utils.driver) + .withTimeout(5000, TimeUnit.MILLISECONDS) + .pollingEvery(250, TimeUnit.MILLISECONDS) + .ignoring(NoSuchElementException.class) + .ignoring(StaleElementReferenceException.class); + + wait.until(ExpectedConditions.elementToBeClickable(By + .id("name1"))); + for (int i = 1; i < 4; i++) { String x = (int) (Math.random() * 8 + 1) + ""; Utils.retryingFindAndSendKeys(By.id("name1"),Keys.DOWN); @@ -85,6 +102,21 @@ } Utils.retryingFindAndClick( By.xpath("//button[contains(text(), '保存并打印新标签')]")); + + //必须先定位回到最外层的iframe,然后逐步定位里层的iframe + Utils.retryingFindAndSwitchToFrame(By + .id("iframe_enterpriseView")); + + // 必须加上如下的切换代码,否则获取条码的javascript语句执行会报异常错误 + Utils.retryingFindAndSwitchToFrame(By.id("mainFrame")); + + //等待表单提交成功 + wait.until(ExpectedConditions.attributeToBe(Utils.driver.findElement(By + .id("formSubmitResult")), "value", "1")); + + //获取一次性物品入库后的条码 + Utils.disposableGoodsBatchBarcodesAfterEntry = Utils.getDisposableGoodsBatchBarcodesAfterEntry(); + System.out.println("本次一次性物品入库后的条码:" + Utils.disposableGoodsBatchBarcodesAfterEntry); } catch (Exception e) { e.printStackTrace(); AssertJUnit.fail(e.getMessage()); Index: ssts-selenium-test/src/test/java/test_4_1/UserRecord.java =================================================================== diff -u -r17854 -r17910 --- ssts-selenium-test/src/test/java/test_4_1/UserRecord.java (.../UserRecord.java) (revision 17854) +++ ssts-selenium-test/src/test/java/test_4_1/UserRecord.java (.../UserRecord.java) (revision 17910) @@ -1,16 +1,28 @@ package test_4_1; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.Test; -import org.testng.annotations.BeforeMethod; -import org.testng.AssertJUnit; +import java.util.NoSuchElementException; +import java.util.concurrent.TimeUnit; + +import org.apache.commons.collections4.CollectionUtils; 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.testng.AssertJUnit; +import org.testng.annotations.AfterMethod; +import org.testng.annotations.Test; import test_4_1.tools.Utils; public class UserRecord { - @BeforeMethod + /** + * 因为在录使用记录记录需要先录入一次性物品入库单,所以此方法先注释 + */ + //@BeforeMethod public void init() { try { Utils.init(); @@ -44,6 +56,13 @@ @Test public void UserRecord_success() { try { + //一次性物品入库 + One_use ou = new One_use(); + ou.init(); + ou.One_use_Entry_success(); + ou.after(); + + init(); Utils.retryingFindAndSendKeys(By.id("hospitalNum"), "01"); Utils.retryingFindAndSendKeys(By.id("treatmentNum"), "02"); Utils.retryingFindAndSendKeys(By.id("washHandNurse"), @@ -59,23 +78,28 @@ Utils.reBarcodes.get(i) + "\n"); } + // 一次性物品登记使用记录 - Utils.retryingFindAndSendKeys(By.id("tempBarcode"), - Utils.settings.getJSONObject("一级供应室一次性物品").getString("条码1") - + "\n"); - Utils.retryingFindAndSendKeys(By.id("tempBarcode"), - Utils.settings.getJSONObject("一级供应室一次性物品").getString("条码2") - + "\n"); - Utils.retryingFindAndSendKeys(By.id("tempBarcode"), - Utils.settings.getJSONObject("一级供应室一次性物品").getString("条码3") - + "\n"); + if(CollectionUtils.isNotEmpty(Utils.disposableGoodsBatchBarcodesAfterEntry)){ + for (String barcode : Utils.disposableGoodsBatchBarcodesAfterEntry) { + Utils.retryingFindAndSendKeys(By.id("tempBarcode"), barcode + "\n"); + } + } Utils.retryingFindAndClick( By.cssSelector("img[src='/images/web/arrow_top.png']")); Utils.retryingFindAndClick( By.xpath("//button[contains(text(), '保存并审核生成申请单')]")); Utils.retryingFindAndClick(By.xpath("//button[contains(text(), '是')]")); - + + //需要判断表单提交成功且返回正常后才能结束,否则就将不会提交到后台 + Wait wait = new FluentWait(Utils.driver) + .withTimeout(5000, TimeUnit.MILLISECONDS) + .pollingEvery(250, TimeUnit.MILLISECONDS) + .ignoring(NoSuchElementException.class) + .ignoring(StaleElementReferenceException.class); + wait.until(ExpectedConditions.attributeToBe(Utils.driver.findElement(By + .id("formSubmitResult")), "value", "1")); } catch (Exception e) { e.printStackTrace(); AssertJUnit.fail(e.getMessage());