/** * */ package test_4_1; 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.WebElement; import org.openqa.selenium.interactions.Actions; import test_4_1.tools.Utils; /** * @author cherry 2016-03-02 * */ public class Review { @BeforeMethod public void init() { try { Utils.init(); Login login = new Login(); login.login_oneSupplyRoom(); Actions moveover = new Actions(Utils.driver); moveover.moveToElement(Utils.retryingFind(By.id("reviewPacking"))) .perform(); Utils.retryingFind( By.linkText(Utils.settings.getJSONObject("一级供应室装配组") .getString("名称1"))).click(); WebElement frame = Utils .retryingFind(By.id("iframe_reviewPacking")); Utils.driver.switchTo().frame(frame); } catch (Exception e) { e.printStackTrace(); AssertJUnit.fail(e.getMessage()); } } /** * 审核失败 * */ @Test public void Review_fail() { try { Utils.retryingFind(By.id("barcode")).sendKeys("44" + "\n"); Utils.retryingFind( By.xpath("//button/b[contains(text(), '审核并打印标签')]")) .click(); } catch (Exception e) { e.printStackTrace(); AssertJUnit.fail(e.getMessage()); } } /** * 扫描条码审核成功 * */ @Test public void Review_single() { try { for (int i = 0; i < Utils.reBarcodes.size(); i++) { Utils.retryingFind(By.id("barcode")).sendKeys( Utils.reBarcodes.get(i) + "\n"); } Utils.retryingFind(By.id("barcode")).sendKeys( Utils.settings.getJSONObject("一级供应室灭菌篮筐1").getString("条码") + "\n"); Utils.retryingFind(By.xpath("//button/b[contains(text(), '审核')]")) .click(); Actions click = new Actions(Utils.driver); click.click( Utils.retryingFind(By .xpath("//button[contains(text(), '是')]"))) .perform(); Utils.driver.switchTo().defaultContent(); WebElement frame = Utils .retryingFind(By.id("iframe_reviewPacking")); Utils.driver.switchTo().frame(frame); String b = null; for (int i = 0; i < 10; i++) { boolean displayed = false; WebElement table = Utils.retryingFind(By .cssSelector("table[class='x-grid3-row-table']")); if (table != null) { displayed = table.isDisplayed(); if (displayed) { b = table.getText(); b = b.trim(); b = b.substring(b.indexOf("0"), b.indexOf("0") + 9); Utils.reBarcodes.add(b); System.out.println("所有装配的条码:" + Utils.reBarcodes); Utils.retryingFind(By.id("barcode")).sendKeys(b + "\n"); Utils.retryingFind(By.id("barcode")).sendKeys( Utils.settings.getJSONObject("一级供应室灭菌篮筐1") .getString("条码") + "\n"); Utils.retryingFind( By.xpath("//button/b[contains(text(), '审核')]")) .click(); click.click( Utils.retryingFind(By .xpath("//button[contains(text(), '是')]"))) .perform(); Utils.driver.switchTo().defaultContent(); frame = Utils.retryingFind(By .id("iframe_reviewPacking")); Utils.driver.switchTo().frame(frame); } } else { break; } } } catch (Exception e) { e.printStackTrace(); AssertJUnit.fail(e.getMessage()); } } /** * 批量审核成功 * */ @Test public void Review_batch() { try { boolean displayed = false; Utils.retryingFind( By.cssSelector("div[class='x-grid3-hd-checker']")).click(); Utils.retryingFind(By.xpath("//button[contains(text(), '进入审核列表')]")) .click(); Utils.driver.switchTo().defaultContent(); Actions click = new Actions(Utils.driver); WebElement element = Utils.retryingFind(By .xpath("//button[contains(text(), '是')]")); if (element != null) { displayed = element.isDisplayed(); if (displayed) { Utils.retryingFind( By.xpath("//button[contains(text(), '是')]")) .click(); } } Utils.driver.switchTo().defaultContent(); WebElement frame = Utils .retryingFind(By.id("iframe_reviewPacking")); Utils.driver.switchTo().frame(frame); Utils.retryingFind(By.id("barcode")).sendKeys( Utils.settings.getJSONObject("一级供应室灭菌篮筐1").getString("条码") + "\n"); Utils.retryingFind(By.xpath("//button/b[contains(text(), '审核')]")) .click(); click.click( Utils.retryingFind(By .xpath("//button[contains(text(), '是')]"))) .perform(); } catch (Exception e) { e.printStackTrace(); AssertJUnit.fail(e.getMessage()); } } @AfterMethod public void after() { Utils.driver.quit(); } }