/** * */ package test_4_1; import java.util.NoSuchElementException; import java.util.concurrent.TimeUnit; import org.testng.annotations.AfterMethod; import org.testng.annotations.Test; import org.testng.annotations.BeforeMethod; import org.testng.AssertJUnit; 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; /** * @author cherry 2016-03-01 * */ public class Wash { @BeforeMethod public void init() { try { Utils.init(); Login login = new Login(); login.login_oneSupplyRoom(); Utils.retryingFindAndClick(By.id("washAndDisinfect")); for (String winHandle : Utils.driver.getWindowHandles()) { Utils.driver.switchTo().window(winHandle); } WebElement frame = Utils.retryingFindAndSwitchToFrame(By .id("iframe_washAndDisinfect")); Utils.retryingFindAndClick(By .xpath("//button[contains(text(), '添加')]")); Utils.driver.switchTo().defaultContent(); String currentwindowhandle = Utils.driver.getWindowHandle(); Utils.driver.switchTo().window(currentwindowhandle); } catch (Exception e) { e.printStackTrace(); AssertJUnit.fail(e.getMessage()); } } /** * 清洗失败 */ // @Test // public void wash_fail() { // try { // Utils.retryingFindAndSendKeys(By.id("inputText"), // "error" + "\n"); // // Utils.retryingFindAndClick(By.id("saveBtn")); // } catch (Exception e) { // e.printStackTrace(); // AssertJUnit.fail(e.getMessage()); // } // } /** * 触摸屏清洗,清洗前,清洗机需要设置为不需要清洗确认 */ @Test public void wash_touch() { try { Utils.init(); Login login = new Login(); Utils.driver.get(Utils.settings.get("触摸屏清洗服务地址").toString()); login.login_touch(); Utils.retryingFindAndSendKeys(By.id("personInCharge"), Utils.settings.getJSONObject("一级供应室用户").getString("条码") + "\n"); Utils.retryingFindAndSendKeys(By.id("disinfectIdentification"), Utils.settings.getJSONObject("一级供应室清洗机").getString("清洗机条码") + "\n"); Utils.retryingFindAndSendKeys(By.id("disinfectProgram"), Utils.settings.getJSONObject("一级供应室清洗机") .getString("清洗程序条码") + "\n"); Utils.retryingFindAndSendKeys(By.id("recyclingRecordForm"), "888888888" + "\n"); Utils.retryingFindAndSendKeys(By.id("personInCharge"), Utils.settings.getJSONObject("一级供应室用户").getString("条码") + "\n"); Utils.retryingFindAndSendKeys(By.id("disinfectIdentification"), Utils.settings.getJSONObject("一级供应室清洗机").getString("清洗机条码") + "\n"); Utils.retryingFindAndSendKeys(By.id("disinfectProgram"), Utils.settings.getJSONObject("一级供应室清洗机") .getString("清洗程序条码") + "\n"); Utils.retryingFindAndSendKeys(By.id("recyclingRecordForm"), Utils.settings.getJSONObject("一级供应室清洗篮筐1").getString("条码") + "\n"); Utils.retryingFindAndSendKeys(By.id("recyclingRecordForm"), Utils.settings.getJSONObject("一级供应室清洗篮筐2").getString("条码") + "\n"); Utils.retryingFindAndSendKeys(By.id("recyclingRecordForm"), Utils.settings.getJSONObject("一级供应室清洗篮筐3").getString("条码") + "\n"); Utils.retryingFindAndSendKeys(By.id("recyclingRecordForm"), Utils.settings.getJSONObject("一级供应室清洗篮筐4").getString("条码") + "\n"); Utils.retryingFindAndSendKeys(By.id("recyclingRecordForm"), "999999999" + "\n"); } catch (Exception e) { e.printStackTrace(); AssertJUnit.fail(e.getMessage()); } } /** * 一级供应室清洗并清洗添加材料 */ @Test public void wash_oneSupplyRoom() { // int x=(int)(Math.random()*10000); try { Utils.retryingFindAndSendKeys(By.id("inputText"), Utils.settings .getJSONObject("一级供应室清洗机").getString("清洗机条码") + "\n"); Utils.retryingFindAndSendKeys(By.id("inputText"), Utils.settings .getJSONObject("一级供应室清洗机").getString("清洗程序条码") + "\n"); Utils.retryingFindAndSendKeys(By.id("inputText"), Utils.settings .getJSONObject("一级供应室审核人").getString("条码") + "\n"); Utils.retryingFindAndSendKeys(By.id("inputText"), Utils.settings .getJSONObject("一级供应室清洗篮筐1").getString("条码") + "\n"); Utils.retryingFindAndSendKeys(By.id("inputText"), Utils.settings .getJSONObject("一级供应室清洗篮筐2").getString("条码") + "\n"); // Utils.retryingFindAndSendKeys(By.id("inputText"), // Utils.settings.getJSONObject("一级供应室清洗篮筐3").getString("条码") // + "\n"); // Utils.retryingFindAndSendKeys(By.id("inputText"), // Utils.settings.getJSONObject("一级供应室清洗篮筐4").getString("条码") // + "\n"); wash_washAddMaterial(); // Date now = new Date(); // System.out.println(now); // SimpleDateFormat dateFormater = new // SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); // System.out.print(dateFormater.format(now)); // Utils.retryingFind(By.id("endDateStr")).clear(); // Utils.retryingFindAndSendKeys(By.id("endDateStr"),dateFormater.format(now)+""); // Utils.retryingFindAndClick(By.id("saveBtn")); } catch (Exception e) { e.printStackTrace(); AssertJUnit.fail(e.getMessage()); } } /** * 清洗记录,需要确认完成,清洗机需要设置为清洗确认 */ @Test public void wash_needConfirmFinish() { try { Utils.retryingFindAndSendKeys(By.id("inputText"), Utils.settings .getJSONObject("一级供应室清洗机1").getString("清洗机条码") + "\n"); Utils.retryingFindAndSendKeys(By.id("inputText"), Utils.settings .getJSONObject("一级供应室清洗机1").getString("清洗程序条码") + "\n"); Utils.retryingFindAndSendKeys(By.id("inputText"), Utils.settings .getJSONObject("一级供应室审核人").getString("条码") + "\n"); Utils.retryingFindAndSendKeys(By.id("inputText"), Utils.settings .getJSONObject("一级供应室清洗篮筐1").getString("条码") + "\n"); Utils.retryingFindAndClick(By.id("saveBtn")); // 定位回来 Utils.retryingFindAndSwitchToFrame(By.id("iframe_washAndDisinfect")); // 需要判断表单提交成功且返回正常后才能结束,否则就将不会提交到后台 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("washSaveSubmitResult")), "value", "1")); // Utils.retryingFindAndClick(By.cssSelector("p[style='background-color:yellow']")); // Thread.sleep(2000); Utils.retryingFindAndClick(By.xpath("//p[contains(text(), '清洗中')]")); Utils.retryingFindAndClick(By .xpath("//button[contains(text(), '清洗完成')]")); // Thread.sleep(2000); Utils.driver.switchTo().defaultContent(); String currentwindowhandle = Utils.driver.getWindowHandle(); Utils.driver.switchTo().window(currentwindowhandle); Utils.retryingFindAndClick(By .xpath("//button[contains(text(), '是')]")); // 定位回来 Utils.retryingFindAndSwitchToFrame(By.id("iframe_washAndDisinfect")); // 需要判断表单提交成功且返回正常后才能结束,否则就将不会提交到后台 Wait wait1 = new FluentWait(Utils.driver) .withTimeout(5000, TimeUnit.MILLISECONDS) .pollingEvery(250, TimeUnit.MILLISECONDS) .ignoring(NoSuchElementException.class) .ignoring(StaleElementReferenceException.class); wait1.until(ExpectedConditions.attributeToBe( Utils.driver.findElement(By.id("washSaveConfirm")), "value", "1")); } catch (Exception e) { e.printStackTrace(); AssertJUnit.fail(e.getMessage()); } } /** * 清洗失败,重新清洗,清洗完成,清洗机需要设置为清洗确认 */ @Test public void wash_fail_reWash_Finish() { try { Utils.retryingFindAndSendKeys(By.id("inputText"), Utils.settings .getJSONObject("一级供应室清洗机1").getString("清洗机条码") + "\n"); Utils.retryingFindAndSendKeys(By.id("inputText"), Utils.settings .getJSONObject("一级供应室清洗机1").getString("清洗程序条码") + "\n"); Utils.retryingFindAndSendKeys(By.id("inputText"), Utils.settings .getJSONObject("一级供应室审核人").getString("条码") + "\n"); Utils.retryingFindAndSendKeys(By.id("inputText"), Utils.settings .getJSONObject("一级供应室清洗篮筐4").getString("条码") + "\n"); Utils.retryingFindAndClick(By.id("saveBtn")); // 定位回来 Utils.retryingFindAndSwitchToFrame(By.id("iframe_washAndDisinfect")); // 需要判断表单提交成功且返回正常后才能结束,否则就将不会提交到后台 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("washSaveSubmitResult")), "value", "1")); // Utils.retryingFindAndClick(By.cssSelector("p[style='background-color:yellow']")); // Thread.sleep(2000); Utils.retryingFindAndClick(By.xpath("//p[contains(text(), '清洗中')]")); Utils.retryingFindAndClick(By .xpath("//button[contains(text(), '清洗失败')]")); // Thread.sleep(2000); Utils.driver.switchTo().defaultContent(); String currentwindowhandle = Utils.driver.getWindowHandle(); Utils.driver.switchTo().window(currentwindowhandle); Utils.retryingFindAndClick(By .xpath("//button[contains(text(), '是')]")); // 定位回来 Utils.retryingFindAndSwitchToFrame(By.id("iframe_washAndDisinfect")); // 需要判断表单提交成功且返回正常后才能结束,否则就将不会提交到后台 Wait wait1 = new FluentWait(Utils.driver) .withTimeout(5000, TimeUnit.MILLISECONDS) .pollingEvery(250, TimeUnit.MILLISECONDS) .ignoring(NoSuchElementException.class) .ignoring(StaleElementReferenceException.class); wait1.until(ExpectedConditions.attributeToBe( Utils.driver.findElement(By.id("washSaveConfirm")), "value", "1")); Utils.driver.switchTo().defaultContent(); currentwindowhandle = Utils.driver.getWindowHandle(); Utils.driver.switchTo().window(currentwindowhandle); // 扫描篮筐条码,录质量监测记录 Utils.retryingFindAndSendKeys(By.id("formName"), Keys.DOWN); Utils.retryingFindAndClick(By.xpath("//div[contains(text(), '无')]")); WebElement element = Utils.retryingFind(By.id("scanBarcode")); boolean displayed = false; if (element != null) { displayed = element.isDisplayed(); if (displayed) { Utils.retryingFindAndSendKeys(By.id("scanBarcode"), Utils.settings.getJSONObject("一级供应室清洗篮筐4") .getString("条码") + "\n"); } } // 质量监测保存 Utils.retryingFindAndClick(By .xpath("//button[contains(text(), '保存')]")); Utils.retryingFindAndSwitchToFrame(By.id("iframe_washAndDisinfect")); // 重新清洗 Utils.retryingFindAndClick(By .xpath("//p[contains(text(), '清洗失败')]")); Utils.retryingFindAndClick(By .xpath("//button[contains(text(), '修改')]")); Utils.driver.switchTo().defaultContent(); currentwindowhandle = Utils.driver.getWindowHandle(); Utils.driver.switchTo().window(currentwindowhandle); Utils.retryingFindAndClick(By .xpath("//button[contains(text(), '重新清洗')]")); Utils.retryingFindAndSwitchToFrame(By.id("iframe_washAndDisinfect")); Utils.retryingFindAndClick(By.xpath("//p[contains(text(), '清洗中')]")); // 重新清洗后完成 Utils.retryingFindAndClick(By .xpath("//button[contains(text(), '清洗完成')]")); // Thread.sleep(2000); Utils.driver.switchTo().defaultContent(); currentwindowhandle = Utils.driver.getWindowHandle(); Utils.driver.switchTo().window(currentwindowhandle); Utils.retryingFindAndClick(By .xpath("//button[contains(text(), '是')]")); // 定位回来 Utils.retryingFindAndSwitchToFrame(By.id("iframe_washAndDisinfect")); // 需要判断表单提交成功且返回正常后才能结束,否则就将不会提交到后台 Wait wait2 = new FluentWait(Utils.driver) .withTimeout(5000, TimeUnit.MILLISECONDS) .pollingEvery(250, TimeUnit.MILLISECONDS) .ignoring(NoSuchElementException.class) .ignoring(StaleElementReferenceException.class); wait2.until(ExpectedConditions.attributeToBe( Utils.driver.findElement(By.id("washSaveConfirm")), "value", "1")); } catch (Exception e) { e.printStackTrace(); AssertJUnit.fail(e.getMessage()); } } /* * 清洗添加材料 */ @Test public void wash_washAddMaterial() { try { // Utils.retryingFindAndSendKeys(By.id("inputText"), // Utils.settings.getJSONObject("一级供应室清洗机").getString("清洗机条码") // + "\n"); // Utils.retryingFindAndSendKeys(By.id("inputText"), // Utils.settings.getJSONObject("一级供应室清洗机") // .getString("清洗程序条码") + "\n"); // Utils.retryingFindAndSendKeys(By.id("inputText"), // Utils.settings.getJSONObject("一级供应室审核人").getString("条码") // + "\n"); // Utils.retryingFindAndSendKeys(By.id("materialName"), Keys.DOWN); Utils.retryingFindAndClick(By.xpath("//div[contains(text(),'" + Utils.settings.getJSONObject("一级供应室材料").getString("名称") + "')]")); // Utils.retryingFindAndSendKeys(By.id("materialName"), // Utils.settings.getJSONObject("一级供应室材料").getString("名称") + "\n"); // Utils.retryingFindAndSendKeys( // By.id("materialAmount"), // Keys.DOWN); Utils.retryingFindAndSendKeys(By.id("materialAmount"), "2" + "\n"); // Utils.retryingFindAndClick(By.id("addMaterialId")); // Thread.sleep(2000); // Utils.retryingFindAndSendKeys(By.id("inputText"), // Utils.settings.getJSONObject("一级供应室清洗篮筐1").getString("条码") // + "\n"); Utils.retryingFindAndClick(By.id("saveBtn")); // 定位回来 Utils.retryingFindAndSwitchToFrame(By.id("iframe_washAndDisinfect")); // 需要判断表单提交成功且返回正常后才能结束,否则就将不会提交到后台 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("washSaveSubmitResult")), "value", "1")); } catch (Exception e) { e.printStackTrace(); } } /* * 清洗删除篮筐再添加篮筐,扫描不同的责任人 */ @Test public void wash_washChangeBasket() { Utils.retryingFindAndSendKeys(By.id("inputText"), Utils.settings .getJSONObject("一级供应室清洗机").getString("清洗机条码") + "\n"); Utils.retryingFindAndSendKeys(By.id("inputText"), Utils.settings .getJSONObject("一级供应室清洗机").getString("清洗程序条码") + "\n"); Utils.retryingFindAndSendKeys(By.id("inputText"), Utils.settings .getJSONObject("一级供应室清洗篮筐3").getString("条码") + "\n"); // 扫描责任人 Utils.retryingFindAndSendKeys(By.id("inputText"), Utils.settings .getJSONObject("一级供应室审核人").getString("条码") + "\n"); // 删除篮筐 Utils.retryingFindAndClick(By .cssSelector("img[src='/images/web/stop.png']")); // 重新扫描篮筐 Utils.retryingFindAndSendKeys(By.id("inputText"), Utils.settings .getJSONObject("一级供应室清洗篮筐3").getString("条码") + "\n"); String basketName = Utils.settings.getJSONObject("一级供应室清洗篮筐3") .getString("名称"); Utils.retryingFindAndClick(By.xpath("//span[contains(text(), '" + basketName + "')]")); // 一级供应室配包人 Utils.retryingFindAndSendKeys(By.id("inputText"), Utils.settings .getJSONObject("一级供应室配包人").getString("条码") + "\n"); Utils.retryingFindAndClick(By.id("saveBtn")); // 定位回来 Utils.retryingFindAndSwitchToFrame(By.id("iframe_washAndDisinfect")); // 需要判断表单提交成功且返回正常后才能结束,否则就将不会提交到后台 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("washSaveSubmitResult")), "value", "1")); } /** * 二级供应室清洗成功 */ @Test public void wash_secondSupplyRoom() { try { // 二级供应室用户登录 oruser1 Utils.init(); Login login = new Login(); login.login_secondSupplyRoom(); Utils.retryingFindAndClick(By.id("washAndDisinfect")); for (String winHandle : Utils.driver.getWindowHandles()) { Utils.driver.switchTo().window(winHandle); } WebElement frame = Utils.retryingFindAndSwitchToFrame(By .id("iframe_washAndDisinfect")); Utils.retryingFindAndClick(By .xpath("//button[contains(text(), '添加')]")); Utils.driver.switchTo().defaultContent(); String currentwindowhandle = Utils.driver.getWindowHandle(); Utils.driver.switchTo().window(currentwindowhandle); Utils.retryingFindAndSendKeys(By.id("inputText"), Utils.settings .getJSONObject("二级供应室清洗机").getString("清洗机条码") + "\n"); Utils.retryingFindAndSendKeys(By.id("inputText"), Utils.settings .getJSONObject("二级供应室清洗机").getString("清洗程序条码") + "\n"); Utils.retryingFindAndSendKeys(By.id("inputText"), Utils.settings .getJSONObject("二级供应室审核人").getString("条码") + "\n"); Utils.retryingFindAndSendKeys(By.id("inputText"), Utils.settings .getJSONObject("二级供应室清洗篮筐1").getString("条码") + "\n"); // Utils.retryingFindAndSendKeys(By.id("cycleCounter"),x+"\n"); Utils.retryingFindAndClick(By.id("saveBtn")); // 定位回来 Utils.retryingFindAndSwitchToFrame(By.id("iframe_washAndDisinfect")); // 需要判断表单提交成功且返回正常后才能结束,否则就将不会提交到后台 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("washSaveSubmitResult")), "value", "1")); } catch (Exception e) { e.printStackTrace(); AssertJUnit.fail(e.getMessage()); } } @AfterMethod public void after() { Utils.driver.quit(); } }