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.retryingFindAndClick(By.id("enterpriseView")); 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.retryingFindAndClick(By.xpath("//button[contains(text(), '添加')]")); String currentwindowhandle = Utils.driver.getWindowHandle(); Utils.driver.switchTo().window(currentwindowhandle); Utils.retryingFindAndSendKeys(By.id("cssdWareHouse"),Keys.DOWN); Utils.retryingFindAndSendKeys(By.id("cssdWareHouse"), "\n"); String name = Utils.settings.getJSONObject("一级供应室一次性物品").getString( "名称"); Utils.retryingFindAndSendKeys(By.id("diposableGoodsName"),name); Utils.retryingFindAndSendKeys(By.id("diposableGoodsName"), "\n"); Utils.retryingFindAndSendKeys(By.id("batchNumber1"),Keys.DOWN); Utils.retryingFind( By.xpath("//div/div[contains(text(), '20160602')]")) .click(); Utils.retryingFindAndSendKeys(By.id("diposableGoodsAmount"), "1" + "\n"); Utils.retryingFindAndSendKeys(By.id("materialCombo"), Utils.settings.getJSONObject("一级供应室材料").getString("拼音码")); Utils.retryingFindAndSendKeys(By.id("materialAmount"), "2"); Utils.retryingFindAndSendKeys(By.id("materialCombo"), "\n"); Utils.retryingFindAndSendKeys(By.id("materialAmount"), "\n"); Utils.retryingFindAndClick(By.xpath("//button[contains(text(), '保存')]")); } catch (Exception e) { e.printStackTrace(); AssertJUnit.fail(e.getMessage()); } } @AfterMethod public void after() { Utils.driver.quit(); } }