/** * */ package test_4_1; import static org.testng.AssertJUnit.assertTrue; import org.testng.annotations.AfterMethod; import org.testng.annotations.Test; import org.testng.annotations.BeforeMethod; import org.testng.AssertJUnit; import java.util.List; import java.util.NoSuchElementException; import java.util.concurrent.TimeUnit; import java.util.function.Function; import org.openqa.selenium.Alert; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.interactions.Actions; import org.openqa.selenium.support.ui.FluentWait; import org.openqa.selenium.support.ui.Wait; import test_4_1.tools.Utils; /** * @author cherry 2016-02-25 * */ public class Recyle { @BeforeMethod public void init() { Utils.init(); Login login = new Login(); login.login_oneSupplyRoom(); Utils.changeWindow(); } @Test public void recyle_fail() { try { // 获取当前日期 // Date now = new Date(); // DateFormat date = DateFormat.getDateInstance(); // String dateNow = date.format(now); // System.out.println(dateNow); // 回收失败 // Utils.retryingFind(By // .xpath("//td[contains(text(), '心血管2区')] and td[contains(text(), '" // + // dateNow +"')]")).click(); WebElement bodyElement = Utils.retryingFind(By.tagName("body")); // 输入临床科室条码,只显示临床科室的申请单 bodyElement.sendKeys(Utils.settings.getJSONObject("临床科室") .getString("条码") + "\n"); // try { // (2000); // } catch (InterruptedException e) { // e.printStackTrace(); // } // 手术室有多张单,则获取器械包的器械(材料)清单表格,点击第一张单 // Utils.retryingFindClickFirstCellOfTable(By.id("awaitForRecycleTable")); // 手术室只有一张单,等待新打开的回收单页面加载完成 Utils.retryingFind(By.cssSelector(".btn-e")).click(); assertTrue(Utils.retryingFind(By.id("idBox")).getText() .contains("还有部分器械包未装入容器,不能保存。")); } catch (Exception e) { e.printStackTrace(); AssertJUnit.fail(e.getMessage()); } } /** * 一级供应室通过申请单回收、修改申请单数量 * */ @Test public void recyle_oneSupplyRoom() { try { WebElement bodyElement = Utils.retryingFind(By.tagName("body")); // 输入临床科室条码,只显示临床科室的申请单 bodyElement.sendKeys(Utils.settings.getJSONObject("临床科室") .getString("条码") + "\n"); String recyclingFormWindowhandle = Utils.driver.getWindowHandle(); Utils.driver.switchTo().window(recyclingFormWindowhandle); // 获取器械包的器械(材料)清单表格 Wait wait = new FluentWait(Utils.driver) .withTimeout(5000, TimeUnit.MILLISECONDS) .pollingEvery(100, TimeUnit.MILLISECONDS) .ignoring(NoSuchElementException.class); WebElement tousseItemTable = wait .until(new Function() { public WebElement apply(WebDriver driver) { return Utils.retryingFind(By.id("tousseItemTable")); } }); tousseItemTable.sendKeys(Utils.settings.getJSONObject("一级供应室清洗篮筐1") .getString("条码") + "\n"); tousseItemTable.sendKeys(Utils.settings.getJSONObject("一级供应室清洗篮筐2") .getString("条码") + "\n"); for (String winHandle : Utils.driver.getWindowHandles()) { Utils.driver.switchTo().window(winHandle); } recyclingFormWindowhandle = Utils.driver.getWindowHandle(); Utils.driver.switchTo().window(recyclingFormWindowhandle); Utils.retryingFind( By.xpath("//div/div/button/span[contains(text(), '是')]")) .click(); for (String winHandle : Utils.driver.getWindowHandles()) { Utils.driver.switchTo().window(winHandle); } List addButtons = tousseItemTable.findElements(By .cssSelector(".btn-a")); Utils.retryingFind( By.xpath("//tbody/tr/td/a[contains(text(), '+')]")).click(); for (WebElement addButton : addButtons) { addButton.click(); } Utils.retryingFind(By.cssSelector(".btn-e")).click(); for (String winHandle : Utils.driver.getWindowHandles()) { Utils.driver.switchTo().window(winHandle); } } catch (Exception e) { e.printStackTrace(); AssertJUnit.fail(e.getMessage()); } } /** * 一级供应室通过申请单回收带标识牌的器械包、修改申请单数量、通过查找添加器械包 * */ @Test public void recyle_oneSupplyRoomSignboard() { try { WebElement bodyElement = Utils.retryingFind(By.tagName("body")); // 输入临床科室条码,只显示临床科室的申请单 bodyElement.sendKeys(Utils.settings.getJSONObject("临床科室") .getString("条码") + "\n"); Utils.retryingFindClickFirstCellOfTable(By .id("awaitForRecycleTable")); String recyclingFormWindowhandle = Utils.driver.getWindowHandle(); Utils.driver.switchTo().window(recyclingFormWindowhandle); // 获取器械包的器械(材料)清单表格 Wait wait = new FluentWait(Utils.driver) .withTimeout(5000, TimeUnit.MILLISECONDS) .pollingEvery(100, TimeUnit.MILLISECONDS) .ignoring(NoSuchElementException.class); WebElement tousseItemTable = wait .until(new Function() { public WebElement apply(WebDriver driver) { return driver.findElement(By.id("tousseItemTable")); } }); scan(tousseItemTable); tousseItemTable.sendKeys(Utils.settings.getJSONObject("一级供应室清洗篮筐4") .getString("条码") + "\n"); boolean displayed = false; WebElement element = Utils.retryingFind(By .xpath("//div/div/button/span[contains(text(), '是')]")); if (element != null) { displayed = element.isDisplayed(); } if (displayed) { Utils.retryingFind( By.xpath("//div/div/button/span[contains(text(), '是')]")) .click(); for (String winHandle : Utils.driver.getWindowHandles()) { Utils.driver.switchTo().window(winHandle); } } Utils.retryingFind(By.linkText("添加器械包")).click(); Utils.driver.switchTo().defaultContent(); WebElement frame = Utils.retryingFind(By.id("xubox_iframe")); Utils.driver.switchTo().frame(frame); Utils.retryingFind( By.id(Utils.settings.getJSONObject("回收查询").getString("按钮3"))) .click(); Utils.retryingFind( By.id(Utils.settings.getJSONObject("回收查询").getString("按钮2"))) .click(); Utils.retryingFind(By .linkText(Utils.settings.getJSONObject("一级供应室器械包2") .getString("名称"))).click(); recyclingFormWindowhandle = Utils.driver.getWindowHandle(); Utils.driver.switchTo().window(recyclingFormWindowhandle); List addButtons = tousseItemTable.findElements(By .cssSelector(".btn-a")); Utils.retryingFind( By.xpath("//tbody/tr/td/a[contains(text(), '+')]")).click(); for (WebElement addButton : addButtons) { addButton.click(); } tousseItemTable.sendKeys(Utils.settings.getJSONObject("一级供应室清洗篮筐1") .getString("条码") + "\n"); element = Utils.retryingFind(By .xpath("//div/div/button/span[contains(text(), '是')]")); if (element != null) { displayed = element.isDisplayed(); } if (displayed) { Utils.retryingFind( By.xpath("//div/div/button/span[contains(text(), '是')]")) .click(); for (String winHandle : Utils.driver.getWindowHandles()) { Utils.driver.switchTo().window(winHandle); } } // 扫描标识牌条码回收入筐 tousseItemTable.sendKeys(Utils.settings.getJSONObject("一级供应室器械包1") .getString("标识牌条码1") + "\n"); Utils.retryingFind(By.cssSelector(".btn-e")).click(); for (String winHandle : Utils.driver.getWindowHandles()) { Utils.driver.switchTo().window(winHandle); } } catch (Exception e) { e.printStackTrace(); AssertJUnit.fail(e.getMessage()); } } /** * 一级供应室通过申请单回收自定义器械包 * */ @Test public void recyle_customSet() { try { boolean displayed = false; WebElement bodyElement = Utils.retryingFind(By.tagName("body")); // 输入临床科室条码,只显示临床科室的申请单 bodyElement.sendKeys(Utils.settings.getJSONObject("临床科室") .getString("条码") + "\n"); // displayed = Utils.retryingFindClickFirstCellOfTable(By // .id("awaitForRecycleTable")); WebElement element = Utils.retryingFind(By.id("tousseItemTable")); if (element == null) { Utils.retryingFindClickFirstCellOfTable(By .id("awaitForRecycleTable")); } else { Utils.retryingFind(By.id("tousseItemTable")); } String recyclingFormWindowhandle = Utils.driver.getWindowHandle(); Utils.driver.switchTo().window(recyclingFormWindowhandle); // 获取器械包的器械(材料)清单表格 Wait wait = new FluentWait(Utils.driver) .withTimeout(5000, TimeUnit.MILLISECONDS) .pollingEvery(100, TimeUnit.MILLISECONDS) .ignoring(NoSuchElementException.class); WebElement tousseItemTable = wait .until(new Function() { public WebElement apply(WebDriver driver) { return driver.findElement(By.id("tousseItemTable")); } }); scan(tousseItemTable); tousseItemTable.sendKeys(Utils.settings.getJSONObject("一级供应室清洗篮筐4") .getString("条码") + "\n"); displayed = false; element = Utils.retryingFind(By .xpath("//div/div/button/span[contains(text(), '是')]")); if (element != null) { displayed = element.isDisplayed(); } if (displayed) { Utils.retryingFind( By.xpath("//div/div/button/span[contains(text(), '是')]")) .click(); for (String winHandle : Utils.driver.getWindowHandles()) { Utils.driver.switchTo().window(winHandle); } } List addButtons = tousseItemTable.findElements(By .cssSelector(".btn-a")); for (WebElement addButton : addButtons) { addButton.click(); } Utils.retryingFind(By.cssSelector(".btn-e")).click(); for (String winHandle : Utils.driver.getWindowHandles()) { Utils.driver.switchTo().window(winHandle); } } catch (Exception e) { e.printStackTrace(); AssertJUnit.fail(e.getMessage()); } } /** * 一级供应室使用记录转申请单回收,修改回收数量 * */ @Test public void recyle_userRecordApplyUpdate() { try { // 获取器械包的器械(材料)清单表格 Wait wait = new FluentWait(Utils.driver) .withTimeout(5000, TimeUnit.MILLISECONDS) .pollingEvery(100, TimeUnit.MILLISECONDS) .ignoring(NoSuchElementException.class); WebElement tousseItemTable = wait .until(new Function() { public WebElement apply(WebDriver driver) { return driver.findElement(By.id("tousseItemTable")); } }); tousseItemTable.sendKeys(Utils.settings.getJSONObject("一级供应室清洗篮筐1") .getString("条码") + "\n"); // 增加休眠,避免扫描后提示条码不符合规范的问题 tousseItemTable.sendKeys(Utils.settings.getJSONObject("一级供应室清洗篮筐3") .getString("条码") + "\n"); // 根据cssClass获取入筐按钮集合 List addButtons = tousseItemTable.findElements(By .cssSelector(".btn-a")); // 序号,回收数量输入框的名称后缀 int index = addButtons.size(); for (WebElement addButton : addButtons) { index--; // 点击回收数量输入框 Utils.retryingFind(By.id("recycleAmount" + index)).click(); // 弹出了数量输入的对话框 WebElement frame = Utils.retryingFind(By.id("xubox_iframe")); Utils.driver.switchTo().frame(frame); Utils.retryingFind(By.linkText("1")).click(); Utils.retryingFind(By.cssSelector(".btn-a")).click(); Utils.driver.switchTo().defaultContent(); addButton.click(); } Utils.retryingFind(By.cssSelector(".btn-e")).click(); for (String winHandle : Utils.driver.getWindowHandles()) { Utils.driver.switchTo().window(winHandle); } } catch (Exception e) { e.printStackTrace(); AssertJUnit.fail(e.getMessage()); } } /** * 一级供应室使用记录转申请单回收 * */ @Test public void recyle_userRecordApply() { try { // 获取器械包的器械(材料)清单表格 Wait wait = new FluentWait(Utils.driver) .withTimeout(5000, TimeUnit.MILLISECONDS) .pollingEvery(100, TimeUnit.MILLISECONDS) .ignoring(NoSuchElementException.class); WebElement tousseItemTable = wait .until(new Function() { public WebElement apply(WebDriver driver) { return driver.findElement(By.id("tousseItemTable")); } }); // 增加休眠,避免扫描后提示条码不符合规范的问题 tousseItemTable.sendKeys(Utils.settings.getJSONObject("一级供应室清洗篮筐3") .getString("条码") + "\n"); scan(tousseItemTable); // 根据cssClass获取入筐按钮集合 List addButtons = tousseItemTable.findElements(By .cssSelector(".btn-a")); for (WebElement addButton : addButtons) { addButton.click(); } Utils.retryingFind(By.cssSelector(".btn-e")).click(); for (String winHandle : Utils.driver.getWindowHandles()) { Utils.driver.switchTo().window(winHandle); } } catch (Exception e) { e.printStackTrace(); AssertJUnit.fail(e.getMessage()); } } /** * 一级供应室回收还物单 * */ @Test public void recyle_return() { try { // 获取body对象,sendKeys更加可靠。actions.click()的方式在win10,IE11下不可靠 WebElement bodyElement = Utils.retryingFind(By.tagName("body")); // 输入临床科室条码,只显示临床科室的申请单 bodyElement.sendKeys(Utils.settings.getJSONObject("临床科室") .getString("条码") + "\n"); Utils.retryingFindClickFirstCellOfTable(By .id("awaitForRecycleTable")); String recyclingFormWindowhandle = Utils.driver.getWindowHandle(); Utils.driver.switchTo().window(recyclingFormWindowhandle); // 获取器械包的器械(材料)清单表格 Wait wait = new FluentWait(Utils.driver) .withTimeout(5000, TimeUnit.MILLISECONDS) .pollingEvery(100, TimeUnit.MILLISECONDS) .ignoring(NoSuchElementException.class); WebElement tousseItemTable = wait .until(new Function() { public WebElement apply(WebDriver driver) { return driver.findElement(By.id("tousseItemTable")); } }); tousseItemTable.sendKeys(Utils.settings.getJSONObject("一级供应室清洗篮筐3") .getString("条码") + "\n"); // for (String winHandle : Utils.driver.getWindowHandles()) { // Utils.driver.switchTo().window(winHandle); // } // recyclingFormWindowhandle = Utils.driver.getWindowHandle(); // Utils.driver.switchTo().window(recyclingFormWindowhandle); // Utils.retryingFind( // By.xpath("//div/div/button/span[contains(text(), '是')]")) // .click(); // (1000); // for (String winHandle : Utils.driver.getWindowHandles()) { // Utils.driver.switchTo().window(winHandle); // } scan(tousseItemTable); // 根据cssClass获取入筐按钮集合 List addButtons = tousseItemTable.findElements(By .cssSelector(".btn-a")); for (WebElement addButton : addButtons) { addButton.click(); } Utils.retryingFind(By.cssSelector(".btn-e")).click(); for (String winHandle : Utils.driver.getWindowHandles()) { Utils.driver.switchTo().window(winHandle); } } catch (Exception e) { e.printStackTrace(); AssertJUnit.fail(e.getMessage()); } } /** * 一级供应室通过添加回收单回收、丢失、报损 * */ @Test public void recyle_recyleAndDropAndScrap() { try { Utils.retryingFind(By.linkText("添加")).click(); Utils.retryingFind(By.linkText("添加器械包")).click(); Utils.driver.switchTo().defaultContent(); WebElement frame = Utils.retryingFind(By.id("xubox_iframe")); Utils.driver.switchTo().frame(frame); Utils.retryingFind( By.id(Utils.settings.getJSONObject("回收查询").getString("按钮1"))) .click(); Utils.retryingFind( By.id(Utils.settings.getJSONObject("回收查询").getString("按钮2"))) .click(); WebElement findElement = Utils.retryingFind(By .linkText(Utils.settings.getJSONObject("一级供应室器械包1") .getString("名称"))); findElement.click(); String recyclingFormWindowhandle = Utils.driver.getWindowHandle(); Utils.driver.switchTo().window(recyclingFormWindowhandle); Wait wait = new FluentWait(Utils.driver) .withTimeout(5000, TimeUnit.MILLISECONDS) .pollingEvery(100, TimeUnit.MILLISECONDS) .ignoring(NoSuchElementException.class); WebElement tousseItemTable = wait .until(new Function() { public WebElement apply(WebDriver driver) { return driver.findElement(By.id("tousseItemTable")); } }); // 扫描科室条码 tousseItemTable.sendKeys(Utils.settings.getJSONObject("临床科室") .getString("条码") + "\n"); // 扫描篮筐条码 tousseItemTable.sendKeys(Utils.settings.getJSONObject("一级供应室清洗篮筐1") .getString("条码") + "\n"); // 扫描篮筐条码 tousseItemTable.sendKeys(Utils.settings.getJSONObject("一级供应室清洗篮筐2") .getString("条码") + "\n"); // 回收入筐增加丢失、报损 List addButtons = tousseItemTable.findElements(By .cssSelector(".btn-a")); for (WebElement addButton : addButtons) { Utils.retryingFind(By.cssSelector(".btn-b")).click(); frame = Utils.retryingFind(By.id("xubox_iframe")); Utils.driver.switchTo().frame(frame); Utils.retryingFind(By.id("recyclingErrorTable")).click(); Utils.retryingFind( By.xpath("//tbody/tr/td/a[contains(text(), '+')]")) .click(); Utils.retryingFind( By.xpath("//tbody/tr/td/a[contains(text(), '确定')]")) .click(); Utils.driver.switchTo().defaultContent(); Utils.retryingFind(By.cssSelector(".btn-c")).click(); frame = Utils.retryingFind(By.id("xubox_iframe")); Utils.driver.switchTo().frame(frame); Utils.retryingFind(By.id("recyclingDamageForm")).click(); Utils.retryingFind(By.cssSelector("a[class=add]")).click(); Utils.retryingFind( By.xpath("//tbody/tr/td/a[contains(text(), '确定')]")) .click(); Utils.driver.switchTo().defaultContent(); addButton.click(); } Utils.retryingFind(By.cssSelector(".divStyle")).click(); frame = Utils.retryingFind(By.id("xubox_iframe")); Utils.driver.switchTo().frame(frame); Utils.retryingFind(By.id("recyclingErrorTable")).click(); Utils.retryingFind( By.xpath("//tbody/tr/td/a[contains(text(), '+')]")).click(); Utils.retryingFind(By.cssSelector("a[class='submit']")).click(); Utils.driver.switchTo().defaultContent(); Utils.retryingFind(By.cssSelector(".btn-e")).click(); } catch (Exception e) { e.printStackTrace(); AssertJUnit.fail(e.getMessage()); } } /** * 一级供应室通过添加回收单回收带标识牌的器械包并丢失、报损 * */ @Test public void recyle_recyleSignboardAndDropAndScrap() { try { Utils.retryingFind(By.linkText("添加")).click(); String recyclingFormWindowhandle = Utils.driver.getWindowHandle(); Utils.driver.switchTo().window(recyclingFormWindowhandle); Wait wait = new FluentWait(Utils.driver) .withTimeout(5000, TimeUnit.MILLISECONDS) .pollingEvery(100, TimeUnit.MILLISECONDS) .ignoring(NoSuchElementException.class); WebElement tousseItemTable = wait .until(new Function() { public WebElement apply(WebDriver driver) { return driver.findElement(By.id("tousseItemTable")); } }); // 扫描科室条码 tousseItemTable.sendKeys(Utils.settings.getJSONObject("临床科室") .getString("条码") + "\n"); scan(tousseItemTable); boolean displayed = false; String a = Utils.settings.getJSONObject("一级供应室清洗篮筐2").getString( "条码"); tousseItemTable.sendKeys(a + "\n"); WebElement element = Utils.retryingFind(By .xpath("//div/div/button/span[contains(text(), '是')]")); if (element != null) { displayed = element.isDisplayed(); } if (displayed) { Utils.retryingFind( By.xpath("//div/div/button/span[contains(text(), '是')]")) .click(); for (String winHandle : Utils.driver.getWindowHandles()) { Utils.driver.switchTo().window(winHandle); } } // 扫描标识牌条码回收入筐 tousseItemTable.sendKeys(Utils.settings.getJSONObject("一级供应室器械包1") .getString("标识牌条码2") + "\n"); // 增加丢失、报损 Utils.retryingFind(By.cssSelector(".btn-b")).click(); WebElement frame = Utils.retryingFind(By.id("xubox_iframe")); Utils.driver.switchTo().frame(frame); Utils.retryingFind(By.id("recyclingErrorTable")).click(); Utils.retryingFind( By.xpath("//tbody/tr/td/a[contains(text(), '+')]")).click(); Utils.retryingFind( By.xpath("//tbody/tr/td/a[contains(text(), '确定')]")) .click(); Utils.driver.switchTo().defaultContent(); Utils.retryingFind(By.cssSelector(".btn-c")).click(); frame = Utils.retryingFind(By.id("xubox_iframe")); Utils.driver.switchTo().frame(frame); Utils.retryingFind(By.id("recyclingDamageForm")).click(); Utils.retryingFind(By.cssSelector("a[class=add]")).click(); Utils.retryingFind( By.xpath("//tbody/tr/td/a[contains(text(), '确定')]")) .click(); Utils.driver.switchTo().defaultContent(); Utils.retryingFind(By.cssSelector(".divStyle")).click(); frame = Utils.retryingFind(By.id("xubox_iframe")); Utils.driver.switchTo().frame(frame); Utils.retryingFind(By.id("recyclingErrorTable")).click(); Utils.retryingFind( By.xpath("//tbody/tr/td/a[contains(text(), '+')]")).click(); Utils.retryingFind(By.cssSelector("a[class='submit']")).click(); Utils.driver.switchTo().defaultContent(); // 扫描篮筐条码 tousseItemTable.sendKeys(Utils.settings.getJSONObject("一级供应室清洗篮筐3") .getString("条码") + "\n"); displayed = false; element = Utils.retryingFind(By .xpath("//div/div/button/span[contains(text(), '是')]")); if (element != null) { displayed = element.isDisplayed(); } if (displayed) { Utils.retryingFind( By.xpath("//div/div/button/span[contains(text(), '是')]")) .click(); for (String winHandle : Utils.driver.getWindowHandles()) { Utils.driver.switchTo().window(winHandle); } } scan(tousseItemTable); Utils.retryingFind(By.cssSelector(".btn-a")).click(); Utils.retryingFind(By.cssSelector(".btn-e")).click(); } catch (Exception e) { e.printStackTrace(); AssertJUnit.fail(e.getMessage()); } } /** * 旧的外来器械回收 * */ @Test public void recyle_oldForeign() { try { Utils.retryingFind(By.id("enterpriseView")).click(); WebElement frame = Utils.retryingFind(By .id("iframe_enterpriseView")); Utils.driver.switchTo().frame(frame); Utils.retryingFind( By.xpath("//div/a/span[contains(text(), '回收清点')]")).click(); Utils.retryingFind(By.cssSelector("a[target='mainFrame']")).click(); frame = Utils.retryingFind(By.id("mainFrame")); Utils.driver.switchTo().frame(frame); Utils.retryingFind( By.xpath("//tbody/tr/td/div[contains(text(), '待接收')]")) .click(); Utils.retryingFind(By.id("editTbar")).click(); String currentwindowhandle = Utils.driver.getWindowHandle(); Utils.driver.switchTo().window(currentwindowhandle); Utils.retryingFind(By.cssSelector("input[name='basketBarcode']")) .sendKeys( Utils.settings.getJSONObject("二级供应室清洗篮筐1") .getString("条码") + "\n"); Utils.retryingFind(By.xpath("//span[contains(text(), '确认接收')]")) .click(); } catch (Exception e) { e.printStackTrace(); AssertJUnit.fail(e.getMessage()); } } /** * 外来器械回收修改材料是否植入物及数量 * */ @Test public void recyle_Foreign() { try { boolean displayed = false; // for (String winHandle : Utils.driver.getWindowHandles()) { // Utils.driver.switchTo().window(winHandle); // } WebElement bodyElement = Utils.retryingFind(By.tagName("body")); // 输入临床科室条码,只显示临床科室的申请单 bodyElement.sendKeys(Utils.settings.getJSONObject("临床科室") .getString("条码") + "\n"); WebElement element = Utils.retryingFind(By.id("tousseItemTable")); if (element != null) { displayed = element.isDisplayed(); } if (displayed) { } else { Utils.retryingFindClickFirstCellOfTable(By .id("awaitForRecycleTable")); } String recyclingFormWindowhandle = Utils.driver.getWindowHandle(); Utils.driver.switchTo().window(recyclingFormWindowhandle); // 获取器械包的器械(材料)清单表格 Wait wait = new FluentWait(Utils.driver) .withTimeout(5000, TimeUnit.MILLISECONDS) .pollingEvery(100, TimeUnit.MILLISECONDS) .ignoring(NoSuchElementException.class); WebElement tousseItemTable = wait .until(new Function() { public WebElement apply(WebDriver driver) { return driver.findElement(By.id("tousseItemTable")); } }); scan(tousseItemTable); tousseItemTable.sendKeys(Utils.settings.getJSONObject("一级供应室清洗篮筐4") .getString("条码") + "\n"); Utils.retryingFind(By.id("showTousseName0")).click(); Utils.driver.switchTo().defaultContent(); WebElement frame = Utils.retryingFind(By.id("xubox_iframe")); Utils.driver.switchTo().frame(frame); Utils.retryingFind(By.id("includeImplant1")).click(); Utils.retryingFind(By.id("amount1")).click(); frame = Utils.retryingFind(By.id("xubox_iframe")); Utils.driver.switchTo().frame(frame); String x = (int) (Math.random() * 8 + 1) + ""; Utils.retryingFind(By.linkText(x)).click(); Utils.retryingFind(By.linkText("6")).click(); Utils.retryingFind(By.cssSelector(".btn-a")).click(); Utils.driver.switchTo().defaultContent(); frame = Utils.retryingFind(By.id("xubox_iframe")); Utils.driver.switchTo().frame(frame); Utils.retryingFind(By.cssSelector("a[class='submit']")).click(); Alert alertBox = Utils.driver.switchTo().alert(); alertBox.accept(); recyclingFormWindowhandle = Utils.driver.getWindowHandle(); Utils.driver.switchTo().window(recyclingFormWindowhandle); List addButtons = tousseItemTable.findElements(By .cssSelector(".btn-a")); for (WebElement addButton : addButtons) { addButton.click(); } Utils.retryingFind(By.cssSelector(".btn-e")).click(); } catch (Exception e) { e.printStackTrace(); AssertJUnit.fail(e.getMessage()); } } /** * 外来器械回收修改数量 * */ @Test public void recyle_Foreign_edit() { try { WebElement bodyElement = Utils.retryingFind(By.tagName("body")); // 输入临床科室条码,只显示临床科室的申请单 bodyElement.sendKeys(Utils.settings.getJSONObject("临床科室") .getString("条码") + "\n"); Utils.retryingFindClickFirstCellOfTable(By .id("awaitForRecycleTable")); String recyclingFormWindowhandle = Utils.driver.getWindowHandle(); Utils.driver.switchTo().window(recyclingFormWindowhandle); // 获取器械包的器械(材料)清单表格 Wait wait = new FluentWait(Utils.driver) .withTimeout(5000, TimeUnit.MILLISECONDS) .pollingEvery(100, TimeUnit.MILLISECONDS) .ignoring(NoSuchElementException.class); WebElement tousseItemTable = wait .until(new Function() { public WebElement apply(WebDriver driver) { return driver.findElement(By.id("tousseItemTable")); } }); scan(tousseItemTable); tousseItemTable.sendKeys(Utils.settings.getJSONObject("一级供应室清洗篮筐4") .getString("条码") + "\n"); boolean displayed = false; WebElement element = Utils.retryingFind(By .xpath("//div/div/button/span[contains(text(), '是')]")); if (element != null) { displayed = element.isDisplayed(); } if (displayed) { Utils.retryingFind( By.xpath("//div/div/button/span[contains(text(), '是')]")) .click(); for (String winHandle : Utils.driver.getWindowHandles()) { Utils.driver.switchTo().window(winHandle); } } Utils.retryingFind(By.id("showTousseName0")).click(); Utils.driver.switchTo().defaultContent(); WebElement frame = Utils.retryingFind(By.id("xubox_iframe")); Utils.driver.switchTo().frame(frame); Utils.retryingFind(By.id("amount1")).click(); frame = Utils.retryingFind(By.id("xubox_iframe")); Utils.driver.switchTo().frame(frame); String x = (int) (Math.random() * 8 + 1) + ""; Utils.retryingFind(By.linkText(x)).click(); Utils.retryingFind(By.linkText("5")).click(); Utils.retryingFind(By.cssSelector(".btn-a")).click(); Utils.driver.switchTo().defaultContent(); frame = Utils.retryingFind(By.id("xubox_iframe")); Utils.driver.switchTo().frame(frame); Utils.retryingFind(By.cssSelector("a[class='submit']")).click(); Alert alertBox = Utils.driver.switchTo().alert(); alertBox.accept(); recyclingFormWindowhandle = Utils.driver.getWindowHandle(); Utils.driver.switchTo().window(recyclingFormWindowhandle); List addButtons = tousseItemTable.findElements(By .cssSelector(".btn-a")); for (WebElement addButton : addButtons) { addButton.click(); } Utils.retryingFind(By.cssSelector(".btn-e")).click(); } catch (Exception e) { e.printStackTrace(); AssertJUnit.fail(e.getMessage()); } } /** * 回收后,修改数量、换篮筐 * */ @Test public void recyle_change() { Actions action = new Actions(Utils.driver); action.click(Utils.retryingFind(By.id("depart"))).perform(); WebElement frame = Utils.retryingFind(By.id("xubox_iframe")); Utils.driver.switchTo().frame(frame); Utils.retryingFind(By.id("buttonX")).click(); String name = Utils.settings.getJSONObject("临床科室").getString("名称"); Utils.retryingFind( By.xpath("//div/ul/li/a[contains(text(), '" + name + "')]")) .click(); String recyclingFormWindowhandle = Utils.driver.getWindowHandle(); Utils.driver.switchTo().window(recyclingFormWindowhandle); Utils.retryingFind(By.id("applicationType")).click(); frame = Utils.retryingFind(By.id("xubox_iframe")); Utils.driver.switchTo().frame(frame); Utils.retryingFind(By.xpath("//div/ul/li/a[contains(text(), '通用申请单')]")) .click(); recyclingFormWindowhandle = Utils.driver.getWindowHandle(); Utils.driver.switchTo().window(recyclingFormWindowhandle); Utils.retryingFind(By.id("recyclingRecordTable")).click(); Utils.retryingFind(By.xpath("//i/a[contains(text(), '删除')]")).click(); Wait wait = new FluentWait(Utils.driver) .withTimeout(5000, TimeUnit.MILLISECONDS) .pollingEvery(100, TimeUnit.MILLISECONDS) .ignoring(NoSuchElementException.class); WebElement tousseItemTable = wait .until(new Function() { public WebElement apply(WebDriver driver) { return driver.findElement(By.id("tousseItemTable")); } }); tousseItemTable.sendKeys(Utils.settings.getJSONObject("一级供应室清洗篮筐1") .getString("条码") + "\n"); List addButtons = tousseItemTable.findElements(By .cssSelector(".btn-a")); for (WebElement addButton : addButtons) { addButton.click(); } Utils.retryingFind(By.cssSelector(".btn-e")).click(); } /** * 快速回收 * */ @Test public void recyle_quickly() { try { Utils.retryingFind(By.xpath("//body/div[1]/div[2]/img[2]")).click(); Wait wait = new FluentWait(Utils.driver) .withTimeout(5000, TimeUnit.MILLISECONDS) .pollingEvery(100, TimeUnit.MILLISECONDS) .ignoring(NoSuchElementException.class); WebElement tousseItemTable = wait .until(new Function() { public WebElement apply(WebDriver driver) { return driver.findElement(By.id("tousseItemTable")); } }); tousseItemTable.sendKeys(Utils.settings.getJSONObject("一级供应室清洗篮筐1") .getString("条码") + "\n"); List addButtons = tousseItemTable.findElements(By .cssSelector(".btn-a")); for (WebElement addButton : addButtons) { addButton.click(); } Utils.retryingFind(By.cssSelector(".btn-e")).click(); for (String winHandle : Utils.driver.getWindowHandles()) { Utils.driver.switchTo().window(winHandle); } String recyclingFormWindowhandle = Utils.driver.getWindowHandle(); Utils.driver.switchTo().window(recyclingFormWindowhandle); Utils.retryingFind(By.cssSelector(".btn-d")).click(); Alert alertBox = Utils.driver.switchTo().alert(); alertBox.accept(); } catch (Exception e) { e.printStackTrace(); AssertJUnit.fail(e.getMessage()); } } /** * 一级供应室丢失后,确认 * */ @Test public void recyle_confirm() { try { WebElement bodyElement = Utils.retryingFind(By.tagName("body")); Utils.retryingFind(By.id("state")).click(); WebElement frame = Utils.retryingFind(By.id("xubox_iframe")); Utils.driver.switchTo().frame(frame); Utils.retryingFind(By.linkText("未确认")).click(); String recyclingFormWindowhandle = Utils.driver.getWindowHandle(); Utils.driver.switchTo().window(recyclingFormWindowhandle); Utils.retryingFind(By.id("recyclingRecordTable")).click(); Utils.retryingFind(By.id("confirmBtnTd")).click(); } catch (Exception e) { e.printStackTrace(); AssertJUnit.fail(e.getMessage()); } } /** * 一级供应室丢失后,确认 * */ @Test public void recyle_confirm_new() { try { WebElement bodyElement = Utils.retryingFind(By.tagName("body")); Utils.retryingFind(By.id("recyclingRecordTable")); Utils.retryingFind(By.cssSelector("tr[bgcolor='#FF8C69']")).click(); Utils.retryingFindClickFirstCellOfTable(By .id("recyclingRecordTable")); Utils.retryingFind(By.id("confirmBtnTd")).click(); } catch (Exception e) { e.printStackTrace(); AssertJUnit.fail(e.getMessage()); } } /** * 二级供应室通过申请单自定义回收 * */ @Test public void recyle_custom() { try { String recyclingFormWindowhandle = Utils.driver.getWindowHandle(); Utils.driver.switchTo().window(recyclingFormWindowhandle); // 获取器械包的器械(材料)清单表格 Wait wait = new FluentWait(Utils.driver) .withTimeout(5000, TimeUnit.MILLISECONDS) .pollingEvery(100, TimeUnit.MILLISECONDS) .ignoring(NoSuchElementException.class); WebElement tousseItemTable = wait .until(new Function() { public WebElement apply(WebDriver driver) { return driver.findElement(By.id("tousseItemTable")); } }); scan(tousseItemTable); Utils.changeCustomWindow(); wait = new FluentWait(Utils.driver) .withTimeout(5000, TimeUnit.MILLISECONDS) .pollingEvery(100, TimeUnit.MILLISECONDS) .ignoring(NoSuchElementException.class); tousseItemTable = wait.until(new Function() { public WebElement apply(WebDriver driver) { return driver.findElement(By.id("tousseItemTable")); } }); tousseItemTable.sendKeys(Utils.settings.getJSONObject("二级供应室清洗篮筐1") .getString("条码") + "\n"); List addButtons = tousseItemTable.findElements(By .cssSelector(".btn-a")); for (WebElement addButton : addButtons) { addButton.click(); } Utils.retryingFind(By.cssSelector(".btn-e")).click(); for (String winHandle : Utils.driver.getWindowHandles()) { Utils.driver.switchTo().window(winHandle); } Utils.retryingFind(By.cssSelector(".btn-e")).click(); } catch (Exception e) { e.printStackTrace(); AssertJUnit.fail(e.getMessage()); } } @AfterMethod public void after() { Utils.driver.quit(); } /** * 获取Html Table的第一个单元格,即第一行第一列的单元格 * * @param table * 表格对象 * @return 单元格对象 */ public WebElement getFirstCellOfTable(WebElement table) { WebElement cell = null; // Now get all the TR elements from the table List allRows = table.findElements(By.tagName("tr")); System.out.println("rows size = " + allRows.size()); if (allRows != null && allRows.size() > 0) { WebElement row = allRows.get(0); // return row; List cells = row.findElements(By.tagName("td")); if (cells != null && cells.size() > 0) { cell = cells.get(0); } } return cell; } /** * 省医回收扫描回收人和清点人 */ public void scan(WebElement table) { try { // 扫描回收人条码 String name = Utils.settings.getJSONObject("回收人").getString("条码"); table.sendKeys(name + "\n"); // for (String winHandle : Utils.driver.getWindowHandles()) { // Utils.driver.switchTo().window(winHandle); // } // String recyclingFormWindowhandle = // Utils.driver.getWindowHandle(); // Utils.driver.switchTo().window(recyclingFormWindowhandle); name = Utils.settings.getJSONObject("清点人").getString("条码"); Thread.sleep(1000); // Utils.retryingFind(By.cssSelector("input[value='清点人员']")) // .click(); // 扫描清点人条码 table.sendKeys(name + "\n"); // for (String winHandle : Utils.driver.getWindowHandles()) { // Utils.driver.switchTo().window(winHandle); // } // recyclingFormWindowhandle = Utils.driver.getWindowHandle(); // Utils.driver.switchTo().window(recyclingFormWindowhandle); // Utils.retryingFind(By.cssSelector("input[value='回收人员']")) // .click(); } catch (Exception e) { e.printStackTrace(); AssertJUnit.fail(e.getMessage()); } } }