JBehave with Selenium

This demo will show a JBehave (Behavior Driven Development) test case entered into Jira and then pulled from Jira and run along with it’s corresponding Selenium test cases. A test case is created in Jira and the JBehave test case is then entered in the description field. Using Jira’s API and JBehave code the JBehave test case is pulled from Jira and run along with the corresponding Selenium test cases. The example code below will show the JBehave hooks entered into the Selenium test cases.

NOTE: The test execution has been slowed down for demo purposes

 

Example Code:

Blue text relates to JBehave annotations used in Java and should be what is seen in the video in the upper left corner

 

package com.creative.oss.selenium.example.jbehave.steps;

public class WikiSteps extends CosJBehaveSteps {

 

private WikipediaPage wikiPage;

private WikiResultPage resultsPage;

 

public WikiSteps (WebDriver webDriver, String baseUrl) {

setWebDriver(webDriver);

wikiPage = new WikipediaPage(getWebDriver());

wikiPage.setPageUrl(baseUrl);

}

@Given(“a user is on www.wikipedia.org”)

public void searchingForSomethingOnWikipediaDotOrg() {

wikiPage.get();

Assert.assertNotNull(wikiPage.getSearchInput().getTagName(), “Search Input was found”);

Assert.assertNotNull(wikiPage.getSearchButton().getTagName(), “Search Button was found”);

}

@When(“user types $searchString in the search field”)

public void whenUserTypesHippoInTheSearchField(String searchString) {

wikiPage.enterSearch(searchString);

}

@When(“clicks search button”)

public void whenClicksSearchButton() {

wikiPage.clickSearchButton();

}

@Then(“user should be on $expectedTitle results page”)

public void thenUserShouldBeOnResults(String expectedTitle) {

resultsPage = WikipediaPageFactory.createWikiResultPage(getWebDriver(), expectedTitle);

Assert.assertNotNull(resultsPage.getHeading().getTagName(), “Heading was found”);

Assert.assertEquals(resultsPage.getHeading().getText(), expectedTitle, String.format(“Heading should be ‘%s’ page”, expectedTitle));

}

}

Download and extend ATF...

ATF Is Now Open Source

Join this 10 week program anytime...

DevOps Mastery Program

Get your DevOps health check now...

Free DevOps Assessment

X