Tuesday 9 August 2016

Cucumber Selenium Integration


CUCUMBER AND SELENIUM INTEGRATION


WHY CUCUMBER?


Many testers feel that there is no need of cucumber it is a waste,it is doing something that they already do with the existing tool according to them there is no use to add natural language to you project or code.What matters is the CODE

Now there is answer of WHY?

Cucumber is a testing framework that helps to bridge the gap between software developers and business managers. Tests are written in plain language based on the behavior-driven development (BDD) style of Given, When, Then, which any layperson can understand. Test cases are then placed into feature files that cover one or more test scenarios.This English(or other natural language)feature files serve as the abstraction over code that allows those statements to execute.Cucumber interprets the tests into the specified programming language and uses Selenium to drive the test cases in a browser. Our tests are translated into Java code.

ADVANTAGES OF SELENIUM WITH CUCUMBER

The advantages of using Selenium with Cucumber for automated testing. Using this framework, you write tests in feature files in a form understandable by any business manager or other non-technical stakeholder. The tests are then translated into the Java language by Cucumber, which supports multiple scripting and programming languages. Selenium is used to drive the browser.

Prerequisites: 

  • Eclipse IDE
  • Jar files required by the framework
    • mockito-core-2.0.8.jar
    • cucumber-4.12.jar
    • gherkin-2.12.2.jar
    • reporting-0.1.0.jar
    • cucumber-jvm-.deps-1.0.3.jar
    • cucumber-junit-1.2.2.jar
    • cucumber-java-1.2.2.jar
    • cucumber-core-1.2.2.jar
    • cobertura-2.1.1.jar
    • cucumber-HTML-0.2.3-sources.jars
    • Selenium-Server-standalone


Steps to make cucumber framework

1.Create a new Java project.





2.Configure Build Path (add all the jars mentioned above)



3.In project make a folder "features" and in that make a feature file "myapplication.feature".




      3.1. Feature in my case is :



4.Now in src, make a package called runner and in this package make a class called TestRunner.


   
 4.1 TestRunner in my case is:


 

5.Now run the TestRunner using JUnit.

6.Now you can see that console display a message that you should make this functions...



7.Create a new package in src called stepdefination and in package create a class called testdefinations.


           7.1 testdefination class in my case is : 

package stepdefination;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

import cucumber.api.PendingException;
import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;

public class testdefinations {

WebDriver driver;

@Given("^Open Chrome$")
public void open_Chrome() throws Throwable {
   
System.setProperty("webdriver.chrome.driver", "\\path\\to\\chrome\\setup\\");
driver= new ChromeDriver();
driver.manage().window().maximize();
  //throw new PendingException();
}

@Given("^Start application$")
public void start_application() throws Throwable {
driver.get("https://www.facebook.com/");
   // throw new PendingException();
}

@When("^I enter valid username$")
public void i_enter_valid_username() throws Throwable {
    
driver.findElement(By.id("******")).sendKeys("username");
    //throw new PendingException();
}

@When("^valid passpord$")
public void valid_passpord() throws Throwable {
driver.findElement(By.id("******")).sendKeys("password");
driver.findElement(By.id("******")).click();
    
    //throw new PendingException();
}

@Then("^user should be able to login successfully$")
public void user_should_be_able_to_login_successfully() throws Throwable {
   
System.out.println("Able to LogIn");
    //throw new PendingException();
}

}


8.Update your TestRunner Class.




9.Run your TestRunner Class as JUnit.

10. Now you can see your HTML results in the folder target/cucumber made dynamically.


Happy Testing :)




Keywords Cucumber, Selenium, Integration, Java, BDD, HTML, Eclipse.

10 comments:

  1. Selenium is the best tool ever to test an application effectively. Your blog made me to realize that through the best examples you have explained. Thanks for sharing a wonderful article.
    Regards:
    Selenium Training in Chennai | Selenium Training

    ReplyDelete
    Replies
    1. Thanks. Will try to post more informative stuff in future.

      Delete
  2. Wonderful post!!Thank you for sharing this info with us.
    Keep updating I would like to know more updates on this topic
    Very useful content, I would like to suggest this blog to my friends.

    Selenium Training in Chennai

    selenium testing training

    ReplyDelete
  3. Helpful blog regarding Cucumber automation services. Thanks for sharing the helpful information.

    ReplyDelete
  4. When your website or blog goes live for the first time, it is exciting. That is until you realize no one but you and your. hazard perception test sa

    ReplyDelete
  5. Profit primarily prime quality items -- you can understand them all within: Viking, Sub-Zero, GE REFRIGERATOR REPAIR IN HIGHLAND

    ReplyDelete