Jenkins Cucumber Tutorial

Jenkins Cucumber Tutorial

Jenkins Cucumber Tutorial, this in blog entry we will look at writing a simple Cucumber test and then running it via Maven. Once we are able to run the test via Maven we will be able to run it via Jenkins.

Feature File:
The feature file below will be used to simple navigate to the QAShahin YouTube page and then assert on the fact that we are on the correct YouTube page.

Feature: Simple feature
 
Scenario: Go to QA Shahin YouTube Page
Given I go to "QASHAHIN"
Then I should be on "QAShahin" youtube page

Step Definition Class:
The Java class below will be used to identify each step definition for each of the test steps for.

public class StepDefinition {
 
WebDriver driver;
 
@Given("^I go to \"([^\"]*)\"$")
public void goTo(String args) {
System.setProperty("webdriver.chrome.driver", "chromedriver.exe");
driver = new ChromeDriver();
driver.navigate().to("https://www.youtube.com/user/GlassBoxt");
}
 
@Then("^I should be on \"([^\"]*)\" youtube page$")
public void shouldBeOnYouTubePage(String page) {
Assert.assertTrue(driver.getTitle().contains(page));
driver.close();
}
 
}

Test Runner Class:
The code below is used to actually identify which feature files to run but through JUnit.

@RunWith(Cucumber.class)
@CucumberOptions(features = "src/test/java")
public class RunCucumberTest{}

Now let’s try to run ‘mvn test’ from the command line.

Assuming you were able to run Cucumber feature file from the command line you should now be able to run feature files from Jenkins by just creating a simple Jenkins job.

Follow the video tutorial below to see a more detailed view of this blog.

Video Tutorial on YouTube

Jenkins Cucumber Tutorial
Direct Video Link

Mo

I am a passionate tester, father, husband and gamer. I love to upload videos on my YouTube channel, write blogs about Software Testing and generally contribute back to the Software Testing world.

More Posts - Twitter - Facebook - Google Plus

Published by

Mo

I am a passionate tester, father, husband and gamer. I love to upload videos on my YouTube channel, write blogs about Software Testing and generally contribute back to the Software Testing world.

Leave a Reply