Skip to content
This repository has been archived by the owner on Nov 17, 2017. It is now read-only.

Commit

Permalink
fragments: tree fragment: changed locators from jQuery to css to be m…
Browse files Browse the repository at this point in the history
…ore stable
  • Loading branch information
Jiri Stefek committed Oct 11, 2013
1 parent ea8e62f commit 2fcaa07
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 deletions.
Expand Up @@ -39,9 +39,9 @@ public class RichFacesTree implements Tree {
@Root
private WebElement root;

@FindByJQuery("> div.rf-tr-nd")
@FindByJQuery("> .rf-tr-nd")
private List<RichFacesTreeNode> childNodes;
@FindByJQuery("> div.rf-tr-nd")
@FindByJQuery("> .rf-tr-nd")
private List<WebElement> childNodesElements;

private final AdvancedTreeInteractions interactions = new AdvancedTreeInteractionsImpl();
Expand Down
Expand Up @@ -21,15 +21,14 @@
*******************************************************************************/
package org.richfaces.tests.page.fragments.impl.tree;

import java.util.List;
import java.util.concurrent.TimeUnit;

import org.jboss.arquillian.drone.api.annotation.Drone;
import org.jboss.arquillian.graphene.findby.ByJQuery;
import org.jboss.arquillian.graphene.findby.FindByJQuery;
import org.jboss.arquillian.graphene.wait.FluentWait;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.richfaces.tests.page.fragments.impl.Utils;
import org.richfaces.tests.page.fragments.impl.utils.Actions;
import org.richfaces.tests.page.fragments.impl.utils.WaitingWrapper;
Expand All @@ -40,22 +39,26 @@

public class RichFacesTreeNode extends RichFacesTree implements Tree.TreeNode {

@FindByJQuery("> .rf-trn")
@FindBy(className = "rf-trn")
private WebElement infoElement;

@FindByJQuery("> .rf-trn > .rf-trn-hnd")
@FindBy(css = ".rf-trn > .rf-trn-hnd")
private WebElement handleElement;

@FindByJQuery("> .rf-trn > .rf-trn-hnd-ldn-fct")
@FindBy(css = ".rf-trn > .rf-trn-hnd-ldn-fct")
private WebElement handleLoadingElement;

@FindByJQuery("> .rf-trn > .rf-trn-cnt")
@FindBy(css = ".rf-trn > .rf-trn-cnt")
private WebElement containerElement;

@FindByJQuery("> .rf-trn > .rf-trn-cnt > .rf-trn-ico:visible")
@FindByJQuery(".rf-trn > .rf-trn-cnt > .rf-trn-ico:visible")
private WebElement iconElement;
@FindByJQuery("> .rf-trn > .rf-trn-cnt > .rf-trn-lbl")
@FindBy(css = ".rf-trn > .rf-trn-cnt > .rf-trn-lbl")
private WebElement labelElement;
@FindByJQuery(".rf-trn > .rf-trn-cnt > .rf-trn-lbl[onclick]")
private WebElement elementForSelection;
@FindByJQuery(".rf-trn > .rf-trn-cnt > .rf-trn-lbl >*[onclick]")
private WebElement innerElementForSelection;

private long _collapseWaitUntilNodeIsCollapsedTimeout = -1;
private long _expandWaitUntilNodeIsExpandedTimeout = -1;
Expand Down Expand Up @@ -85,7 +88,7 @@ public TreeNode collapse() {
if (isToggleByHandle()) {
getHandleElement().click();
} else {
new Actions(driver).triggerEventByWD(getToggleNodeEvent(), getCorrectElementWithOnclickAction()).perform();
new Actions(driver).triggerEventByWD(getToggleNodeEvent(), getCorrectElementForInteraction()).perform();
}
}
waitUntilNodeIsCollapsed()
Expand All @@ -100,7 +103,7 @@ public TreeNode expand() {
if (isToggleByHandle()) {
getHandleElement().click();
} else {
new Actions(driver).triggerEventByWD(getToggleNodeEvent(), getCorrectElementWithOnclickAction()).perform();
new Actions(driver).triggerEventByWD(getToggleNodeEvent(), getCorrectElementForInteraction()).perform();
}
}
waitUntilNodeIsExpanded()
Expand All @@ -115,12 +118,13 @@ public WebElement getContainerElement() {
}

/**
* We have to get correct element with onclick event, which is by default the label element,
* but when there is an panel inside node, the onclick action is moved to that panel.
* We have to get correct element, which is by default the label element,
* but when there is a panel inside the node, the interaction point is moved to that panel.
* When the label element has onclick action (unchangeable event for selection), then return the label element,
* otherwise return a child (with onclick action) of that label.
*/
private WebElement getCorrectElementWithOnclickAction() {
List<WebElement> possibleElements = getLabelElement().findElements(ByJQuery.selector(">*[onclick]"));
return (possibleElements.isEmpty() ? getLabelElement() : possibleElements.get(0));
private WebElement getCorrectElementForInteraction() {
return Utils.isVisible(elementForSelection) ? elementForSelection : innerElementForSelection;
}

@Override
Expand Down Expand Up @@ -177,7 +181,7 @@ public boolean isSelected() {
@Override
public TreeNode select() {
if (!isSelected()) {
getCorrectElementWithOnclickAction().click();
getCorrectElementForInteraction().click();
}
waitUntilNodeIsSelected()
.withTimeout(getSelectWaitUntilNodeIsSelectedTimeout(), TimeUnit.SECONDS)
Expand Down

0 comments on commit 2fcaa07

Please sign in to comment.