Advertisement
Atanasov_88

Untitled

Jul 8th, 2016
398
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.89 KB | None | 0 0
  1. package bg.pragmatic.objectmap;
  2.  
  3. import java.io.FileInputStream;
  4. import java.io.IOException;
  5. import java.util.Properties;
  6.  
  7. import org.openqa.selenium.By;
  8.  
  9. public class ObjectMap {
  10.  
  11.     Properties properties;
  12.    
  13.     public ObjectMap(String mapFile)
  14.     {
  15.         properties = new Properties();
  16.         try {
  17.             FileInputStream in = new FileInputStream(mapFile);
  18.             properties.load(in);
  19.             in.close();
  20.         }catch (IOException e) {
  21.             System.out.println(e.getMessage());
  22.         }
  23.        
  24.     }
  25.     public By getLocator(String logicalElementName) throws Exception
  26.     {
  27.         //Read value using the logical name as Key
  28.         String locator = properties.getProperty(logicalElementName);
  29.         //name>heightCMS
  30.         //Split the value which contains locator type and locator value
  31.         String locatorType = locator.split(">")[0];
  32.         String locatorValue = locator.split(">")[1];
  33.  
  34.         //Return a instance of By class based on type of locator
  35.         if(locatorType.toLowerCase().equals("id"))
  36.             return By.id(locatorValue);
  37.         else if(locatorType.toLowerCase().equals("name"))
  38.             return By.name(locatorValue);
  39.         else if((locatorType.toLowerCase().equals("classname")) || (locatorType.toLowerCase().equals("class")))
  40.             return By.className(locatorValue);
  41.         else if((locatorType.toLowerCase().equals("tagname")) || (locatorType.toLowerCase().equals("tag")))
  42.             return By.tagName(locatorValue);
  43.         else if((locatorType.toLowerCase().equals("linktext")) || (locatorType.toLowerCase().equals("link")))
  44.             return By.linkText(locatorValue);
  45.         else if(locatorType.toLowerCase().equals("partiallinktext"))
  46.             return By.partialLinkText(locatorValue);
  47.         else if((locatorType.toLowerCase().equals("cssselector")) || (locatorType.toLowerCase().equals("css")))
  48.             return By.cssSelector(locatorValue);
  49.         else if(locatorType.toLowerCase().equals("xpath"))
  50.             return By.xpath(locatorValue);
  51.         else
  52.         throw new Exception("Locator type '" + locatorType + "' not defined!!");
  53.     }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement