By Anusha Ammaluru
This time we bring you a blog article about Cucumber, Selenium and Integration with Azure DevOps, let's get started and welcome to the journey to learn Cucumber.
The blog post will cover the following topics:
Cucumber Introduction
Cucumber is a tool that supports Behaviour-Driven Development(BDD). It lets us define application behavior in plain meaningful English text using a simple grammar defined by a language called Gherkin. Cucumber itself is written in Ruby, but it can be used to “test” code written in Ruby or other languages.
Cucumber is one of the most powerful tools. It offers us the real communication layer on top of a robust testing framework. The tool can help run automation tests on wide-ranging testing needs from the backend to the frontend. Moreover, Cucumber creates deep connections among members of the testing team, which we hardly found in other testing frameworks.
What is Gherkin? It is a simple, lightweight, and structured language, which uses regular spoken language to describe user requirements and scenarios. Examples of regular spoken language are English, French, and around 30 more languages. Gherkin contains a set of syntax/keywords
Feature: Defines the feature (generally a user story)
Given: Specifies the pre-condition of the test
And: Defines additional conditions of the test
Then: States the post-condition/expected result of the test
Key points to note:
Setup Cucumber with Selenium in Eclipse
Download .exe file
Help
> Eclipse Marketplace
Cucumber Eclipse Plugin
.
Help
> Install New software
https://cucumber.github.io/cucumber-eclipse/update-site
Cucumber Eclipse Plugin
Cucumber Basics
@Given("user is on home page")
public void user_is_on_home_page() {
driver.get("https://pul-ai-anu.azurewebsites.net/");
driver.manage().timeouts().pageLoadTimeout(100, TimeUnit.SECONDS);
}
@When("I click on login link")
public void i_click_on_login_link() {
login = new LoginPage(driver);
login.lnk_Login.click();
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
}
@When("I enter username {string}")
public void i_enter_username(String email) {
login = new LoginPage(driver);
login.txtbx_UserName.sendKeys(email);
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
}
@@When("I enter password {string}"
public void i_enter_password(String password) {
login = new LoginPage(driver);
login.txtbx_Password.sendKeys(password);
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
}
@When("I click on login button")
public void i_click_on_login_button() {
login = new LoginPage(driver);
login.btn_Login.click();
driver.manage().timeouts().pageLoadTimeout(100, TimeUnit.SECONDS);
}
@Then("I verify the login is successful")
public void i_verify_the_login_is_successful() {
login = new LoginPage(driver);
assert(login.lnk_profile.isEnabled());
}
Junit Test Runner Class
package runner;
import io.cucumber.junit.Cucumber;
import io.cucumber.junit.CucumberOptions;
import org.junit.runner.RunWith;
@RunWith(Cucumber.class)
@CucumberOptions(plugin = {"pretty"},
features= "src\\test\\resources\\features" ,
glue= "stepDefinitions")
public class RunCucumberTest {
}
Right-click on TestRunner class and Click Run As > JUnit Test Application
Test Run Report will be shown like this
Eclipse Integration with Azure DevOps
Conclusion
I have created a sample Java Maven project using the Selenium Page factory and Cucumber in GitHub https://github.com/anu-01/CucumberSelenliumPageFactory. This is a great place to get started with a Cucumber-based framework.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.