Now that you have your own story, you need your steps. Steps - This is the Java code that will be executed over the history. Each line in your story is mapped to a Java step. See the Documentation for Candidate Steps .
Here's a really easy hit on what your story and steps might look like. But that should at least give you an idea of ββhow stories and steps come together.
History
Given user username with password passcode is on product page url When the user clicks add to wish list Then the wish list page is displayed And the product title appears on the wish list
Steps
public class WishlistSteps { WebDriver driver = null; @BeforeScenario public void scenarioSetup() { driver = new FirefoxDriver; } @Given("user $username with password $passcode is on product page $url") public void loadProduct(String username, String passcode, String url) { doUserLogin(driver, username, passcode); // defined elsewhere driver.get(url); } @When("the user clicks add to wishlist") public void addToWishlist() { driver.findElement(By.class("addToWishlist")).click(); } @Then("the wish list page is displayed") public void isWishlistPage() { assertTrue("Wishlist page", driver.getCurrentUrl().matches(".*/gp/registry/wishlist.*")); } @Then("the product $title appears on the wish list") public void checkProduct(String title) { // check product entries // assert if product not found } @AfterScenario public void afterScenario() { driver.quit(); } }
Then you need a runner who actually finds and runs the stories. See the documentation for Running History . Below is a very simple runner that will work as a JUnit test.
Runner
public class JBehaveRunner extends JUnitStories { public JBehaveRunner() { super(); } @Override public injectableStepsFactory stepsFactory() { return new InstanceStepsFactory( configuration(), new WishlistSteps() ); } @Override protected List<String> storyPaths() { return Arrays.asList("stories/Wishlist.story"); } }
This runner will then be executed as a JUnit test. You can configure your IDE to run it or use Maven or Gradle (depending on your setup).
mvn test
I found that the pages below give an excellent overview of the whole setup. And examples from the JBhave repository are also useful.
source share