All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cz.datalite.webdriver.ElementFactory Maven / Gradle / Ivy

Go to download

Integration tests with Selenium 2.0 (WebDriver) - PageObjects pattern (still in beta)

The newest version!
package cz.datalite.webdriver;

import cz.datalite.webdriver.components.ZkElement;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

import org.openqa.selenium.WebElement;

/**
 * Factory which creating elements found in HTML
 * according to the style of element.
 *
 *
 * @author Karel Cemus
 */
public class ElementFactory {

    public static  T create( final WebElement element, final ZkElement contextElement ) {
        final String cssClass = element.getAttribute( "class" );
        if ( cssClass != null ) {
            final Set classes = new HashSet( Arrays.asList( cssClass.split( " " ) ) );
            if ( !classes.isEmpty() ) {
                for ( ZkComponents component : ZkComponents.values() ) {
                    if ( classes.contains( component.getStyleClass() ) ) {
                        return ( T ) component.create( contextElement, element );
                    }
                }
            }
        }
        return ( T ) new ZkElement( contextElement, element );
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy