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.Keys; import org.openqa.selenium.WebElement; import test_4_1.tools.Utils; /** * @author cherry 2016-06-01 * */ public class Reject { @BeforeMethod public void init() { try { Utils.init(); Login login = new Login(); login.login_oneSupplyRoom(); Utils.retryingFind(By.id("enterpriseView")).click(); WebElement frame = Utils.retryingFind(By .id("iframe_enterpriseView")); Utils.driver.switchTo().frame(frame); Utils.retryingFind( By.xpath("//div/span[contains(text(), '后台监控管理')]")).click(); Utils.retryingFind( By.xpath("//div/a/span[contains(text(), '退货记录管理')]")) .click(); Utils.retryingFind( By.xpath("//div/a/span[contains(text(), '退货记录信息')]")) .click(); } catch (Exception e) { e.printStackTrace(); AssertJUnit.fail(e.getMessage()); } } /** * 一次性物品退货 * */ @Test public void Reject_one_use_success() { try { WebElement frame = Utils.retryingFind(By.id("mainFrame")); Utils.driver.switchTo().frame(frame); Utils.retryingFind( By.xpath("//button[contains(text(), '一次性物品退货')]")).click(); String currentwindowhandle = Utils.driver.getWindowHandle(); Utils.driver.switchTo().window(currentwindowhandle); Utils.retryingFind(By.id("depart")).sendKeys(Keys.DOWN); String name = Utils.settings.getJSONObject("临床科室").getString("名称"); Utils.retryingFind( By.xpath("//div/div/div[contains(text(), '" + name + "')]")) .click(); Utils.retryingFind(By.id("warehouse")).sendKeys(Keys.DOWN); name = Utils.settings.getJSONObject("一级供应室用户").getString("科室名称"); Utils.retryingFind( By.xpath("//div/div/div[contains(text(), '" + name + "')]")) .click(); Utils.retryingFind(By.id("barcode")).sendKeys( Utils.settings.getJSONObject("一级供应室一次性物品").getString("条码1") + "\n"); Utils.retryingFind(By.xpath("//button[contains(text(), '添加')]")) .click(); Utils.retryingFind(By.id("barcode")).sendKeys( Utils.settings.getJSONObject("一级供应室一次性物品").getString("条码2") + "\n"); Utils.retryingFind(By.xpath("//button[contains(text(), '添加')]")) .click(); Utils.retryingFind(By.id("barcode")).sendKeys( Utils.settings.getJSONObject("一级供应室一次性物品").getString("条码3") + "\n"); Utils.retryingFind(By.xpath("//button[contains(text(), '添加')]")) .click(); Utils.retryingFind(By.xpath("//button[contains(text(), '保存')]")) .click(); currentwindowhandle = Utils.driver.getWindowHandle(); Utils.driver.switchTo().window(currentwindowhandle); Utils.retryingFind(By.xpath("//button[contains(text(), '是')]")) .click(); } catch (Exception e) { e.printStackTrace(); AssertJUnit.fail(e.getMessage()); } } /** * 材料退货 * */ @Test public void Reject_Mateials_success() { try { Utils.driver.navigate().refresh(); String currentwindowhandle = Utils.driver.getWindowHandle(); Utils.driver.switchTo().window(currentwindowhandle); Utils.tryToCloseWarningWindow(); Utils.retryingFind(By.id("enterpriseView")).click(); WebElement frame = Utils.retryingFind(By .id("iframe_enterpriseView")); Utils.driver.switchTo().frame(frame); Utils.retryingFind( By.xpath("//div/span[contains(text(), '后台监控管理')]")).click(); Utils.retryingFind( By.xpath("//div/a/span[contains(text(), '退货记录管理')]")) .click(); Utils.retryingFind( By.xpath("//div/a/span[contains(text(), '材料退货记录')]")) .click(); frame = Utils.retryingFind(By.id("mainFrame")); Utils.driver.switchTo().frame(frame); Utils.retryingFind(By.xpath("//button[contains(text(), '添加')]")) .click(); currentwindowhandle = Utils.driver.getWindowHandle(); Utils.driver.switchTo().window(currentwindowhandle); String name = Utils.settings.getJSONObject("临床科室").getString("名称"); Utils.retryingFind(By.id("depart")).sendKeys(Keys.DOWN); Utils.retryingFind( By.xpath("//div/div/div[contains(text(), '" + name + "')]")) .click(); Utils.retryingFind(By.id("warehouse")).sendKeys(Keys.DOWN + "\n"); Utils.retryingFind(By.id("package1")).sendKeys( Utils.settings.getJSONObject("一级供应室材料").getString("拼音码")); Utils.retryingFind(By.id("package1")).sendKeys("\n"); Utils.retryingFind(By.id("count1")).sendKeys("1" + "\n"); Utils.retryingFind(By.xpath("//button[contains(text(), '保存')]")) .click(); currentwindowhandle = Utils.driver.getWindowHandle(); Utils.driver.switchTo().window(currentwindowhandle); Utils.retryingFind(By.xpath("//button[contains(text(), '是')]")) .click(); } catch (Exception e) { e.printStackTrace(); AssertJUnit.fail(e.getMessage()); } } /** * 器械包退货 * */ @Test public void Reject_set_success() { try { WebElement frame = Utils.retryingFind(By.id("mainFrame")); Utils.driver.switchTo().frame(frame); Utils.retryingFind(By.xpath("//button[contains(text(), '器械包退货')]")) .click(); String currentwindowhandle = Utils.driver.getWindowHandle(); Utils.driver.switchTo().window(currentwindowhandle); for (int i = 0; i < Utils.reBarcodes.size(); i++) { Utils.retryingFind(By.id("barcode")).sendKeys( Utils.reBarcodes.get(i) + "\n"); } String name = Utils.settings.getJSONObject("一级供应室器械包3").getString( "名称"); Utils.retryingFind(By.id("package1")).sendKeys(Keys.DOWN); Utils.retryingFind( By.xpath("//div/div/div[contains(text(), '" + name + "')]")) .click(); Utils.retryingFind(By.id("count1")).sendKeys("1" + "\n"); Utils.retryingFind(By.xpath("//button[contains(text(), '保存')]")) .click(); currentwindowhandle = Utils.driver.getWindowHandle(); Utils.driver.switchTo().window(currentwindowhandle); Utils.retryingFind(By.xpath("//button[contains(text(), '是')]")) .click(); } catch (Exception e) { e.printStackTrace(); AssertJUnit.fail(e.getMessage()); } } /** * 器械包退货取偶数 * */ @Test public void Reject_set_success_ou() { try { WebElement frame = Utils.retryingFind(By.id("mainFrame")); Utils.driver.switchTo().frame(frame); Utils.retryingFind(By.xpath("//button[contains(text(), '器械包退货')]")) .click(); String currentwindowhandle = Utils.driver.getWindowHandle(); Utils.driver.switchTo().window(currentwindowhandle); for (int i = 0; i < Utils.reBarcodes.size(); i++) { int a = Integer.valueOf(Utils.reBarcodes.get(i)).intValue(); if (a % 2 == 0) { Utils.retryingFind(By.id("barcode")).sendKeys( Utils.reBarcodes.get(i) + "\n"); } } String name = Utils.settings.getJSONObject("一级供应室器械包3").getString( "拼音码"); Utils.retryingFind(By.id("package1")).sendKeys(name); Utils.retryingFind(By.id("package1")).sendKeys("\n"); Utils.retryingFind(By.id("count1")).sendKeys("1"); Utils.retryingFind(By.id("count1")).sendKeys("\n"); Utils.retryingFind(By.xpath("//button[contains(text(), '保存')]")) .click(); currentwindowhandle = Utils.driver.getWindowHandle(); Utils.driver.switchTo().window(currentwindowhandle); Utils.retryingFind(By.xpath("//button[contains(text(), '是')]")) .click(); } catch (Exception e) { e.printStackTrace(); AssertJUnit.fail(e.getMessage()); } } @AfterMethod public void after() { Utils.driver.quit(); } }