package test_4_1; import org.testng.annotations.AfterMethod; import org.testng.annotations.Test; import org.testng.annotations.BeforeMethod; import org.testng.AssertJUnit; import java.text.SimpleDateFormat; import java.util.Date; 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 One_use { @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(); } catch (Exception e) { e.printStackTrace(); AssertJUnit.fail(e.getMessage()); } } /** * 一次性物品入库 * */ @Test public void One_use_Entry_success() { try { Utils.retryingFind( By.xpath("//div/a/span[contains(text(), '入库单管理')]")) .click(); 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); String name = Utils.settings.getJSONObject("一级供应室一次性物品").getString( "名称"); for (int i = 1; i < 4; i++) { String x = (int) (Math.random() * 8 + 1) + ""; Utils.retryingFind(By.id("name1")).sendKeys(Keys.DOWN); Utils.retryingFind( By.xpath("//div/div/div[contains(text(), '" + name + "')]")).click(); Utils.retryingFind(By.id("amount1")).clear(); Utils.retryingFind(By.id("amount1")).sendKeys(i + "\n"); Utils.retryingFind(By.id("batchNumber1")).sendKeys( "2017030" + i + "\n"); Utils.retryingFind(By.id("expDate1")).clear(); Utils.retryingFind(By.id("expDate1")).sendKeys( "2020010" + i + "\n"); Utils.retryingFind(By.id("cost1")).clear(); Utils.retryingFind(By.id("cost1")).sendKeys( x + "." + x + x + "\n"); WebElement supplier = Utils.retryingFind(By.id("supplier1")); if (supplier.getText() != null) { supplier.sendKeys(Keys.DOWN); supplier.sendKeys("\n"); } Utils.retryingFind(By.xpath("//button[contains(text(), '添加')]")) .click(); } Utils.retryingFind( By.xpath("//button[contains(text(), '保存并打印新标签')]")).click(); } catch (Exception e) { e.printStackTrace(); AssertJUnit.fail(e.getMessage()); } } /** * 一次性物品退库 * */ @Test public void One_use_cancle_success() { try { Utils.retryingFind( By.xpath("//div/a/span[contains(text(), '退库单管理')]")) .click(); 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("name1")).sendKeys( Utils.settings.getJSONObject("一级供应室一次性物品").getString("名称")); Utils.retryingFind(By.id("name1")).sendKeys("\n"); Utils.retryingFind(By.id("amount1")).sendKeys("1" + "\n"); Utils.retryingFind(By.xpath("//button[contains(text(), '添加')]")) .click(); Utils.retryingFind(By.xpath("//button[contains(text(), '保存')]")) .click(); } catch (Exception e) { e.printStackTrace(); AssertJUnit.fail(e.getMessage()); } } /** * 一次性物品调拨 * */ @Test public void One_use_allot_success() { try { Utils.retryingFind( By.xpath("//div/a/span[contains(text(), '调拨单管理')]")) .click(); 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); String name = Utils.settings.getJSONObject("二级供应室用户").getString( "科室名称"); Utils.retryingFind(By.id("targetWareHouse")).sendKeys(Keys.DOWN); Utils.retryingFind( By.xpath("//div/div/div[contains(text(), '" + name + "')]")) .click(); name = Utils.settings.getJSONObject("一级供应室一次性物品").getString("名称"); Utils.retryingFind(By.id("name1")).sendKeys(Keys.DOWN); Utils.retryingFind( By.xpath("//div/div/div[contains(text(), '" + name + "')]")) .click(); Utils.retryingFind(By.id("amount1")).sendKeys("1" + "\n"); Utils.retryingFind(By.xpath("//button[contains(text(), '添加')]")) .click(); Utils.retryingFind(By.xpath("//button[contains(text(), '保存')]")) .click(); } catch (Exception e) { e.printStackTrace(); AssertJUnit.fail(e.getMessage()); } } /** * 一次性物品盘点 * */ @Test public void One_use_check() { try { Date now = new Date(); SimpleDateFormat dateFormater = new SimpleDateFormat("yyyy-MM-dd"); Utils.retryingFind( By.xpath("//div/a/span[contains(text(), '一次性物品盘点管理')]")) .click(); WebElement frame = Utils.retryingFind(By.id("mainFrame")); Utils.driver.switchTo().frame(frame); Utils.retryingFind(By.xpath("//button[contains(text(), '添加盘点记录')]")) .click(); Utils.retryingFind(By.id("saveBtn")).click(); Utils.retryingFind( By.xpath("//a[contains(text(), '" + dateFormater.format(now) + "')]")).click(); Utils.retryingFind( By.xpath("//button[contains(text(), '盘点数据初始化')]")).click(); } catch (Exception e) { e.printStackTrace(); AssertJUnit.fail(e.getMessage()); } } @AfterMethod public void after() { Utils.driver.quit(); } }