'Variables defined at Karate Background is not matching with local Scenario ones

Scenario: I send an image_URL at my Request Body to an endpoint, and I would like to confirm image URL is loaded by asserting from the response (Easy peasy)

Background: Get ready
    #Get random image via Java class
    * def dataGenerator = Java.type('Com.helpers.DataGenerator')
    * def randomImage = dataGenerator.getImage()

  Scenario: Pass Image_URL, assert image URL is in the response
    Given url myUrl
    And request
      """
      {
          "image": { "upload_url": #(randomImage) },
      }
      """
    When method POST

    * print "=========image URL============== " + response.metadata.image_url
    * print "=========random Image============== " + (randomImage)
    Then status 201
    Then match response.metadata[*].image_url == (randomImage)

The response is something like this:

{
"metadata": {
    ....,
    "image_url": "https://link/image.jpeg",
    ....}
}


My issue:
`"response.metadata.image_url"` from response is different than `(randomImage)`, hence assertion is failing. 

When I manually run from the postman, Response "image_url" is matching with request body "upload url"

From my understanding, 

* def randomImage should be called once before Every Scenario, so it should be the exact same entire Scenario during runtime.

Not sure if I am missing some obvious concept. Curious to see any guidance on this one

Versions:

     <java.version>1.8</java.version>
<maven.compiler.version>3.8.1</maven.compiler.version>
<maven.surefire.version>2.22.2</maven.surefire.version>
 <artifactId>karate-junit5</artifactId>
<karate.version>1.1.0</karate.version>

Also, my Java Helper class is working fine, but I can add it if needed.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source