[arquillian-issues] [JBoss JIRA] (ARQGRA-74) Support Graphene utility in original scope with Selenium 2
Jan Papousek (JIRA)
jira-events at lists.jboss.org
Tue Jul 24 11:08:06 EDT 2012
[ https://issues.jboss.org/browse/ARQGRA-74?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12707569#comment-12707569 ]
Jan Papousek commented on ARQGRA-74:
------------------------------------
*My proposal:*
{code:title=Graphene.java}
public class Graphene {
protected static final int WAIT_MODEL_INTERVAL = 5;
protected static final long WAIT_FOR_STALE_ELEMENT_IN_MS = 100;
protected static final int NUM_OF_TRIES_FOR_STALE_ELEMENT = 5;
public static AttributeConditionFactory attribute(WebElement element, String attribute) {
return new AttributeConditionFactory(element, attribute);
}
public static ElementConditionFactory element(WebElement element) {
return new ElementConditionFactory(element);
}
public static <T> T initElements(T target) {
return initElements(GrapheneContext.getProxy(), target);
}
public static <T> T initElements(WebDriver driver, T target) {
PageFactory.initElements(new StaleReferenceAwareFieldDecorator(new DefaultElementLocatorFactory(driver), NUM_OF_TRIES_FOR_STALE_ELEMENT, WAIT_FOR_STALE_ELEMENT_IN_MS), target);
return target;
}
public static WebDriverWait waitModel() {
return waitModel(GrapheneContext.getProxy());
}
public static WebDriverWait waitModel(WebDriver driver) {
return new WebDriverWait(driver, WAIT_MODEL_INTERVAL);
}
}
{code}
{code:title=ElementConditionFactory.java}
public class ElementConditionFactory {
private WebElement element;
private boolean negation = false;
public ElementConditionFactory(WebElement element) {
Validate.notNull(element, "The element can't be null.");
this.element = element;
}
public ExpectedCondition<Boolean> displayed() {
return new ElementDisplayed(element, negation);
}
public ExpectedCondition<Boolean> present() {
return new ElementPresent(element, negation);
}
public ExpectedCondition<Boolean> textContains(String expected) {
return new ElementTextContains(element, expected, negation);
}
public ExpectedCondition<Boolean> textEquals(String expected) {
return new ElementTextEquals(element, expected, negation);
}
public ElementConditionFactory not() {
ElementConditionFactory copy = copy();
copy.negation = true;
return copy;
}
protected ElementConditionFactory copy() {
ElementConditionFactory copy = new ElementConditionFactory(element);
copy.negation = this.negation;
return copy;
}
}
{code}
{code:title=AttributeConditionFactory.java}
public class AttributeConditionFactory {
private WebElement element;
private String attribute;
private boolean negation = false;
public AttributeConditionFactory(WebElement element, String attribute) {
Validate.notNull(element, "The element can't be null.");
Validate.notNull(element, "The attribute can't be null.");
this.element = element;
this.attribute = attribute;
}
public ExpectedCondition<Boolean> present() {
return new AttributePresent(element, attribute, negation);
}
public ExpectedCondition<Boolean> valueContains(String expected) {
return new AttributeValueContains(element, attribute, expected, negation);
}
public ExpectedCondition<Boolean> valueEquals(String expected) {
return new AttributeValueEquals(element, attribute, expected, negation);
}
public AttributeConditionFactory not() {
AttributeConditionFactory copy = copy();
copy.negation = true;
return copy;
}
protected AttributeConditionFactory copy() {
AttributeConditionFactory copy = new AttributeConditionFactory(element, attribute);
copy.negation = this.negation;
return copy;
}
}
{code}
*The usage:*
{code}
waitModel.failWith("Error message").until(element(element).not().present());
waitModel.until(attribute(element, "attribute-name").valueEquals("expected"));
{code}
> Support Graphene utility in original scope with Selenium 2
> ----------------------------------------------------------
>
> Key: ARQGRA-74
> URL: https://issues.jboss.org/browse/ARQGRA-74
> Project: Arquillian Graphene
> Issue Type: Feature Request
> Components: core
> Reporter: Lukáš Fryč
> Assignee: Jan Papousek
> Priority: Critical
> Fix For: 2.0.0.Alpha2
>
>
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.jboss.org/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira
More information about the arquillian-issues
mailing list