[Cucumber] Run with Cucumber Runner


This is a companion discussion topic for the original entry at https://docs.katalon.com/katalon-studio/docs/cucumber-kw-run-cucumber-runner.html

I am using 7.2 version of Katalon, I tried to execute BDD with Cucumber Runner. I am facing some difficulty while executing TC with below statement.

CucumberKW.runWithCucumberRunner(CucumberRunner.class)

Kindly let me know if this feature is not working in 7.2 version

Please share us your difficulties. You can also refer to our doc:

This keyword is not working in 7.2.6 version, Please let me know how to resolve it.
Please find the error message

03-12-2020 03:15:59 PM Test Cases/BDDTests/CucumberTC

Elapsed time: 0.439s

Test Cases/BDDTests/CucumberTC FAILED.
Reason:
groovy.lang.MissingPropertyException: No such property: CucumberRunner for class: Script1583939058141
at CucumberTC.run(CucumberTC:23)
at com.kms.katalon.core.main.ScriptEngine.run(ScriptEngine.java:194)
at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(ScriptEngine.java:119)
at com.kms.katalon.core.main.TestCaseExecutor.runScript(TestCaseExecutor.java:337)
at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:328)
at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:307)
at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:299)
at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:233)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:114)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:105)
at com.kms.katalon.core.main.TestCaseMain$runTestCase$0.call(Unknown Source)
at TempTestCase1584006356540.run(TempTestCase1584006356540.groovy:23)

You need to declare your own CucumberRunner.class

Thank you for your quickest reply.

I have added my own Cucumber runner, Path is like

Include/scripts/(own package is created)/keyword named as CucumberRunner
please find the code inside it.

package com.cucumber.testrunner
import static com.kms.katalon.core.checkpoint.CheckpointFactory.findCheckpoint
import static com.kms.katalon.core.testcase.TestCaseFactory.findTestCase
import static com.kms.katalon.core.testdata.TestDataFactory.findTestData
import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject

import com.kms.katalon.core.annotation.Keyword
import com.kms.katalon.core.checkpoint.Checkpoint
import com.kms.katalon.core.checkpoint.CheckpointFactory
import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as Mobile
import com.kms.katalon.core.model.FailureHandling
import com.kms.katalon.core.testcase.TestCase
import com.kms.katalon.core.testcase.TestCaseFactory
import com.kms.katalon.core.testdata.TestData
import com.kms.katalon.core.testdata.TestDataFactory
import com.kms.katalon.core.testobject.ObjectRepository
import com.kms.katalon.core.testobject.TestObject
import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI

import internal.GlobalVariable

import org.openqa.selenium.WebElement
import org.openqa.selenium.WebDriver
import org.openqa.selenium.By

import com.kms.katalon.core.mobile.keyword.internal.MobileDriverFactory
import com.kms.katalon.core.webui.driver.DriverFactory

import com.kms.katalon.core.testobject.RequestObject
import com.kms.katalon.core.testobject.ResponseObject
import com.kms.katalon.core.testobject.ConditionType
import com.kms.katalon.core.testobject.TestObjectProperty

import com.kms.katalon.core.mobile.helper.MobileElementCommonHelper
import com.kms.katalon.core.util.KeywordUtil

import com.kms.katalon.core.webui.exception.WebElementNotFoundException

import cucumber.api.java.en.And
import cucumber.api.java.en.Given
import cucumber.api.java.en.Then
import cucumber.api.java.en.When

import org.junit.runner.RunWith;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;

@RunWith(Cucumber.class)
@CucumberOptions(features=“Include/features”, glue=" ", plugin = [“pretty”,
“junit:D:/BDD_Reports/cucumber.xml”,
“html:D:/BDD_Reports”,
“json:D:/BDD_Reports/cucumber.json”])

public class CucumberRunner {
}

Actually I am facing issue when I created a Test case and using the cucumber key word “run with cucumber runner”

CucumberKW.runWithCucumberRunner(CucumberRunner.class)

getting issue with CucumberRunner.class

@m.sivakrishna

You need to import: com.cucumber.testrunner package in the test case script.

import com.cucumber.testrunner

Thank You, Compilation error is gone but unable to run it and getting below error.

Test Cases/BDDTests/CucumberTC FAILED.
Reason:
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
file:/C:/Users/msivakrishna/Katalon%20Studio/DemoTest/Scripts/BDDTests/CucumberTC/Script1583939058141.groovy: 17: unable to resolve class com.cucumber.CucumberRunner
@ line 17, column 1.
import com.cucumber.CucumberRunner
^

1 error

at com.kms.katalon.core.main.ScriptEngine.getScript(ScriptEngine.java:199)
at com.kms.katalon.core.main.ScriptEngine.run(ScriptEngine.java:194)
at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(ScriptEngine.java:119)
at com.kms.katalon.core.main.TestCaseExecutor.runScript(TestCaseExecutor.java:337)
at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:328)
at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:307)
at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:299)
at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:233)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:114)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:105)
at com.kms.katalon.core.main.TestCaseMain$runTestCase$0.call(Unknown Source)
at TempTestCase1584010286837.run(TempTestCase1584010286837.groovy:23)

Kindly help me on this

You need to import:

import com.cucumber.testrunner.CucumberRunner

or press Ctrl + Shift + O on your test script

Wonderful, Thank you so much for your help.

how can we add tags attribute in Cucumber runner, Could you please suggest. Please find the code I am using but getting error at tags attribute.

package com.cucumber.testrunner
import static com.kms.katalon.core.checkpoint.CheckpointFactory.findCheckpoint
import static com.kms.katalon.core.testcase.TestCaseFactory.findTestCase
import static com.kms.katalon.core.testdata.TestDataFactory.findTestData
import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject

import com.kms.katalon.core.annotation.Keyword
import com.kms.katalon.core.checkpoint.Checkpoint
import com.kms.katalon.core.checkpoint.CheckpointFactory
import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as Mobile
import com.kms.katalon.core.model.FailureHandling
import com.kms.katalon.core.testcase.TestCase
import com.kms.katalon.core.testcase.TestCaseFactory
import com.kms.katalon.core.testdata.TestData
import com.kms.katalon.core.testdata.TestDataFactory
import com.kms.katalon.core.testobject.ObjectRepository
import com.kms.katalon.core.testobject.TestObject
import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI

import internal.GlobalVariable

import org.openqa.selenium.WebElement
import org.openqa.selenium.WebDriver
import org.openqa.selenium.By

import com.kms.katalon.core.mobile.keyword.internal.MobileDriverFactory
import com.kms.katalon.core.webui.driver.DriverFactory

import com.kms.katalon.core.testobject.RequestObject
import com.kms.katalon.core.testobject.ResponseObject
import com.kms.katalon.core.testobject.ConditionType
import com.kms.katalon.core.testobject.TestObjectProperty

import com.kms.katalon.core.mobile.helper.MobileElementCommonHelper
import com.kms.katalon.core.util.KeywordUtil

import com.kms.katalon.core.webui.exception.WebElementNotFoundException

import cucumber.api.java.en.And
import cucumber.api.java.en.Given
import cucumber.api.java.en.Then
import cucumber.api.java.en.When

import org.junit.runner.RunWith;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;

@RunWith(Cucumber.class)
@CucumberOptions(features=“Include/features”, glue="", tags={"@login","@Products"} plugin = [“pretty”,
“junit:Reports/cucumber.xml”,
“html:Reports”,
“json:Reports/cucumber.json”])

public class CucumberRunner {
}

Could you please reply

Hi, is there any way to generate reports using Serenity BDD? By doing @RunWith(CucumberWithSerenity.class)?

I’ve added the depencies using gradle but I’m still getting some errors.

I’m facing issue with running the feature file with cucumber runner. The feature file is executed fine by using test suite. I’m following the docs instructions of simple example #1 to create a cucumber runner, but the execution failed. Thank you for any help:

04-29-2020 02:21:22 PM Test Cases/operations/MyRunner

Elapsed time: 0,676s

Test Cases/operations/MyRunner FAILED.
Reason:
java.lang.IllegalArgumentException: argument type mismatch
at MyRunner.run(MyRunner:18)
at com.kms.katalon.core.main.ScriptEngine.run(ScriptEngine.java:194)
at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(ScriptEngine.java:119)
at com.kms.katalon.core.main.TestCaseExecutor.runScript(TestCaseExecutor.java:337)
at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:328)
at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:307)
at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:299)
at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:233)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:114)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:105)
at com.kms.katalon.core.main.TestCaseMain$runTestCase$0.call(Unknown Source)
at TempTestCase1588162880073.run(TempTestCase1588162880073.groovy:25)

@m.sivakrishna I faced the same issue with exactly the same errors. My problem was that when I created the CucumberRunner class it had groovy extension not java. Make sure that you create the class as a new java class