IDEMPIERE-92 Implement Selenium testing framework. Handle single quote in zk selector.

This commit is contained in:
Heng Sin Low 2013-01-14 14:30:36 +08:00
parent ebb76fd02c
commit f0806d82ab
2 changed files with 16 additions and 4 deletions

View File

@ -37,25 +37,36 @@ public class Widget extends By {
private WebElement findElement(WebDriver driver) { private WebElement findElement(WebDriver driver) {
JavascriptExecutor executor = (JavascriptExecutor) driver; JavascriptExecutor executor = (JavascriptExecutor) driver;
return (WebElement) executor.executeScript("return zk('"+locator+"').$().$n();"); StringBuilder builder = getWidgetLocatorScript(locator);
builder.insert(0, "return ").append(".$n();");
return (WebElement) executor.executeScript(builder.toString());
} }
public WebElement $n(WebDriver driver, String subName) { public WebElement $n(WebDriver driver, String subName) {
JavascriptExecutor executor = (JavascriptExecutor) driver; JavascriptExecutor executor = (JavascriptExecutor) driver;
return (WebElement) executor.executeScript("return zk('"+locator+"').$().$n('"+subName+"');"); StringBuilder builder = getWidgetLocatorScript(locator);
builder.insert(0, "return ")
.append(".$n('").append(subName).append("');");
return (WebElement) executor.executeScript(builder.toString());
} }
public void execute(WebDriver driver, String command) { public void execute(WebDriver driver, String command) {
JavascriptExecutor executor = (JavascriptExecutor) driver; JavascriptExecutor executor = (JavascriptExecutor) driver;
executor.executeScript("zk('"+locator+"').$()."+command+";"); StringBuilder builder = getWidgetLocatorScript(locator);
builder.append(".").append(command).append(";");
executor.executeScript(builder.toString());
} }
public Object eval(WebDriver driver, String command) { public Object eval(WebDriver driver, String command) {
JavascriptExecutor executor = (JavascriptExecutor) driver; JavascriptExecutor executor = (JavascriptExecutor) driver;
return executor.executeScript("return zk('"+locator+"').$()."+command+";"); StringBuilder builder = getWidgetLocatorScript(locator);
builder.insert(0, "return ");
builder.append(".").append(command).append(";");
return executor.executeScript(builder.toString());
} }
public static StringBuilder getWidgetLocatorScript(String locator) { public static StringBuilder getWidgetLocatorScript(String locator) {
locator = locator.replace("'", "\\'");
StringBuilder builder = new StringBuilder("zk('"); StringBuilder builder = new StringBuilder("zk('");
builder.append(locator).append("').$()"); builder.append(locator).append("').$()");
return builder; return builder;

View File

@ -34,6 +34,7 @@ public class Zk {
public List<WebElement> findElements(SearchContext context) { public List<WebElement> findElements(SearchContext context) {
JavascriptExecutor executor = null; JavascriptExecutor executor = null;
String selector = this.selector; String selector = this.selector;
selector = selector.replace("'", "\\'");
if (context instanceof WebDriver) { if (context instanceof WebDriver) {
executor = (JavascriptExecutor) context; executor = (JavascriptExecutor) context;
} else { } else {