How to debug through a cucumber karate project

8.7k Views Asked by At

I have inherited a Java / Maven / Cucumber project. I am fairly new to Cucumber.

Inside one of the folder I have a class like this...

import com.intuit.karate.junit4.Karate;
import org.junit.runner.RunWith;

@RunWith(Karate.class)
public class RoadsRunner {

}

Then in the same subdirectory / package I have a .feature file. with a number of scenario's.

Feature: Check transaction
  Background:
    * url apiHost + '/api/v1'
    * configure headers = {'X-TransactionID': '#(Math.random().toString())' }

    Scenario: Get Classes
      # get classes
      Given path '/myUrl/classes'
      And param processName = 'myProcess'
      When method get
      Then status 200

Question One.

I am using Eclipse. Is there a way I can debug through the test in a similar way that I would debug a Java app?

I have downloaded myself the Cucumber Eclipse plugin but can't quite figure out how to use it.

Question Two.

Without using a custom plugin to debug is there anything I can add to the scenarios to maybe print extra debug information.

thanks

2

There are 2 best solutions below

0
On BEST ANSWER

The Cucumber Eclipse plugin gives you 2 things:

  • IDE syntax coloring / formatting support
  • Being able to right-click and run a Feature directly without the JUnit "runner"

Karate is Java behind the scenes so you can debug and set break-points, but it may not be as seamless as you expect. In 0.6.0 you have the option of placing a conditional break-point in Karate code that runs before / after each test step - see screen-shot.

So as you rightly called out, printing to the log might be the most effective way to work through complicated test scripts. Please refer to the print keyword - which is exactly what you are looking for.

2 more points:

  • the optional HTML report includes all HTTP request / response logs - which is great for troubleshooting a test.
  • I would love for the Karate UI (currently in alpha) to become stable sooner and be the best option for debugging, please do submit feedback and contribute if you can.

EDIT: we now have the Visual Studio Code IDE support with first-class debug support: https://github.com/intuit/karate/wiki/IDE-Support#vs-code-karate-plugin

EDIt2: If you want to debug Java code, that is possible with the new IntelliJ plugin: https://plugins.jetbrains.com/plugin/19232-karate

2
On

As per the documentation here, At this moment best way to debug Karate Steps is using Visual Studio Code for developing tests and VS Code Karate Plugin for debugging.

Visual Studio Code is Free, built on open Source and runs on all platforms including mac/linux and windows.

Please note this

The Karate UI has been retired and is not available in 0.9.5 onwards ! Use the VS Code Debug Support instead.

As per the comment by Peter Thomas, Eclipse/IntelliJ may also support debugging but I am unable to find any development there.