RobotActions1
RobotActions1

Reputation: 13

How to configure karate-config to only run block of code if certain conditions are met

I am completely new to Karate and had a question regarding the karate-config.js file.

I understand it is the first to run as "config" for all the scripts- sort of global settings.

What I have written are a few test cases that require different "setup" steps that cannot be done in the Background (what I understand runs after karate-config.js) for each test scenario.

I have two Feature files with scenarios in them. One of the feature file requires this setup from the karate-config.js. The other Feature file doesn't. Right now the setup is running for both Feature files when I only want it to run for the first one.

I was thinking I could tag each Feature file with a unique tag and use an If statement in karate-config.js to only run if this tag is present. However, that likely won't work since the Feature files don't get accessed until after karate-config.js is traversed right?

Is there a way to get this done?

Sorry if the description is long.

Upvotes: 1

Views: 529

Answers (1)

Peter Thomas
Peter Thomas

Reputation: 58088

I think you are overcomplicating things. If something is not to be used in all features, please don't put it in karate-config.js.

Just go with the strategy of having 2 re-usable features and call them in the Background where needed. This is what is done in normal programming languages, and Karate in that regard is no different.

You seem to be trying to save one line of code being repeated in multiple files. My advice: don't.

Upvotes: 0

Related Questions