I also had the same problem when I need to skip a script from running based on a flag that I get from the application dynamically at runtime, which indicates whether the tested function is enabled in the application or not ..
so this is how I wrote my logic in a script file, where we have glue code for each step.
I used the unique tag '@ Feature-01AXX' to mark my scripts that need to be run only when this function (code) is available in the application.
therefore, for each script, the '@ Feature-01XX' tag is checked first, if it is present, then the availability of this function is checked, only then the script will be selected to run. Otherwise, it will simply be skipped and Dunnit will not mark it as a failure, instead it will be marked as Pass. Thus, the end result, if these tests were not performed due to the unavailability of the function, will pass, this is cool ...
@Before public void before(final Scenario scenario) throws Exception { /* my other pre-setup tasks for each scenario. */ // get all the scenario tags from the scenario head. final ArrayList<String> scenarioTags = new ArrayList<>(); scenarioTags.addAll(scenario.getSourceTagNames()); // check if the feature is enabled on the appliance, so that the tests can be run. if (checkForSkipScenario(scenarioTags)) { throw new AssumptionViolatedException("The feature 'Feature-01AXX' is not enabled on this appliance, so skipping"); } } private boolean checkForSkipScenario(final ArrayList<String> scenarioTags) { // I use a tag "@Feature-01AXX" on the scenarios which needs to be run when the feature is enabled on the appliance/application if (scenarioTags.contains("@Feature-01AXX") && !isTheFeatureEnabled()) { // if feature is not enabled, then we need to skip the scenario. return true; } return false; } private boolean isTheFeatureEnabled(){ /* my logic to check if the feature is available/enabled on the application. in my case its an REST api call, I parse the JSON and check if the feature is enabled. if it is enabled return 'true', else return 'false' */ }
source share