JBoss Community Archive (Read Only)

Graphene 2

Delegate to WebElement

It is easy to add all WebElement methods to your custom page fragment, because Graphene supports delegate pattern.

Basic usage

Suppose following page fragment, which implements WebElement.

import org.jboss.arquillian.graphene.fragment.Root;
import org.openqa.selenium.WebElement;

public abstract class MyInputFragment implements WebElement {

    @Root
    private WebElement input;

    public String getInputText() {
        return input.getAttribute("value");
    }

    public String getStyleClass() {
        return input.getAttribute("class");
    }
}

Graphene will ensure that you can call on such a page fragment all WebElement and all your custom methods.

import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.WebDriver;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.arquillian.container.test.api.RunAsClient;
import org.jboss.arquillian.drone.api.annotation.Drone;

@RunWith(Arquillian.class)
@RunAsClient
public class Test {

    @Drone
    private WebDriver browser;

    @FindBy(css = ".foo-bar")
    private MyInputFragment input;

    @Test
    public void testPageFragmentMethodIsDelegatingCorrectly() {
        //page loading, etc.
        
        //WebDriver methods
        input.sendKeys("Graphene rulez!");
        
        //Custom fragment methods
        String value = input.getInputText();
    }
}
JBoss.org Content Archive (Read Only), exported from JBoss Community Documentation Editor at 2020-03-10 12:14:40 UTC, last content change 2014-04-01 09:05:48 UTC.