Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Heckenlights Test with JBehave, Selenide and Guice
import org.jbehave.core.annotations.BeforeScenario;
import org.jbehave.web.selenium.SeleniumContext;
import org.jbehave.web.selenium.WebDriverProvider;
import org.openqa.selenium.WebDriver;
import javax.inject.Inject;
public abstract class AbstractSeleniumSteps {
private WebDriverProvider webDriverProvider;
private SeleniumContext seleniumContext;
public void beforeTheScenario() {
protected WebDriver webDriver() {
return webDriverProvider.get();
Scenario: Visit
Given website heckenlights
Then the website is displayed
And the title is HECKENLIGHTS
And the controls are visible
And 2 tikales are in the playlist
When I click on Contact
Then the page scrolls down
Given website heckenlights
Then there are at least 2 presets
And upload alert is invisible
When I click preset number 1
Then upload is successful
import static com.codeborne.selenide.Selenide.$;
import static com.codeborne.selenide.Selenide.$$;
import static com.codeborne.selenide.Selenide.executeJavaScript;
import static com.codeborne.selenide.Selenide.title;
import static org.openqa.selenium.By.linkText;
import com.codeborne.selenide.ElementsCollection;
import com.codeborne.selenide.Selenide;
import com.codeborne.selenide.SelenideElement;
* @author <a href="">Mark Paluch</a>
public class HeckenlightsPage {
public String getTitle() {
return title();
public SelenideElement getControls() {
return $("#controls");
public ElementsCollection getPlaylistTitles() {
return $$("#playlist a");
public void clickLink(String item) {
public Number height() {
return executeJavaScript("return (document.height !== undefined) ? document.height : document.body.offsetHeight;");
public Number scrollY() {
return executeJavaScript("return window.scrollY;");
public ElementsCollection getPresets() {
return $$("#presets a");
public SelenideElement getUploadSuccessAlert()
return $("#uploadsuccess");
import static com.codeborne.selenide.Condition.text;
import static com.codeborne.selenide.Condition.visible;
import static com.codeborne.selenide.Selenide.Wait;
import static java.util.concurrent.TimeUnit.SECONDS;
import static org.assertj.core.api.Assertions.assertThat;
import com.codeborne.selenide.CollectionCondition;
import com.codeborne.selenide.ex.ListSizeMismatch;
import com.codeborne.selenide.impl.WebElementsCollection;
import org.jbehave.core.annotations.Given;
import org.jbehave.core.annotations.Then;
import org.jbehave.core.annotations.When;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import javax.inject.Inject;
import java.util.List;
* @author <a href="">Mark Paluch</a>
public class HeckenlightsSteps extends AbstractSeleniumSteps {
private HeckenlightsPage page;
private String baseUri = "";
@Given("website heckenlights")
public void givenNavigate() {
@When("I click on $item")
public void whenIClickOn(String item) {
@When("I click preset number $number")
public void whenIClickOnPreset(int position) {
page.getPresets().get(position + 1).click();
@Then("the website is displayed")
public void thenWebsiteIsDisplayed() {
@Then("the controls are visible")
public void thenControlsAreVisible() {
@Then("$number titles are in the playlist")
public void thenNumberOfTitlesAreInThePlaylist(int number) {
@Then("the title is $title")
public void thenTitleIs(String title) {
@Then("upload alert is invisible")
public void thenUploadAlertIsInvisible() {
@Then("upload is successful")
public void thenUploadIsSucessful() {
page.getUploadSuccessAlert().has(text("Enqeued your track "));
@Then("there are at least $number presets")
public void thenThereAreAtLeastCountPresets(int count) {
@Then("the page scrolls down")
public void thenThePageScrollsDown() {
final int half = halfHeight();
Wait().withTimeout(2, SECONDS).until(new Predicate<WebDriver>() {
public boolean apply(WebDriver input) {
int scroll = page.scrollY().intValue();
return scroll > half;
private int halfHeight() {
int height = page.height().intValue();
return height / 2;
private CollectionCondition atLeastElements(final int count) {
return new CollectionCondition() {
public void fail(WebElementsCollection collection, List<WebElement> elements, Exception lastError, long timeoutMs) {
throw new ListSizeMismatch(count, collection, elements, lastError, timeoutMs);
public boolean apply(List<WebElement> input) {
return input.size() >= count;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment