karatelabs / karate

Test Automation Made Simple
https://karatelabs.github.io/karate
MIT License
8.26k stars 1.94k forks source link

NPE on afterStep because KarateBackend.getVars() seems to return a null? #158

Closed paulprogrammer closed 7 years ago

paulprogrammer commented 7 years ago

Given a basic feature file and task runner (below) I'm getting an NPE in the CucumberUtils.afterStep() due to the KarateBackend returning a null for getVars(). AFAICT this is not a misconfiguration on my part, but rather a failure of the backend. Please advise.

sanity.feature

Feature: Sanity Check
  As a developer
  I want to ensure that the test framework is active
  So that I can be confident I am testing correctly

  Background:
    * url httpBin

  Scenario: httpBin reflection
    Given path '/anything/foo/bar?baz=quux'
    When method GET
    Then status 200
    And match response contains { "args": {"baz":"quux"}}
    And match response contains { "method": "GET" }

SmokeTest.java

package apigee.feature.sanity;

import com.intuit.karate.junit4.Karate;
import cucumber.api.CucumberOptions;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.runner.RunWith;

/**
 * Created by williamspaul on 8/29/17.
 */
@RunWith(Karate.class)
@CucumberOptions(plugin = {"pretty", "html:target/cucumber"})
public class SmokeTest {

    @BeforeClass
    public static void beforeClass() {}

    @AfterClass
    public static void afterClass() {}

}

The Error

java.lang.NullPointerException
    at com.intuit.karate.cucumber.CucumberUtils.afterStep(CucumberUtils.java:148)
    at com.intuit.karate.cucumber.CucumberUtils.runStep(CucumberUtils.java:140)
    at com.intuit.karate.cucumber.KarateRuntime.runStep(KarateRuntime.java:51)
    at cucumber.runtime.model.StepContainer.runStep(StepContainer.java:44)
    at cucumber.runtime.model.StepContainer.runSteps(StepContainer.java:39)
    at cucumber.runtime.model.CucumberScenario.runBackground(CucumberScenario.java:59)
    at cucumber.runtime.model.CucumberScenario.run(CucumberScenario.java:42)
    at cucumber.runtime.junit.ExecutionUnitRunner.run(ExecutionUnitRunner.java:102)
    at cucumber.runtime.junit.FeatureRunner.runChild(FeatureRunner.java:63)
    at cucumber.runtime.junit.FeatureRunner.runChild(FeatureRunner.java:18)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at cucumber.runtime.junit.FeatureRunner.run(FeatureRunner.java:70)
    at com.intuit.karate.junit4.Karate.runChild(Karate.java:60)
    at com.intuit.karate.junit4.Karate.runChild(Karate.java:25)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at com.intuit.karate.junit4.Karate.run(Karate.java:66)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
    at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:51)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
ptrthomas commented 7 years ago

thanks for reporting this. is an edge case for an error on the FIRST step in a file.

can you hard-code the url like * url 'http://foo.bar' or add some dummy * print 'hello' statement as the first line and see if that works around for now. so you tried the unofficial 0.5.0.3 version right ?

paulprogrammer commented 7 years ago

Same error on 0.5.0.3.

When I hardcode the url I get something about failing to construct the class by name: 'karate-http.properties'

java.lang.RuntimeException: failed to construct class by name: karate-http.properties not found, aborting
    at com.intuit.karate.http.HttpClient.construct(HttpClient.java:266)
    at com.intuit.karate.ScriptContext.<init>(ScriptContext.java:109)
    at com.intuit.karate.StepDefs.<init>(StepDefs.java:82)
    at com.intuit.karate.cucumber.KarateObjectFactory.getInstance(KarateObjectFactory.java:86)
    at cucumber.runtime.java.JavaStepDefinition.execute(JavaStepDefinition.java:38)
    at cucumber.runtime.StepDefinitionMatch.runStep(StepDefinitionMatch.java:37)
    at com.intuit.karate.cucumber.CucumberUtils.runStep(CucumberUtils.java:133)
    at com.intuit.karate.cucumber.KarateRuntime.runStep(KarateRuntime.java:51)
    at cucumber.runtime.model.StepContainer.runStep(StepContainer.java:44)
    at cucumber.runtime.model.StepContainer.runSteps(StepContainer.java:39)
    at cucumber.runtime.model.CucumberScenario.runBackground(CucumberScenario.java:59)
    at cucumber.runtime.model.CucumberScenario.run(CucumberScenario.java:42)
    at cucumber.runtime.junit.ExecutionUnitRunner.run(ExecutionUnitRunner.java:102)
    at cucumber.runtime.junit.FeatureRunner.runChild(FeatureRunner.java:63)
    at cucumber.runtime.junit.FeatureRunner.runChild(FeatureRunner.java:18)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at cucumber.runtime.junit.FeatureRunner.run(FeatureRunner.java:70)
    at com.intuit.karate.junit4.Karate.runChild(Karate.java:60)
    at com.intuit.karate.junit4.Karate.runChild(Karate.java:25)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at com.intuit.karate.junit4.Karate.run(Karate.java:66)
    at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:252)
    at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:141)
    at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:112)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)
    at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165)
    at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85)
    at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115)
    at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75)
    at ✽.* url 'http://httpbin.org'(apigee/feature/sanity/sanity.feature:7)

BTW, I just selected the most recent build on search.maven.org - might want to tag that as unofficial somehow ... or maybe not deploy it to central?

ptrthomas commented 7 years ago

just refer to the doc. you need 2 dependencies. 0.5.0 is the latest official version. I would rather not deploy to central but from experience, many organizations are not able to use SNAPSHOT builds. so this is the compromise solution that we evolved.

ptrthomas commented 7 years ago

documentation was not being followed closing as invalid.

paulprogrammer commented 7 years ago

Verified working with 0.5.0.3