cucumberkarate

Reference error while running karate test


Hi I am having a karate test , I am trying to iterate through a url list and making an http call . the following is my script . however when i run the script i get an error

 Feature: test
    
      Background:
        * configure ssl = true
        * configure httpVersion = 'http2'
        * def baseUrls = ['http://localhost:28090', 'https://localhost:28091', 'http://localhost:28092', 'https://localhost:28093', 'http://localhost:28081']
      Scenario: Test7
        * def retryEndpoint = '/service/v1/id'
        * def serviceEndpoint = ''
        
        # Loop through service endpoints
        * table baseUrls
        | <serviceBaseUrl>
        Given url serviceBaseUrl
        And path retryEndpoint
        When method get
        Then status 200
        And print response

Error recieved

 javascript evaluation failed: serviceBaseUrl, ReferenceError: "serviceBaseUrl" is not defined in <eval> at line number 1

any idea what is happening and how can i fix the above code ?


Solution

  • I think there is wrong usage of table syntax and confusion with a Scenario Outline. Refer https://stackoverflow.com/a/76618739/143475

    This should get you going:

    Feature:
    
    @setup
    Scenario:
      * def urls = ['http://localhost:28090', 'https://localhost:28091']
      * def data = urls.map(x => ({ baseUrl: x}))
    
    Scenario Outline:
      * print 'baseUrl is:', baseUrl
    
      Examples:
        | karate.setup().data |