Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package bg.pragmatic.objectmap;
- import static org.junit.Assert.assertEquals;
- import static org.junit.Assert.fail;
- import java.util.concurrent.TimeUnit;
- import org.junit.After;
- import org.junit.Before;
- import org.junit.Test;
- import org.openqa.selenium.WebDriver;
- import org.openqa.selenium.WebElement;
- import org.openqa.selenium.chrome.ChromeDriver;
- import org.openqa.selenium.firefox.FirefoxDriver;
- import bg.pragmatic.objectmap.ObjectMap;
- public class ObjectMapDemo {
- private WebDriver driver;
- private StringBuffer verificationErrors = new StringBuffer();
- private ObjectMap map;
- @Before
- public void setUp() throws Exception {
- // Create a new instance of the Firefox driver
- System.setProperty("webdriver.chrome.driver", "D:\\workspace\\chromedriver.exe");
- driver = new ChromeDriver();
- driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
- driver.get("http://dl.dropbox.com/u/55228056/bmicalculator.html");
- }
- @Test
- public void testBmiCalculator() {
- try {
- //Get the Object Map File
- map = new ObjectMap("D:\\courseworkspace\\objectmap\\src\\test\\resources\\objectmap.properties");
- //Get the Height element
- WebElement height = driver.findElement(map.getLocator("height_field"));;
- height.sendKeys("181");
- //Get the Weight element
- WebElement weight = driver.findElement(map.getLocator("weight_field"));
- weight.sendKeys("80");
- //Click on the Calculate button
- WebElement calculateButton = driver.findElement(map.getLocator("calculate_button"));
- calculateButton.click();
- //Verify the Bmi
- WebElement bmi = driver.findElement(map.getLocator("bmi_field"));
- assertEquals("24.4", bmi.getAttribute("value"));
- } catch (Exception e) {
- //Capture and append Exceptions/Errors
- verificationErrors.append(e.toString());
- }
- }
- @After
- public void tearDown() throws Exception {
- //Close the browser
- driver.quit();
- String verificationErrorString = verificationErrors.toString();
- if (!"".equals(verificationErrorString)) {
- fail(verificationErrorString);
- }
- }
- }
Add Comment
Please, Sign In to add comment