Arquillian Graphene 2 nested page fragments

Posted: April 18, 2013 in web

Test class



@RunWith(Arquillian.class)
public class PageIT {

    private final static String CAR_TYPE = "SUV";
    private final static String CAR_VALUE_STRING = "$20.0005";
    private final static String CAR_VALUE = "20.0005";

...
    @Test
    @OperateOnDeployment(WEBAPP_DEPLOYMENT)
    public void quotesCar_CheckCarRate_RateInfoDisplayed() {

...
        Assert.assertEquals("Value not shown",
                quotePage.getUtilityPF(CAR_TYPE).getRatePF(CAR_VALUE).getRateValueString(),
                CAR_VALUE_STRING);
    }
...
}

Page class

public class QuotePage {

    @FindBy(className = "ui-accordion")
    private List<RateUtilityPageFragment> rateUtilitiesPF;

...

    public RateUtilityPageFragment getUtilityPF(String label) {
        for (RateUtilityPageFragment pf : rateUtilitiesPF) {
            if (label.contains(pf.getUtilityLabel())) {
                return pf;
            }
        }
        return null;
    }

...
}

Rate Utility PageFragment

public class RateUtilityPageFragment {

    @Root
    WebElement root;

    @FindBy(tagName = "a")
    private WebElement label;

    @FindBy(css = ".rate-container > .rate")
    private List<RatePageFragment> rateFragments;

    public RatePageFragment getRatePF(String value) {
        for (RatePageFragment pf : rateFragments) {
            if (value.contains(pf.getRateValue())) {
                return pf;
            }
        }
        return null;
    }

    public RatePageFragment getRatePF(int index) {
        return rateFragments.get(index);
    }

    public String getUtilityLabel() {
        return label.getText();
    }
}

Rate PageFragment


public class RatePageFragment {
    @Root
    WebElement root;

    @FindBy(className = "rate-name")
    private WebElement rateName;

    @FindBy(className = "rate-value")
    private WebElement rateValue;

    @FindBy(className = "rate-unit")
    private WebElement rateUnit;

    @FindBy(className = "rate-disclaimer")
    private WebElement rateLoad;

    @FindBy(className = "rate-select")
    private WebElement enterInfo;

    private final static String TERM_DIVIDER = " Month - ";

    public String getRateTermString() {
        return rateName.getText();
    }

    public String getRateTerm() {
        return getTerm(rateName.getText());
    }

    public String getRateType() {
        return getType(rateName.getText());
    }

    public String getRateValueString() {
        return rateValue.getText();
    }

    public String getRateValue() {
        return getValue(rateValue.getText());
    }

    public String getRateUnit() {
        return rateUnit.getText();
    }

    public String getRateLoad() {
        return rateLoad.getText();
    }

    public String getEnterInfoString() {
        return enterInfo.getText();
    }

    public WebElement getEnterInfoWE() {
        return enterInfo;
    }

    private String getTerm(String string) {
        return string.split(TERM_DIVIDER)[0];
    }

    private String getType(String string) {
        return string.split(TERM_DIVIDER)[1];
    }

    private String getValue(String string) {
        Pattern pattern = Pattern.compile("(\\d+\\.\\d+)|(\\d+)");
        Matcher matcher = pattern.matcher(string);
        matcher.find();
        return matcher.group();
    }

}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s