Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(refactor) Service: Enhance the functionality of the services. #167

Open
4 of 5 tasks
hastebrot opened this issue Dec 1, 2014 · 2 comments
Open
4 of 5 tasks

(refactor) Service: Enhance the functionality of the services. #167

hastebrot opened this issue Dec 1, 2014 · 2 comments

Comments

@hastebrot
Copy link
Member

hastebrot commented Dec 1, 2014

@hastebrot
Copy link
Member Author

clickOn(".button");
verifyThat(".button", isEnabled()); // Matcher<Node>
verifyThat(".button", hasItem(isEnabled()); // Matcher<Iterable<Node>>
verifyThat(".button", everyItem(isEnabled()); // Matcher<Iterable<Node>>
// FxRobot:
void clickOn(String selector) { // pointFor(String selector)
    // queryFirst() throws a NodeQueryException that gives the matcher's descriptions 
    // and states how many items were matched by them. If throwIfEmpty() was omitted
    // then queryFirst().get() will throw an IllegalStateException.
    NodeQuery nodeQuery = nodeFinder()
        .from(rootsOfWindows(windowFinder().allWindows()))
        .lookup(bySelector(selector))
        .match(isVisible());
    clickOn(nodeQuery.throwIfEmpty().queryFirst().get());
}

// FxRobot:
void clickOn(String selector) {
    NodeQuery nodeQuery = nodeFinder().node()
        .from(rootsOfWindows(windowFinder().allWindows()))
        .lookup(bySelector(selector));
    // if (visibleNodeQuery.queryAll().isEmpty()) { throw new FxRobotException()) }
    NodeQuery visibleNodeQuery = nodeFinder().node()
        .from(nodeQuery.queryAll())
        .match(isVisible());
    clickOn(visibleNodeQuery.queryFirst().get());
}

// FxAssert:
void verifyThat(String selector, Matcher<Node> matcher) {
    // queryFirst().orNull() does not throw an Exception, since throwIfEmpty() was 
    // omitted. verifyThat() throws an AssertionError and uses matcher for description.
    NodeQuery nodeQuery = nodeFinder()
        .from(rootsOfWindows(windowFinder().allWindows()))
        .lookup(bySelector(selector));
    verifyThat(nodeQuery.queryFirst().orNull(), matcher);
}

// FxAssert:
void verifyThat(String selector, Matcher<Iterable<Node>> matcher) {
    NodeQuery nodeQuery = nodeFinder()
        .from(rootsOfWindows(windowFinder().allWindows()))
        .lookup(bySelector(selector));
    verifyThat(nodeQuery.queryAll(), matcher);
}

TODO: Create screenshots and add a note to the matcher descriptions.


query().from(verifyThatNode).queryFirst();

query().from(rootOfPopupControl(popupControl))
       .lookup(bySelector(".color-square"))
       .match(isColorSquareWith(Color.RED)) // NoNodesFoundException?
       .match(isVisible()) // NoNodesVisibleException?
       .queryFirst();

query().from(tableView)
       .lookupAt(rowIndex, bySelector(".table-row-cell"))
       .lookupAt(columnIndex, bySelector(".table-cell"))
       .match(isVisible())
       .queryFirst();

Reference: http://en.wikipedia.org/wiki/Monotonicity_of_entailment

@hastebrot
Copy link
Member Author

FxRobot provides node(String selector), point(String selector) and moveTo(String selector).

  • node() and node(...) return a NodeQuery that provides queryFirst() and queryAll().
  • point(...) and offset(...) return a PointQuery that provides query(). They should use node().queryFirst() where appropriate and throw an FxRobotException, if no Nodes were found.
  • moveTo(...) returns void. It internally uses visiblePoint(String selector) which in turn uses node(String selector). It should check if Nodes were found and filter visible Nodes. It should call queryFirst() and throw an FxRobotException that gives a precise message if no Nodes were found. moveTo(Node) does not need node() but should also verify that Node is visible.
FxRobotException: Could not calculate target point.
(no visible Nodes to interact with were found)
The selector "#button" returned 1 nodes, but none was visible.
FxRobotException: Could not calculate target point.
The predicate returned 5 nodes, but none was visible.
FxRobotException: Could not calculate target point.
The node query returned 0 nodes.

@hastebrot hastebrot changed the title refactor(Service): Enhance the functionality of the services. (refactor) Service: Enhance the functionality of the services. Mar 9, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant