Atanasov_88

demo

Jul 8th, 2016
296
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.09 KB | None | 0 0
  1. package bg.pragmatic.objectmap;
  2.  
  3. import static org.junit.Assert.assertEquals;
  4. import static org.junit.Assert.fail;
  5.  
  6. import java.util.concurrent.TimeUnit;
  7.  
  8. import org.junit.After;
  9. import org.junit.Before;
  10. import org.junit.Test;
  11. import org.openqa.selenium.WebDriver;
  12. import org.openqa.selenium.WebElement;
  13. import org.openqa.selenium.chrome.ChromeDriver;
  14. import org.openqa.selenium.firefox.FirefoxDriver;
  15.  
  16. import bg.pragmatic.objectmap.ObjectMap;
  17.  
  18.  
  19. public class ObjectMapDemo {
  20.    
  21.     private WebDriver driver;
  22.     private StringBuffer verificationErrors = new StringBuffer();
  23.     private ObjectMap map;
  24.        
  25.     @Before
  26.     public void setUp() throws Exception {
  27.         // Create a new instance of the Firefox driver
  28.         System.setProperty("webdriver.chrome.driver", "D:\\workspace\\chromedriver.exe");
  29.         driver = new ChromeDriver();
  30.         driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
  31.         driver.get("http://dl.dropbox.com/u/55228056/bmicalculator.html");
  32.     }
  33.  
  34.     @Test
  35.     public void testBmiCalculator() {
  36.         try {
  37.             //Get the Object Map File
  38.             map = new ObjectMap("D:\\courseworkspace\\objectmap\\src\\test\\resources\\objectmap.properties");
  39.  
  40.            
  41.             //Get the Height element
  42.             WebElement height = driver.findElement(map.getLocator("height_field"));;
  43.             height.sendKeys("181");
  44.  
  45.             //Get the Weight element
  46.             WebElement weight = driver.findElement(map.getLocator("weight_field"));
  47.             weight.sendKeys("80");
  48.    
  49.             //Click on the Calculate button
  50.             WebElement calculateButton = driver.findElement(map.getLocator("calculate_button"));
  51.             calculateButton.click();
  52.            
  53.             //Verify the Bmi
  54.             WebElement bmi = driver.findElement(map.getLocator("bmi_field"));
  55.             assertEquals("24.4", bmi.getAttribute("value"));
  56.            
  57.         } catch (Exception e) {
  58.             //Capture and append Exceptions/Errors
  59.             verificationErrors.append(e.toString());
  60.         }
  61.     }
  62.    
  63.     @After
  64.     public void tearDown() throws Exception {
  65.    
  66.         //Close the browser
  67.         driver.quit();
  68.        
  69.         String verificationErrorString = verificationErrors.toString();
  70.         if (!"".equals(verificationErrorString)) {
  71.             fail(verificationErrorString);
  72.         }
  73.     }
  74. }
Add Comment
Please, Sign In to add comment