CONFIGURE ECLIPSE WITH CUCUMBER

Components to be set up

1.Environment (Eclipse)
2.Feature File
3.StepDefinition File
4.Runner File


Cucumber Eclipse Plugin helps eclipse to understand the basic Gherkin syntax and it works like a syntax highlighter. It highlights all the main syntax
in the feature file which makes it more readable and clear. It also enables the run of the feature file independently.

Steps to follow:

1) Launch the Eclipse IDE and from Help menu, click “Install New Software”.
2) You will see a dialog window, click “Add” button.
3) Type name as you wish, let’s take “Cucumber” and type “http://cucumber.github.com/cucumber-eclipse/update-site” as location. Click OK.
4) You come back to the previous window but this time you must see Cucumber Eclipse Plugin option in the available software list. Just Check the box
and press “Next” button.
5) Click on Next.
6) Click “I accept the terms of the license agreement” then click Finish.
7) Let it install, it will take few seconds to complete.
8) You may or may not encounter a Security warning, if in case you do just click OK.
9) You are all done now, just Click Yes (It will restart).

Required Jars : Download from here
1.cucumber-core
2.cucumber-java
3.cucumber-junit
4.cucumber-jvm-deps
5.cucumber-reporting
6.gherkin
7.junit
9.mockito-all
10.cobertura

Dependencies in Pom (MAVEN) :

<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-core</artifactId>
<version>1.1.5</version>
</dependency>

<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-java</artifactId>
<version>1.1.5</version>
</dependency>

<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-junit</artifactId>
<version>1.1.5</version>
</dependency>

This post cover maven based java webdriver BDD framework using cucumber for Google advance search scenario, Following are the steps to write scenario for BDD framework:
Step 1.  First create a maven eclipse project.

Step 2. Add above maven pom.xml file.Or click here.

Step 3. Create a feature “GoogleScenario.feature”  file and put into package “com/maven/test” of source folder “src/test/resources”.

Paste the below scenario in GoogleScenario.feature

Feature: Google Search

Scenario: Advance Search in Google

Given user is on google search page

When enter “testing” text into search field

And click on search button

And click on advance search icon

And click on advance search link

And click on advance search button

Then verify first link text “testing”

Step 4. Now need to create step definition file for above scenario and implement webdriver automation code. So Create a java file “GoogleStep.java” and put under into package “com/maven/test” of source folder” src/test/java” and write below code:

package com.maven.test;

import java.util.concurrent.TimeUnit;

import org.junit.Assert;

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.WebElement;

import org.openqa.selenium.firefox.FirefoxDriver;

import cucumber.annotation.*;

import cucumber.annotation.en.*;

public class GoogleStep {

protected WebDriver driver;

@Before

public void setUp() {

driver = new FirefoxDriver();

driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);

driver.manage().window().maximize();

}

@After

public void tearDown() {

driver.close();

}

@Given(“user is on google search page”)

public void The_user_is_on_google_search_page() {

driver.get(“https://www.google.co.in/&#8221;);

}

@When(“enter \”([^\”]*)\” text into search field”)

public void User_enters_text_into_field(String text) {

driver.findElement(By.id(“gbqfq”)).sendKeys(text);

}

@And(“click on search button”)

public void user_click_on_search_button() {

driver.findElement(By.id(“gbqfb”)).click();

}

@And(“click on advance search icon”)

public void click_on_advance_icon() {

driver.findElement(By.id(“abar_button_opt”)).click();

}

@And(“click on advance search link”)

public void click_on_advance_link() {

driver.findElement(By.xpath(“//div[text()=\”Advanced search\”]”)).click();

}

@And(“click on advance search button”)

public void click_on_advance_button() {

driver.findElement(By.xpath(“//input[@value=’Advanced Search’]”)).click();

}

@Then(“verify first link text \”([^\”]*)\””)

public void verify_first_link_text(String msg)

{

WebElement message = driver.findElement(By.xpath(“//*[@id=’rso’]/li[1]/div/h3/a”));

Assert.assertTrue(message.getText().contains(msg));

}

}

Step 5. Now create “RunCukesTest.java” which defines cucumber-jvm configuration and put under package “com/maven/test” of source folder” src/test/java”.

package com.maven.test;

import org.junit.runner.RunWith;

import cucumber.junit.Cucumber;

@RunWith(Cucumber.class)

@Cucumber.Options(plugin= {“pretty”, “html:target/cucumber-htmlreport”,”json-pretty:target/cucumber-report.json”})

public class RunCukesTest {

}

Step 6.Now right click on the project and click on maven test.Or just run the ‘RunCukesTest’ class.

Step 7. You should see test will execute and after execution report is generated under directory “\target\cucumber-htmlreport”.

No comments:

Post a Comment