A library with the goal of making interactions with a web browser for the purpose of testing web applications trivial and fun.
- Two versions:
Scala(dollarX)and Java (jdollarX). Both are immutable. - Flexible syntax that allows to declare arbitrarily complex DOM elements easily.
- Optimized for atomic interaction with the browser, to avoid common pitfalls in testing web applications and optimize performance.
- Includes custom matchers for both Hamcrest and
ScalaTest. The matchers provide useful error messages. - Reach API that supports visual testing, high-level operations and AgGrid.
- Two "flavors": The standard, with multiple browsers instances support, and a simplified API for a single browser instance.
jdollarx-example contain several behavior tests and other examples that demonstrate the use of the library. Beyond that, the unit tests in jdollarx contain many examples.
NodeList nodes = PathParsers.findAllByPath("<div>foo</div><span></span>><div>boo</div>",
BasicPath.div.before(BasicPath.span));
// and using static imports makes the expression simpler:
// findAllByPath("...", div.before(span))
import static com.github.loyada.jdollarx.custommatchers.CustomMatchers.*;
import static com.github.loyada.jdollarx.BasicPath.*;
Document doc = PathParsers.getDocumentFromString("<div><span></span></div>");
assertThat(div.inside(div), isAbsentFrom(doc));
// or ...
assertThat(span.inside(div), isPresentIn(doc));
// or you might want ...
assertThat(div.withClass("foo"), isPresent(5).timesOrLessIn(doc));
Let's say the last assertion in our examples fails. Then the error message would look like:
Expected: document contains div with class "foo" at most 5 times
but: div with class "foo" appears 6 times
import static com.github.loyada.jdollarx.custommatchers.CustomMatchers.*;
InBrowser browser;
assertThat(div, isPresentIn(browser));
// which is equivalent to:
assertThat(browser, hasElement(div));
// or you might want to assert something like:
assertThat(span.inside(div), isPresent(5).timesIn(browser));
import static com.github.loyada.jdollarx.singlebrowser.InBrowserSinglton.*;
Path myElement;
scrollTo(myElement);
hoverOver(myElement);
clickAt(myElement);
// or alternatively, if you prefer the OO style:
myElement.click();
For the behavior tests examples (in dollarx-example, jdollarx-example) to work, you need to download the chrome selenium driver and set an environment variable 'CHROMEDRIVERPATH' to its path location.