View Javadoc

1   /**
2    * 
3    */
4   package org.sirius.server.web;
5   
6   import org.openqa.selenium.By;
7   import org.openqa.selenium.WebDriver;
8   import org.openqa.selenium.WebElement;
9   
10  /**
11   * @author Myk Kolisnyk
12   *
13   */
14  public class WebHelper {
15  
16  	/**
17  	 * 
18  	 */
19  	public WebHelper() {
20  		// TODO Auto-generated constructor stub
21  	}
22  
23  	protected WebDriver driver(String token) {
24  		WebDriver driver = DriverMap.drivers.get(token);
25  		return driver;
26  	}
27  
28  	// WebElement wrappers
29  	protected By toLocator(String locator) {
30  		String prefix = locator.split("=")[0];
31  		String value = locator.substring(locator.indexOf("=") + 1);
32  		if (prefix.equals("id")) {
33  			return By.id(value);
34  		} else if (prefix.equals("name")) {
35  			return By.name(value);
36  		} else if (prefix.equals("link")) {
37  			return By.linkText(value);
38  		} else if (prefix.equals("tag")) {
39  			return By.tagName(value);
40  		} else if (prefix.equals("class")) {
41  			return By.className(value);
42  		} else if (prefix.equals("css")) {
43  			return By.cssSelector(value);
44  		} else if (prefix.equals("xpath")) {
45  			return By.xpath(value);
46  		}
47  
48  		return null;
49  	}
50  
51  	protected WebElement getElement(String token, String startFrom, String locator) {
52  		if (startFrom != null) {
53  			return driver(token).findElement(toLocator(startFrom)).findElement(
54  					toLocator(locator));
55  		}
56  		return driver(token).findElement(toLocator(locator));
57  	}
58  }