-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hi, I have web application and its implemented using Zkoss, the question is: Can I test it using Selenium WebDriver (recording the objects in the interface)?
Thanks..
<button id="btnOK" class="btnOK_Selenium" label="OK"/>
you can have access in Selenium to the button by using it's class name. If you have already using the class name for a css modification you can add an additionally class name for selenium tests. <.. class="MyButtonCSS btnOK_Selenium" ../>
@FindBy(classname = "btnOK_Selenium")
private WebElement btnOK_Selenium;
/**
* Clicks the OK buttun.
*/
public void clickOKBtn() {
$(this.btnOK_Selenium).click();
}
best Stephan
I have successfully written a Selenium 2 (WebDriver) test against a ZK application. You will face two problems:
1.) You need to implement a ConsistentIDGenerator. 2.) Selenium 2 (WebDriver) does not offer a way to wait for a component to load. So, you end up putting in waits. For that reason, it might be a better idea to use Selenium 1 (RC).
3.) In lieu of the consistent Id generator, you can use things like class names to find components.
package mydomain;
import java.util.concurrent.atomic.AtomicInteger;
import javax.servlet.http.HttpServletResponse;
import org.zkoss.zk.ui.Component; import org.zkoss.zk.ui.Desktop; import org.zkoss.zk.ui.Page; import org.zkoss.zk.ui.metainfo.ComponentInfo; import org.zkoss.zk.ui.sys.IdGenerator;
public class ConsistentIdGenerator implements IdGenerator
{
private static final String ATTRIBUTEGENERATEDID = "generatedId";
private static final String HEADERDESKTOP = "Desktop";
private static final String ZKDESKTOPPREFIX = "zkdt";
private static final String ZKPAGEPREFIX = "zkpage";
private static final String ZKCOMPONENTPREFIX = "zkcomp_";
private static AtomicInteger desktopCounter = new AtomicInteger();
private static AtomicInteger pageCounter = new AtomicInteger();
@Override
public String nextComponentUuid(Desktop desktop, Component comp, ComponentInfo info)
{
if (!desktop.hasAttribute(ATTRIBUTE_GENERATED_ID))
{
desktop.setAttribute(ATTRIBUTE_GENERATED_ID, new AtomicInteger());
}
AtomicInteger componentCounter = (AtomicInteger) desktop.getAttribute(ATTRIBUTE_GENERATED_ID);
return formatId(ZK_COMPONENT_PREFIX, componentCounter);
}
@Override
public String nextPageUuid(Page page)
{
return formatId(ZK_PAGE_PREFIX, pageCounter);
}
@Override
public String nextDesktopId(Desktop desktop)
{
String dtid = formatId(ZK_DESKTOP_PREFIX, desktopCounter);
HttpServletResponse response = (HttpServletResponse) desktop.getExecution().getNativeResponse();
response.addHeader(HEADER_DESKTOP, dtid);
return dtid;
}
private String formatId(String prefix, AtomicInteger counter)
{
return prefix + Integer.toHexString(counter.getAndIncrement());
}
}
The easiest way to test your ZK applications is ZTL. Did you used this product? This is a official tool for testing.
Get best Selenium Online training here!
Asked: 2013-08-22 11:41:07 +0800
Seen: 61 times
Last updated: Mar 08 '18
Do not update to ZK Studio 2.0
Catch Server 503 Error - Or Catch Stale Page
how to save spreadsheet data into postgres database?
One controller file with multiple zul file
Why am I getting authentication error for ZK studio activation?
How can i make Tomcat (with virtual hosts) to parse the zul page in subfolders?