
com.cucumber.utils.context.stepdefs.VarSteps Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of cucumber-jutils Show documentation
Show all versions of cucumber-jutils Show documentation
A little helper for Cucumber Java
package com.cucumber.utils.context.stepdefs;
import com.cucumber.utils.context.ScenarioUtils;
import com.cucumber.utils.context.ScenarioVarsUtils;
import com.cucumber.utils.context.vars.ScenarioVars;
import com.google.inject.Inject;
import io.cucumber.guice.ScenarioScoped;
import io.cucumber.java.en.Given;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import ro.skyah.util.MessageUtil;
import java.util.List;
import java.util.Map;
import java.util.Set;
@ScenarioScoped
public class VarSteps {
private static final Logger LOG = LogManager.getLogger();
@Inject
private ScenarioVars scenarioVars;
@Inject
private ScenarioUtils scenarioUtils;
@Given("var {}=\"{}\"")
public void setVar(String name, Object value) {
scenarioVars.put(name, value);
scenarioUtils.log("var {} = {}", name, value != null ? MessageUtil.cropL(value.toString()) : null);
LOG.debug("var {} = {}", name, value);
}
@Given("var {}=")
public void setVarFromDocString(String name, StringBuilder value) {
setVar(name, value.toString());
}
@Given("var {} from file path \"{}\"")
public void setVarFromFile(String name, String filePath) {
setVar(name, ScenarioVarsUtils.parse(filePath, scenarioVars));
}
@Given("load vars from file \"{}\"")
public void loadScenarioVarsFromFile(String filePath) {
Set propertyNames = ScenarioVarsUtils.loadScenarioVarsFromFile(filePath, scenarioVars);
scenarioUtils.log("Loaded scenario variables having names: {}", propertyNames);
}
@Given("load file \"{}\" to var \"{}\"")
public void loadScenarioVarsFromFile(String filePath, String propertyName) {
ScenarioVarsUtils.loadFileAsScenarioVariable(filePath, scenarioVars, propertyName);
scenarioUtils.log("Loaded scenario variable with name: {}", propertyName);
}
@Given("load vars from dir \"{}\"")
public void loadScenarioVarsFromDir(String dirPath) {
Set propertyNames = ScenarioVarsUtils.loadScenarioVarsFromDir(dirPath, scenarioVars);
scenarioUtils.log("Loaded scenario variables having names: {}", propertyNames);
}
@Given("table {}=")
public void setCustomDataTable(String name, List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy