For my selenium tests I activate the wicket path (set you application in
development mode) and use the following class :

/**
 * Use wicket path dans for selenium tests. <br>
 * 
 *  wicket-selenium <http://www.wijsmullerbros.nl/content/wicket-selenium>  
 *
 */
public final class WicketBy extends By {
    /** xpath expression. */
    private final String xpathExpression;
    /** wicket path. */
    private final String wicketPath;

    /**
     * Creates a new instance of {@link WicketBy}.
     *
     * @param varWicketPath the wicket path (eg: "id1:id2:id3")
     */
    private WicketBy(final String varWicketPath) {
        super();
        this.wicketPath = varWicketPath;
        this.xpathExpression = convert(varWicketPath);
    }

    /**
     * Factory method to create this specific By.
     *
     * @param varWicketPath the wicket path (eg: "id1:id2:id3")
     * @return By of type WicketBy
     */
    public static By wicketPath(final String varWicketPath) {
        return new WicketBy(varWicketPath);
    }

    /**
     * Convertit le wicketpath en regexp xpath.
     *
     * @param varWicketPath
     * @return l'expression pour le xpath
     */
    private String convert(final String varWicketPath) {
        final String renderedPathVal = wicketPath.replaceAll(":", "_");
        return String.format("//*[@wicketpath='%s']", renderedPathVal);
    }

    @Override
    public List<WebElement> findElements(final SearchContext context) {
        return ((FindsByXPath)
context).findElementsByXPath(xpathExpression);
    }

    @Override
    public WebElement findElement(final SearchContext context) {
        return ((FindsByXPath) context).findElementByXPath(xpathExpression);
    }

    @Override
    public String toString() {
        return "By.wicketPath: " + wicketPath + " (xpath: " +
xpathExpression + ")";
    }

}

--
View this message in context: 
http://apache-wicket.1842946.n4.nabble.com/Generated-IDs-tp4677000p4677039.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to