Friday 19 September 2014

Creating a Cucumber project in Eclipse



Creating a cucumber project in eclipse

     1 .       Create a maven project in eclipse using following link.


     2.       Add the below dependencies in your pom.xml.

<dependency>
 <groupId>info.cukes</groupId>
 <artifactId>cucumber-picocontainer</artifactId>
 <version>1.1.5</version>
 <scope>test</scope>
 </dependency>

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

 <dependency>
 <groupId>junit</groupId>
 <artifactId>junit</artifactId>
 <version>4.11</version>
 <scope>test</scope>
 </dependency>

 <dependency>
   <groupId>org.seleniumhq.selenium</groupId>
   <artifactId>selenium-server</artifactId>
   <version>2.41.0</version>
  </dependency>
 
<dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>2.39.0</version>
        </dependency>

      3.       The project structure would be as shown below.

 



     4.       Here in the project structure, we need to add the below things :
 
    a)      src/main/java – Write your java code.
    b)      src/main/resources – Place your resource file in this folder.
    c)      src/test/java – Place your test code in this folder.
    d)      src/main/resources – Place your test resources in this folder.

    5.       For a cucumber project you need
a)      Feature File
b)      Step Definitions
c)       Runner file

    6.       Now first create the feature file under src/main/resources folder.

     Steps to create feature file is as below:
a)      Right click on the src/main/resources folder and create a new file.
b)      Create a file with extension .feature. Name the file as HelloStepsDefs.feature

 


c)      Now write the Gherkin language code in the feature file.  


Feature: Hello World

  Scenario: Say hello
    Given I have a hello app with "Hello"
    When I ask it to say hi
    Then it should answer with "Hello World"

7.       Now run the feature file directly. Right click on the feature file and run as à cucumber feature. You will get an error as below.

 


    9.       Copy the above steps and to add the java code this can invoke the steps written in the feature file.

Steps to write the java code
a)      Right click on src/test/java and create a new class file. This class file will be step definition file.

package test.cucumber;

import junit.framework.Assert;
import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;

public class HelloStepDefs {
     
     
      @Given("^I have a hello app with Hello$")
      public void I_have_a_hello_app_with_Hello() throws Throwable {
         System.out.println(" I have a app which says hello");
      }

      @When("^I ask it to say hi$")
      public void I_ask_it_to_say_hi() throws Throwable {
            System.out.println(" I say Hi");
      }

      @Then("^it should answer with Hello World$")
      public void it_should_answer_with_Hello_World() throws Throwable {
            System.out.println(" It answers with Hello World");
        
      }

}

9. Now try to run the feature file again. Run as -- > Cucumber Feature. It shows success this  time.

 

    10.       To create reports and run the test easily. Now create a runner file in src/main/java folder structure.
a)      Right click on src/main/java and create a new class file. This class file will be the runner file. Name the class as RunCukesTest
b)      Write the below code in the runner file.

package test.cucumber;

import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
import org.junit.runner.RunWith;
// Associates Cucumber-JVM with the JUnit runner
@RunWith(Cucumber.class)
@CucumberOptions(format = {"html:target/cucumber-html-report", "json:target/cucumber-json-" +"report.json"})
public class RunCukesTest {
}
    11.       Now run the runner file as Run as -- > Junit Test case. You will see the below result.

 


1    12.       You will see results and reports in target folder of the project. You can find the HTML reports in the folder structure  of your project
   Eg : D:\Workspace\cucumber-jvm\target\cucumber-html-report\
  
    Open the index.html. It looks like report as shown below.
 




 
  



 

24 comments:

  1. Thanks for your post; selenium is most trusted automation tool to validate web application and browser. This tool provides precise and complete information about a software application or environment.Selenium Training in Chennai | Selenium Course in Chennai | Best Selenium training institute in Chennai

    ReplyDelete
  2. I hope your Testing tools content has unique identity across the world. Each and every blog in your website is very informative users. I am eagerly waiting for the next content.
    Qtp training institutes in chennai
    Qtp training Chennai

    ReplyDelete
  3. awesome post presented by you..your writing style is fabulous and keep update with your blogs Ruby on Rails Online Course Bangalore

    ReplyDelete
  4. Thanks for the informative article. This is one of the best resources I have found in quite some time. Nicely written and great info. I really cannot thank you enough for sharing.

    rpa training in marathahalli

    rpa training in btm

    rpa training in kalyan nagar

    rpa training in electronic city

    rpa training in chennai

    rpa training in pune

    rpa online training

    ReplyDelete
  5. I have picked cheery a lot of useful clothes outdated of this amazing blog. I’d love to return greater than and over again. Thanks! 
    python training in annanagar
    python training in chennai
    python training in chennai
    python training in Bangalore

    ReplyDelete
  6. Good Post! Thank you so much for sharing this pretty post, it was so good to read and useful to improve my knowledge as updated one, keep blogging.
    Devops Training in pune
    Devops Training in Chennai
    Devops training in sholinganallur
    Devops training in velachery
    Devops training in annanagar
    Devops training in tambaram

    ReplyDelete

  7. Hello. This post couldn’t be written any better! Reading this post reminds me of my previous roommate. He always kept chatting about this. I will forward this page to him. Fairly certain he will have a good read. Thank you for sharing.
    AWS Training in Bangalore |Best AWS Training Institute in Bangalore BTM, Marathahalli
    AWS Training in Chennai | AWS Training Institute in Chennai Velachery, Tambaram, OMR

    ReplyDelete
  8. Hmm, it seems like your site ate my first comment (it was extremely long) so I guess I’ll just sum it up what I had written and say, I’m thoroughly enjoying your blog. I as well as an aspiring blog writer, but I’m still new to the whole thing. Do you have any recommendations for newbie blog writers? I’d appreciate it.
    Best Selenium Training in Chennai | Selenium Training Institute in Chennai | Besant Technologies

    ReplyDelete
  9. You truly did more than visitors’ expectations. Thank you for rendering these helpful, trusted, edifying and also cool thoughts on the topic to Kate.
    best safety course in chennai

    ReplyDelete
  10. Fantastic work! This is the type of information that should follow collective approximately the web. Embarrassment captivating position Google for not positioning this transmit higher! Enlarge taking place greater than and visit my web situate
    angularjs online training

    apache spark online training

    informatica mdm online training

    devops online training

    aws online training

    ReplyDelete
  11. Very well written blog and I always love to read blogs like these because they offer very good information to readers with very less amount of words....thanks for sharing your info with us and keep sharing.

    Microsoft Azure online training
    Selenium online training
    Java online training
    Java Script online training
    Share Point online training


    ReplyDelete
  12. Your very own commitment to getting the message throughout came to be rather powerful and have consistently enabled employees just like me to arrive at their desired goals.

    Best PHP Training Institute in Chennai|PHP Course in chennai
    Best .Net Training Institute in Chennai
    Dotnet Training in Chennai
    Dotnet Training in Chennai

    ReplyDelete
  13. such a great word which you use in your article and article is amazing knowledge. thank you for sharing it.

    Softgen Infotech is the Best SAP HANA Training in Bangalore located in BTM Layout, Bangalore providing quality training with Realtime Trainers and 100% Job Assistance.

    ReplyDelete
  14. This is a nice article here with some useful tips for those who are not used-to comment that frequently. Thanks for this helpful information I agree with all points you have given to us. I will follow all of them.
    web designing training in chennai

    web designing training in tambaram

    digital marketing training in chennai

    digital marketing training in tambaram

    rpa training in chennai

    rpa training in tambaram

    tally training in chennai

    tally training in tambaram

    ReplyDelete
  15. Thank you for posting informative insights, I think we have got some more information to share with! Do check out
    oracle training in chennai and let us know your thoughts. Let’s have great learning!

    ReplyDelete
  16. Thank you for posting informative insights, I think we have got some more information to share with! Do check out
    oracle dba training in chennai and let us know your thoughts. Let’s have great learning!

    ReplyDelete
  17. Grab the Digital Marketing Training in Chennai from Infycle Technologies, the best software training institute, and Placement center in Chennai which is providing professional software courses such as Data Science, Artificial Intelligence, Cyber Security, Big Data, Java, Hadoop, Selenium, Android, and iOS Development, DevOps, Oracle, etc with 100% hands-on practical training. Dial 7502633633 to get more info and a free demo and to grab the certification for having a peak rise in your career.

    ReplyDelete
  18. This comment has been removed by the author.

    ReplyDelete