1

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.

aslanTest
  • 23
  • 4
  • 1
    The moment you include some custom code like `Com.helpers.DataGenerator` all bets are off. most likely the way that code written is not thread safe. if you are not able to follow this process, you are not likely to get any help on this from anyone: https://github.com/karatelabs/karate/wiki/How-to-Submit-an-Issue - be before all this - maybe you should just read THIS: https://stackoverflow.com/a/46080568/143475 – Peter Thomas Feb 03 '22 at 04:53

0 Answers0