konradm
konradm

Reputation: 83

How to pass arguments to karate feature file from selenium java test file

I want to pass an argument to karate graphql test from selenium java test. I tried to do that this way, but it didn't work.

HashMap<String, Object> args = new HashMap<String, Object>();
args.put("argument1", "value1");
Map<String, Object> result = CucumberRunner.runFeature(featureFile, 
args, true);

I tried to put that value in karate file in ways like

<argument1>

or

#(argument1)

but literally this text was passed to query in karate test. Have someone done that by karate?

Here you have fragment of my feature file:

Given text query =
"""
{
  element(name:"<argument1>") {
    name
  }
}
"""
And request {query: '#(query)'}
When method post
Then status 200
* print response

Upvotes: 1

Views: 1212

Answers (1)

Peter Thomas
Peter Thomas

Reputation: 58058

I think you missed a replace, try this:

Given text query =
"""
{
  element(name:"<argument1>") {
    name
  }
}
"""
And replace query.argument1 = argument1
And request {query: '#(query)'}
When method post
Then status 200

Upvotes: 2

Related Questions