1

my team has been using Karate version 1.2.0 together with jUnit4. Recently we are working on upgrading to Karate version 1.4.0 and jUnit5 then we hit some errors with our existing regression test scenarios.

It seems like the way how variables are initialized by our existing script are not able to be read / picked up during the execution. The following is how the scenarios are written:

We have featureFileA.feature:

Feature: Regression

    Background:
        * url apiUrl
        * def sharedScope = 'classpath:feature/featureFileB.feature'
        * def createAUser = (sharedScope + '@sharedScopeCreateUser')
        * def requestBody =
        """
            {
                "name": "morpheus",
                "job": "leader"
            }
        """


    @regressionCreateUser
    Scenario: Regression
        * call read(createAUser)

And we have featureFileB.feature:

Feature: Create user

    Background: Base and shared endpoint

        * def currentFilePath = 'classpath:feature/featureFileB.feature'
        * def POSTCreateUser = (currentFilePath + '@POSTCreateUser')

    @ignore
    @POSTCreateUser
    Scenario: Create new user
        
        Given path '/api/users'
        And request requestBody
        When method POST

    
    @ignore
    @sharedScopeCreateUser
    Scenario: Shared scope create new user
        * call read(POSTCreateUser)
        Then response.status == 200

With Karate version 1.2.0 together with jUnit4, the execution for @regressionCreateUser has been passing all these times. But after upgrading the version, we are told that it fails to look for the variable url.

Execution result for Karate version 1.4.0 with jUnit5:

12:07:11.204 [main] ERROR com.intuit.karate - classpath:conduitApp/feature/createUser.feature:15
When method POST
incomplete http request, 'url' not set
classpath:conduitApp/feature/createUser.feature:15
12:07:11.215 [main] ERROR com.intuit.karate - classpath:conduitApp/feature/createUser.feature:21
* call read(POSTCreateUser)
incomplete http request, 'url' not set
classpath:conduitApp/feature/createUser.feature:15
classpath:conduitApp/feature/createUser.feature:21
12:07:11.216 [main] ERROR com.intuit.karate - classpath:conduitApp/feature/regressionCreateUser.feature:19
* call read(createAUser)
incomplete http request, 'url' not set
classpath:conduitApp/feature/createUser.feature:15
classpath:conduitApp/feature/createUser.feature:21
classpath:conduitApp/feature/regressionCreateUser.feature:19
---------------------------------------------------------
feature: classpath:conduitApp/feature/regressionCreateUser.feature
scenarios:  1 | passed:  0 | failed:  1 | time: 0.0908
---------------------------------------------------------

12:07:11.947 [main] INFO  com.intuit.karate.Suite - <<fail>> feature 4 of 4 (0 remaining) classpath:conduitApp/feature/regressionCreateUser.feature
12:07:11.948 [main] DEBUG com.intuit.karate.Suite - waiting for 4 features to complete
Karate version: 1.4.0
======================================================
elapsed:   2.80 | threads:    1 | thread time: 0.09 
features:     1 | skipped:    3 | efficiency: 0.03
scenarios:    1 | passed:     0 | failed: 1
======================================================

Execution result for Karate version 1.2.0 with jUnit4:

12:12:20.825 [main] DEBUG com.intuit.karate - request:
1 > POST https://reqres.in/api/users
1 > Content-Type: application/json; charset=UTF-8
1 > Content-Length: 34
1 > Host: reqres.in
1 > Connection: Keep-Alive
1 > User-Agent: Apache-HttpClient/4.5.13 (Java/11.0.18)
1 > Accept-Encoding: gzip,deflate
{"name":"morpheus","job":"leader"}

12:12:21.433 [main] DEBUG com.intuit.karate - response time in milliseconds: 606
1 < 201
1 < Date: Tue, 04 Jul 2023 04:12:21 GMT
1 < Content-Type: application/json; charset=utf-8
1 < Content-Length: 83
1 < Connection: keep-alive
1 < X-Powered-By: Express
1 < Access-Control-Allow-Origin: *
1 < Etag: W/"53-q569yxBoNJJezeruhEO7W2cEpf8"
1 < Via: 1.1 vegur
1 < CF-Cache-Status: DYNAMIC
1 < Report-To: {"endpoints":[{"url":"https:\/\/a.nel.cloudflare.com\/report\/v3?s=05cli6kH4otxcz6NMUKARoGbHtUnBmiUqRCUMlTj8YTxzBVkfmd2M8TuYlFpx93dOXRNjSMolxbcrtb6mvnv57SQ%2F5H8bC%2B87ce43Mhavabm7CgzR4jpbAyP2A%3D%3D"}],"group":"cf-nel","max_age":604800}
1 < NEL: {"success_fraction":0,"report_to":"cf-nel","max_age":604800}
1 < Server: cloudflare
1 < CF-RAY: 7e148787d9b813db-KUL
{"name":"morpheus","job":"leader","id":"80","createdAt":"2023-07-04T04:12:21.392Z"}

---------------------------------------------------------
feature: classpath:conduitApp/feature/regressionCreateUser.feature
scenarios:  1 | passed:  1 | failed:  0 | time: 0.8974
---------------------------------------------------------

12:12:22.224 [main] INFO  com.intuit.karate.Suite - <<pass>> feature 4 of 4 (0 remaining) classpath:conduitApp/feature/regressionCreateUser.feature
12:12:22.225 [main] DEBUG com.intuit.karate.Suite - waiting for 4 features to complete
Karate version: 1.2.0
======================================================
elapsed:   3.33 | threads:    1 | thread time: 0.90 
features:     1 | skipped:    3 | efficiency: 0.27
scenarios:    1 | passed:     1 | failed: 0
======================================================

I am wondering if this is a few feature that we are not aware of from the version update breaking changes? Or it is an issue to be looked into for Karate version 1.4.0 together with jUnit5?

Please do kindly help and advise accordingly. Thank you in advance!

yjAng
  • 11
  • 1
  • first, junit will not affect the behavior, second this is certainly wrong: `Then response.status == 200`, third - we wish teams would provide this feedback when we release RC versions, fourth: it is impossible to make out anything from such a complex example, so please follow this process if you want help: https://github.com/karatelabs/karate/wiki/How-to-Submit-an-Issue, and finally the error message seems to be very clear, `url` is not set, refer: https://github.com/karatelabs/karate/issues/2209 – Peter Thomas Jul 04 '23 at 04:55
  • just so you know, I strongly discourage excessive re-use of tests which I think you are doing, so read this also: https://stackoverflow.com/a/54126724/143475 – Peter Thomas Jul 04 '23 at 04:59

0 Answers0