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 Consume { @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("//ul/li/div/a/span[contains(text(), '消毒供应中心物品领用')]")) .click(); } catch (Exception e) { e.printStackTrace(); AssertJUnit.fail(e.getMessage()); } } /** * 领用一次性物品、材料 * */ @Test public void Consume_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("cssdWareHouse")).sendKeys(Keys.DOWN); Utils.retryingFind(By.id("cssdWareHouse")).sendKeys("\n"); String name = Utils.settings.getJSONObject("一级供应室一次性物品").getString( "名称"); Utils.retryingFind(By.id("diposableGoodsName")).sendKeys(name); Utils.retryingFind(By.id("diposableGoodsName")).sendKeys("\n"); Utils.retryingFind(By.id("batchNumber1")).sendKeys(Keys.DOWN); Utils.retryingFind( By.xpath("//div/div[contains(text(), '20160602')]")) .click(); Utils.retryingFind(By.id("diposableGoodsAmount")).sendKeys( "1" + "\n"); Utils.retryingFind(By.id("materialCombo")).sendKeys( Utils.settings.getJSONObject("一级供应室材料").getString("拼音码")); Utils.retryingFind(By.id("materialAmount")).sendKeys("2"); Utils.retryingFind(By.id("materialCombo")).sendKeys("\n"); Utils.retryingFind(By.id("materialAmount")).sendKeys("\n"); Utils.retryingFind(By.xpath("//button[contains(text(), '保存')]")) .click(); } catch (Exception e) { e.printStackTrace(); AssertJUnit.fail(e.getMessage()); } } @AfterMethod public void after() { Utils.driver.quit(); } }