4

I need to run the tests in a feature file with multiple endpoint urls. All the tests hit REST endpoints and I need to hit multiple endpoints for the same tests. I came up with the two below working solutions, but they both have maintenance overhead. So I was wondering if there is a better solution.

1. Add a dummy feature file: Add a new dummy feature file and call the actual feature file with the endpoint url as argument like below. The actual feature file has test data of 100 rows. So when this was executed individually, the cucumber report showed 100 scenarios and it was easy to see how many passed/failed. But when executed with the dummy feature file, the report shows only 1 scenario from the dummy feature file and shows all the 100 test cases underneath it.

  Scenario: Call actual feature file with internal URL
    * def params = { endpoint_url: 'internal' }
    * karate.callSingle('actualTestCases.feature', params);

  Scenario: Call actual feature file with public URL
    * def params = { endpoint_url: 'public' }
    * karate.callSingle('actualTestCases.feature', params);

2. Duplicate the test data rows and add a new column endpoint_url: In the test data, add duplicate test data rows, and add a column 'endpoint_url' with values like 'internal', 'public'. Use this column data in the actual feature file. This has the overhead that test data needs to be duplicated. I have more than 3000 rows of test data.

      |testcaseName|email|endpoint_url
      |"Valid Parameters"|["validtests@test.com"]|"internal"
      |"Valid Parameters"|["validtests@test.com"]|"public"

2 Answers2

1

Just use JSON as input file.
If you need to create even more dynamic urls, use karate.map to fill the variable with more values and pass to your feature.

Remember to use Verbs (When, Then, And), so report will show the content. Otherwise you need to configure manually.

Input file urls.json:

[ 
    {"url" : "https://jsonplaceholder.typicode.com/users/1"},
    {"url" : "https://jsonplaceholder.typicode.com/users/2"},
    {"url" : "https://jsonplaceholder.typicode.com/users/3"}
]

Main feature file main.feature:

Feature: Test REST

  Scenario: Dynamic URL Test
    When def urls = read('./urls.json')
    Then call read('_sub.feature') urls

Sub feature file _sub.feature:

@ignore
Feature:

  Scenario: Call URL
    * def keyword = __arg.url
    Given driver keyword
    Then retry(5, 1000).waitUntil("document.readyState == 'complete'")
Luiz Vaz
  • 1,669
  • 1
  • 19
  • 32
0

Use 2 loops or a Scenario Outline:

Scenario Outline:
* call read('actualTestCases.feature')

Examples:
| endpoint_url |
| internal     |
| public       |

Note that endpoint_url will be visible to the "called" feature, so you don't need to worry about passing parameters. Actually I think you can do all of this in a single feature file.

Peter Thomas
  • 54,465
  • 21
  • 84
  • 248
  • Tried the code as suggested. Used 2 files & both of them have 'Scenario Outline'. But karate report still shows one scenario with the 100 test cases underneath it. Sample report below. Also, did not understand the 2 loops solution that you suggested. ** `Scenario Outline: [1.1:9]Call feature file in local env Test 1 : * call read('actualTestCases.feature'); 33.656583 Test 2 : actualTestCases.feature 33.469832 Test 7 : * print 'Test for', "All valid parameters" + "-" + endpoint_path 0.009311 ... Test 30 : * print 'Test for', "null testId" + "-" + endpoint_path 0.004675 ...` ** – karate_newbie Apr 13 '20 at 19:18
  • @karate_newbie this is because I haven't understood your question. so please follow this process: https://github.com/intuit/karate/wiki/How-to-Submit-an-Issue - and make sure it is a SIMPLE example and also I don't understand what is wrong with `one scenario with the 100 test cases underneath it` - it is fine, don't worry about "pretty reports" focus on getting some actual work done, okay ? – Peter Thomas Apr 14 '20 at 03:08
  • Peter its not about pretty report. I am not getting right number of scenarios passed/failed with the above approach. As i am calling three feature files in dummy feature file in the report it is treating each feature file as one scenario and in turn i see in cucumber report three scenarios where as in real i have 100 scenarios/tests – karate_newbie Apr 14 '20 at 06:19