https://github.com/unruly/flick
Modern Java DSL for Acceptance Tests using the screenplay pattern
https://github.com/unruly/flick
acceptance-testing java java8 screenplay-pattern tdd
Last synced: 7 months ago
JSON representation
Modern Java DSL for Acceptance Tests using the screenplay pattern
- Host: GitHub
- URL: https://github.com/unruly/flick
- Owner: unruly
- License: mit
- Created: 2017-04-26T13:42:44.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2018-12-13T05:29:28.000Z (over 6 years ago)
- Last Synced: 2024-03-25T13:10:24.639Z (over 1 year ago)
- Topics: acceptance-testing, java, java8, screenplay-pattern, tdd
- Language: Java
- Size: 21.5 KB
- Stars: 6
- Watchers: 8
- Forks: 1
- Open Issues: 10
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# flick
[](https://travis-ci.org/unruly/flick)
[](https://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22co.unruly%22%20AND%20a%3A%22flick%22)Flick is an acceptance testing library for Java that implements the Screenplay Pattern, an improvement over the Page Object pattern for UI testing.
At Unruly, we use this to drive our [monitoring-in-production](https://vimeo.com/channels/pipelineconf/123629954) specs against our customer-facing Reporting UI.
## Getting started with Flick
Install from Maven Central
```xml
co.unruly
flick
1.0.1```
## Using Flick in your tests
A test that implements the FlickDSL interface has access to the given/when/then methods to build a coherent and clean test - these are _default_ methods so classes need not override them. FlickDSL is actually more like a mixin.
```java
public class ExampleTest implements FlickDSL {
// Tests go here
}
```## Screenplay Pattern
Flick abstracts away notions of WebDriver/UI specific code from the test. You can find more detail on the Screenplay Pattern [here](https://ideas.riverglide.com/page-objects-refactored-12ec3541990)
### Example Test
```java
@Test
public void shouldRestrictToDateRange() {
InternalUser actor = new InternalUser(); // Actorfinal Page page = given(actor.using(browser, "acme-reporting-ui.com"))
.wasAbleTo(loginWith(actor.user(), actor.password())) // Logging in as an Action
.hasHappened();when(actor.using(browser, page))
.attemptsTo(generateReport()) // Generating a report as Action
.enact();then(actor.using(browser, page))
.should(haveTotalWithValue("LOTS"))) // Inspecting the output as an Assertion
.check();
}
```## Why would I use Flick/the Screenplay pattern?
The Screenplay pattern guides us towards higher-level abstractions and decoupling from implementation - by encapsulating interactions and validations within interfaces that only expose the Browser.
The implementation can then be refactored without changing the tests outside of swapping in new actions/assertions, leading to less brittle, more robust tests.
## Concepts in Flick
A test consists of an *Actor* interacting with a *Stage* - we phrase this as *Given* (an Action is performed), *When* (an Action is performed), *Then* (an Assertion must be valid).
### Actions
An [Action](./src/main/java/co/unruly/flick/dsl/Action.java) is a function that takes a Browser (to interact with) and returns nothing.
For example
```java
class NavigateToPage implements Action {private final String url;
private NavigateToPage(String url) { this.url = url; }
@Override
public void performOn(Browser browser) {
browser.load(url);
}
}
```In a more functional style:
```java
public static Action navigateToPage(final String url) {
return browser -> browser.load(url);
}
```### Assertions
An [Assertion](./src/main/java/co/unruly/flick/dsl/Assertion.java) is a function that takes a Browser (to interact with) and returns nothing.
```java
public class HasHeader implements Assertion {
@Override
public void check(Browser browser) {
browser.waitUntil(browser.findElement(By.xpath("//*h1"))::isPresent);
}
}
```In a more functional style:
```java
public static Assertion hasHeader() {
return browser -> browser.waitUntil(browser.findElement(By.xpath("//*h1"))::isPresent);
}
```