/** * */ package test_4_1; import java.util.List; 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 { boolean displayed = false; @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.retryingFindAndClick(By.linkText(Utils.settings .getJSONObject("一级供应室装配组").getString("名称2"))); WebElement frame = Utils.retryingFindAndSwitchToFrame(By .id("iframe_reviewPacking")); } catch (Exception e) { e.printStackTrace(); AssertJUnit.fail(e.getMessage()); } } /** * 审核失败 * */ @Test public void Review_fail() { try { Utils.retryingFindAndSendKeys(By.id("barcode"), "44" + "\n"); Utils.retryingFindAndClick(By .xpath("//button/b[contains(text(), '审核并打印标签')]")); } 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.retryingFindAndSendKeys(By.id("barcode"), Utils.reBarcodes.get(i) + "\n"); } Utils.retryingFindAndSendKeys(By.id("barcode"), Utils.settings .getJSONObject("灭菌篮筐01").getString("条码") + "\n"); Utils.retryingFindAndClick(By .xpath("//button/b[contains(text(), '审核')]")); Actions click = new Actions(Utils.driver); WebElement element = Utils.retryingFind(By .xpath("//button[contains(text(), '是')]")); if (element != null) { displayed = element.isDisplayed(); if (displayed) { Utils.retryingFindAndClick(By .xpath("//button[contains(text(), '是')]")); } } Utils.driver.switchTo().defaultContent(); Utils.doWait(1000); Utils.retryingFindAndSwitchToFrame(By.id("iframe_reviewPacking")); String b = null; List allRows = Utils.driver.findElements(By .cssSelector("table[class='x-grid3-row-table']")); System.out.println("rows size = " + allRows.size()); if (allRows.size() > 0) { for (WebElement row : allRows) { b = row.getText(); if (b.length() >= 9) { b = b.trim(); b = b.substring(b.indexOf("0"), b.indexOf("0") + 9); Utils.reBarcodes.add(b); System.out.println("所有装配的条码:" + Utils.reBarcodes); Utils.retryingFindAndSendKeys(By.id("barcode"), b + "\n"); continue; } Utils.retryingFindAndSendKeys( By.id("barcode"), Utils.settings.getJSONObject("灭菌篮筐01").getString( "条码") + "\n"); Utils.retryingFindAndClick(By .xpath("//button/b[contains(text(), '审核')]")); click = new Actions(Utils.driver); element = Utils.retryingFind(By .xpath("//button[contains(text(), '是')]")); if (element != null) { displayed = element.isDisplayed(); if (displayed) { Utils.retryingFindAndClick(By .xpath("//button[contains(text(), '是')]")); } } Utils.driver.switchTo().defaultContent(); Utils.retryingFindAndSwitchToFrame(By .id("iframe_reviewPacking")); Utils.doWait(1000); break; } } } catch (Exception e) { e.printStackTrace(); AssertJUnit.fail(e.getMessage()); } } /** * 批量审核成功 * */ @Test public void Review_batch() { try { Utils.retryingFindAndClick(By .cssSelector("div[class='x-grid3-hd-checker']")); Utils.retryingFindAndClick(By .xpath("//button[contains(text(), '进入审核列表')]")); 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.retryingFindAndClick(By .xpath("//button[contains(text(), '是')]")); } } Utils.driver.switchTo().defaultContent(); WebElement frame = Utils .retryingFind(By.id("iframe_reviewPacking")); Utils.driver.switchTo().frame(frame); Utils.retryingFindAndSendKeys(By.id("barcode"), Utils.settings .getJSONObject("灭菌篮筐01").getString("条码") + "\n"); Utils.retryingFindAndClick(By .xpath("//button/b[contains(text(), '审核')]")); 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(); } }