io.cucumber.core.gherkin.Feature Java Examples

The following examples show how to use io.cucumber.core.gherkin.Feature. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CourgetteLoader.java    From courgette-jvm with MIT License 6 votes vote down vote up
private Map<PickleLocation, Feature> filterCucumberScenarios(List<Feature> features) {
    final Map<PickleLocation, Feature> scenarios = new HashMap<>();

    if (features != null) {
        features.forEach(feature ->
                feature.getPickles().forEach(pickle -> {
                    CourgettePickleMatcher pickleMatcher = new CourgettePickleMatcher(feature, filters);

                    PickleLocation pickleLocation = pickleMatcher.matchLocation(pickle.getLocation().getLine());
                    if (pickleLocation != null) {
                        scenarios.put(pickleLocation, feature);
                    }
                }));
    }
    return scenarios;
}
 
Example #2
Source File: Courgette.java    From courgette-jvm with MIT License 6 votes vote down vote up
public Courgette(Class clazz) throws InitializationError {
    super(clazz);

    final CourgetteOptions courgetteOptions = new CourgetteRunOptions(clazz);
    courgetteProperties = new CourgetteProperties(courgetteOptions, createSessionId(), courgetteOptions.threads());

    callbacks = new CourgetteCallbacks(clazz);

    final CourgetteLoader courgetteLoader = new CourgetteLoader(courgetteProperties);
    features = courgetteLoader.getFeatures();

    runnerInfoList = new ArrayList<>();

    if (courgetteOptions.runLevel().equals(CourgetteRunLevel.FEATURE)) {
        features.forEach(feature -> runnerInfoList.add(new CourgetteRunnerInfo(courgetteProperties, feature, null)));
    } else {
        final Map<PickleLocation, Feature> scenarios = courgetteLoader.getCucumberScenarios();
        scenarios
                .keySet()
                .forEach(location -> runnerInfoList.add(new CourgetteRunnerInfo(courgetteProperties, scenarios.get(location), location.getLine())));
    }
}
 
Example #3
Source File: FeatureBuilder.java    From cucumber-performance with MIT License 6 votes vote down vote up
public static List<ScenarioDefinition> FindScenarios(String prefix, String feature,
		List<Feature> features) {
	List<ScenarioDefinition> result = new ArrayList<ScenarioDefinition>();
	for (Feature f : features) {
		if (f.getName().equalsIgnoreCase(feature)) {
			for (Iterator<Node> iterator = f.children().iterator(); iterator.hasNext();) {
				Node n = iterator.next();
				 if (n instanceof ScenarioDefinition) {
					 if (((ScenarioDefinition)n).getName().startsWith(prefix)) {
						result.add(((ScenarioDefinition)n));
					}
				 }
			}
		}
	}
	return result;
}
 
Example #4
Source File: TestNGCourgette.java    From courgette-jvm with MIT License 6 votes vote down vote up
@BeforeClass(alwaysRun = true)
public void initialize() {
    final CourgetteOptions courgetteOptions = new CourgetteRunOptions(this.getClass());
    courgetteProperties = new CourgetteProperties(courgetteOptions, createSessionId(), courgetteOptions.threads());

    CourgetteLoader courgetteFeatureLoader = new CourgetteLoader(courgetteProperties);
    List<Feature> features = courgetteFeatureLoader.getFeatures();

    runnerInfoList = new ArrayList<>();

    if (courgetteOptions.runLevel().equals(CourgetteRunLevel.FEATURE)) {
        features.forEach(feature -> runnerInfoList.add(new CourgetteRunnerInfo(courgetteProperties, feature, null)));
    } else {
        final Map<PickleLocation, Feature> scenarios = courgetteFeatureLoader.getCucumberScenarios();
        scenarios
                .keySet()
                .forEach(location -> runnerInfoList.add(new CourgetteRunnerInfo(courgetteProperties, scenarios.get(location), location.getLine())));
    }
}
 
Example #5
Source File: CucumberRunner.java    From cucumber-performance with MIT License 6 votes vote down vote up
@Override
public Object call() {
	List<Feature> features = this.getFeatures();
	GroupResult result = null;
	randomWait();
	try {
		start();
		for (Feature f : features) {
			runFeature(f, options.getSlice());
		}
		finish();
		result = resultListener.getResult();
		result.setChildResults(scenarioResults);
	} catch (Throwable e) {
		result = (resultListener.getResult() != null) ? resultListener.getResult()
				: new GroupResult(this.options.getGroupText(),
						new Result(Status.FAILED, Duration.ofMillis(0), e), LocalDateTime.now(), LocalDateTime.now());
		result.setChildResults(scenarioResults);
	}
	return result;
}
 
Example #6
Source File: FeatureFilter.java    From cucumber-performance with MIT License 6 votes vote down vote up
public static boolean isMatch(Feature feature, String text) {
	if (text.startsWith("@")) {
		List<String> tags = getGroupTags(text);
		TagPredicate tp = new TagPredicate(tags);
		for (Pickle pe : feature.getPickles()) {
			if (tp.test(pe)) {
				return true;
			}
		}
	} else {
		if (feature.getName().equalsIgnoreCase(text) || feature.getUri().toString()
				.substring(feature.getUri().toString().lastIndexOf("/") + 1).equalsIgnoreCase(text))
			return true;
	}
	return false;
}
 
Example #7
Source File: FeatureFilter.java    From cucumber-performance with MIT License 6 votes vote down vote up
private Feature getMatch(Feature feature, String text) {
	if (text.startsWith("@")) {
		Feature result = feature;//new Feature(feature.children(), feature.getUri(), "", feature.getPickles());
		List<String> tags = getGroupTags(text);
		TagPredicate tp = new TagPredicate(tags);
		boolean isValid = false;
		for (int p = 0; p<result.getPickles().size();p++) {
			if (!tp.test(result.getPickles().get(p))) {
				result.getPickles().remove(p);
			} else {
				isValid = true;
			}
		}
		if (isValid)
		{
			return result;
		}
	} else {
		if (feature.getName().equalsIgnoreCase(text) || feature.getUri().toString()
				.substring(feature.getUri().toString().lastIndexOf("/") + 1).equalsIgnoreCase(text))
			return feature;
	}
	return null;
}
 
Example #8
Source File: CucumberRuntime.java    From cucumber-performance with MIT License 6 votes vote down vote up
private CucumberRuntime(final ExitStatus exitStatus,
                final EventBus bus,
                final Predicate<Pickle> filter,
                final int limit,
                final RunnerSupplier runnerSupplier,
                final List<Feature> features,
                final ExecutorService executor,
                final PickleOrder pickleOrder,
                final boolean failFast) {
    this.bus = bus;
    this.filter = filter;
    this.limit = limit;
    this.runnerSupplier = runnerSupplier;
    //this.featureSupplier = featureSupplier;
    this.features = features;
    this.executor = executor;
    this.exitStatus = exitStatus;
    this.pickleOrder = pickleOrder;
    this.failFast = failFast;
}
 
Example #9
Source File: FeatureFilter.java    From cucumber-performance with MIT License 5 votes vote down vote up
public List<Feature> filter(String text) {
	List<Feature> features = new ArrayList<Feature>();
	for (Feature feature : this.features) {
		Feature result =this.getMatch(feature, text);
		if (result != null) {
			features.add(feature);
		}
	}
	return features;
}
 
Example #10
Source File: CourgetteRuntimeOptions.java    From courgette-jvm with MIT License 5 votes vote down vote up
public CourgetteRuntimeOptions(CourgetteProperties courgetteProperties, Feature feature) {
    this.courgetteProperties = courgetteProperties;
    this.feature = feature;
    this.cucumberOptions = courgetteProperties.getCourgetteOptions().cucumberOptions();
    this.cucumberResourcePath = feature.getUri().getSchemeSpecificPart();
    this.reportTargetDir = courgetteProperties.getCourgetteOptions().reportTargetDir();

    createRuntimeOptions(cucumberOptions, cucumberResourcePath).forEach((key, value) -> runtimeOptions.addAll(value));
}
 
Example #11
Source File: JustTestLahRunner.java    From justtestlah with Apache License 2.0 5 votes vote down vote up
@Override
public void evaluate() throws Throwable {
  if (multiThreadingAssumed) {
    plugins.setSerialEventBusOnEventListenerPlugins(bus);
  } else {
    plugins.setEventBusOnEventListenerPlugins(bus);
  }

  bus.send(new TestRunStarted(bus.getInstant()));
  for (Feature feature : features) {
    bus.send(new TestSourceRead(bus.getInstant(), feature.getUri(), feature.getSource()));
  }
  runFeatures.evaluate();
  bus.send(new TestRunFinished(bus.getInstant()));
}
 
Example #12
Source File: FeatureFilterTest.java    From cucumber-performance with MIT License 5 votes vote down vote up
@Test
public void filterNameTest() {
	PerfRuntimeOptions options = new PerfRuntimeOptions(Arrays.asList(new String[] {"-g steps","src/test/java/resources"}));
	List<Feature>  features = FeatureBuilder.getFeatures(FeatureBuilder.createRuntimeOptions(options.getCucumberOptions()));
	FeatureFilter filter = new FeatureFilter(features);
	List<Feature> ffs = filter.filter("test.feature");
	assertEquals(ffs.get(0).getName(),"test");
	assertEquals(ffs.get(0).getPickles().size(),4);
}
 
Example #13
Source File: FeatureFilterTest.java    From cucumber-performance with MIT License 5 votes vote down vote up
@Test
public void filterMultiTagTest() {
	PerfRuntimeOptions options = new PerfRuntimeOptions(Arrays.asList(new String[] {"-g steps","src/test/java/resources"}));
	List<Feature>  features = FeatureBuilder.getFeatures(FeatureBuilder.createRuntimeOptions(options.getCucumberOptions()));
	FeatureFilter filter = new FeatureFilter(features);
	List<Feature> ffs = filter.filter("@onlyfilter or @only");
	assertEquals(ffs.size(),2);
	assertEquals(ffs.get(0).getPickles().size(),2);
	assertEquals(ffs.get(1).getPickles().size(),2);
}
 
Example #14
Source File: FeatureFilterTest.java    From cucumber-performance with MIT License 5 votes vote down vote up
@Test
public void filterTagTest() {
	PerfRuntimeOptions options = new PerfRuntimeOptions(Arrays.asList(new String[] {"-g steps","src/test/java/resources"}));
	List<Feature>  features = FeatureBuilder.getFeatures(FeatureBuilder.createRuntimeOptions(options.getCucumberOptions()));
	FeatureFilter filter = new FeatureFilter(features);
	List<Feature> ffs = filter.filter("@onlyfilter");
	assertEquals(ffs.get(0).getPickles().size(),2);
}
 
Example #15
Source File: FeatureFilterTest.java    From cucumber-performance with MIT License 5 votes vote down vote up
@Test
public void filterTagReduceScenarioTest() {
	PerfRuntimeOptions options = new PerfRuntimeOptions(Arrays.asList(new String[] {"-g steps","src/test/java/resources"}));
	List<Feature>  features = FeatureBuilder.getFeatures(FeatureBuilder.createRuntimeOptions(options.getCucumberOptions()));
	FeatureFilter filter = new FeatureFilter(features);
	List<Feature> ffs = filter.filter("@onlyfilter1");
	assertEquals(ffs.get(0).getPickles().size(),1);
}
 
Example #16
Source File: CourgetteJUnitRunner.java    From courgette-jvm with MIT License 5 votes vote down vote up
protected void notifyTestFailure(RunNotifier notifier, List<CourgetteRunResult> failures) {
    failures.forEach(failure -> {
        Feature feature = failure.getFeature();
        Description description = featureDescriptions.get(feature);
        notifier.fireTestFailure(new Failure(description, new CourgetteTestFailureException("Please refer to Courgette / Cucumber report for more info.")));
    });
    featureDescriptions.keySet().removeAll(failures.stream().map(CourgetteRunResult::getFeature).collect(Collectors.toList()));
}
 
Example #17
Source File: FeatureBuilder.java    From cucumber-performance with MIT License 5 votes vote down vote up
public static List<Feature> FindFeatures(String prefix, List<Feature> features) {
	List<Feature> result = new ArrayList<Feature>();
	for (Feature f : features) {
		if (f.getName().toLowerCase().startsWith(prefix)) {
			result.add(f);
		}
	}
	return result;
}
 
Example #18
Source File: FeatureBuilder.java    From cucumber-performance with MIT License 5 votes vote down vote up
public static List<List<ScenarioDefinition>> GetScenarios(List<Feature> features) {
	List<List<ScenarioDefinition>> result = new ArrayList<List<ScenarioDefinition>>();
	for (Feature f : features) {
		List<ScenarioDefinition> sc = new ArrayList<ScenarioDefinition>();
		for (Iterator<Node> iterator = f.children().iterator(); iterator.hasNext();) {
			Node n = iterator.next();
			 if (n instanceof ScenarioDefinition) {
					sc.add(((ScenarioDefinition)n));
			 }
		}
		result.add(sc);
	}
	return result;
}
 
Example #19
Source File: CucumberRunner.java    From cucumber-performance with MIT License 5 votes vote down vote up
/**
 * @return List of detected cucumber features
 */
public List<Feature> getFeatures() {

	if (this.options.getFeatures() == null) {
		return featureSupplier.get();
	}
	return this.options.getFeatures();
}
 
Example #20
Source File: CucumberRunner.java    From cucumber-performance with MIT License 5 votes vote down vote up
private void runFeature(Feature cucumberFeature, Slice slice) throws Throwable {
	List<Pickle> pickles = createPickles(cucumberFeature, slice);
	for (Pickle pickle : pickles) {
		if (filters.test(pickle)) {
			runScenario(pickle);
		}
	}
}
 
Example #21
Source File: CourgetteLoader.java    From courgette-jvm with MIT License 5 votes vote down vote up
private List<Feature> filterFeatures() {
    final List<Feature> matchedFeatures = new ArrayList<>();

    features.forEach(feature -> {
        CourgettePickleMatcher pickleMatcher = new CourgettePickleMatcher(feature, filters);

        if (pickleMatcher.matches()) {
            matchedFeatures.add(feature);
        }
    });
    return matchedFeatures;
}
 
Example #22
Source File: CucumberRunner.java    From cucumber-performance with MIT License 5 votes vote down vote up
public static List<Pickle> createPickles(Feature feature, Slice slice) {
    if (slice!= null) {
	    List<Pickle> pickles = new ArrayList<Pickle>();
	    for (Pickle pickle : feature.getPickles()) {
	    	pickles.add(new PerfPickle(pickle,slice));
	    }
	    return pickles;
    } else {
    	return feature.getPickles();
    }
}
 
Example #23
Source File: CucumberRunner.java    From cucumber-performance with MIT License 5 votes vote down vote up
private void configListeners() {
	// Pre Cucumber 4.0.0
	// trying to remove pretty but doesn't seem possible
	// you can do getPlugins() before creating the runtime to disable all plugins
	// however
	/*
	 * for (int i = 0; i <runtimeOptions.getPlugins().size();i++) {
	 * if(runtimeOptions.getPlugins().get(i).getClass().isInstance(new
	 * PluginFactory().create("pretty"))) { runtimeOptions.getPlugins().remove(i);
	 * System.out.println(""+runtimeOptions.getPlugins().get(i).getClass()); } }
	 */
	// reporter.setEventPublisher(eventBus);

	// Post Cucumber 4.0.0
	// Enable plugins
	// StepDefinitionReporter stepDefinitionReporter =
	// plugins.stepDefinitionReporter();
	// runnerSupplier.get().reportStepDefinitions(stepDefinitionReporter);

	for (Feature feature : this.options.getFeatures()) {
		 eventBus.send(new TestSourceRead(eventBus.getInstant(), feature.getUri(), feature.getSource()));
	}

	// Enable plugins
	// StepDefinitionReporter stepDefinitionReporter =
	// plugins.stepDefinitionReporter();
	// runnerSupplier.get().reportStepDefinitions(stepDefinitionReporter);

	resultListener = new GroupResultListener();
	resultListener.setEventPublisher(eventBus);
	resultListener.setGroupName(options.getGroupText());

	testCaseResultListener = new TestCaseResultListener();
	testCaseResultListener.setEventPublisher(eventBus);

	stepResultListener = new StepResultListener();
	stepResultListener.setEventPublisher(eventBus);
}
 
Example #24
Source File: CucumberTestUnitFinder.java    From pitest-cucumber-plugin with Apache License 2.0 4 votes vote down vote up
public List<TestUnit> findTestUnits(Class<?> junitTestClass) {

        if (hasACucumberAnnotation(junitTestClass)) {

            List<TestUnit> result = new ArrayList<>();

            RuntimeOptions runtimeOptions = new CucumberOptionsAnnotationParser()
                .withOptionsProvider(new CustomProvider())
                .parse(junitTestClass)
                .build();

            TimeServiceEventBus bus = new TimeServiceEventBus(Clock.systemUTC(), UUID::randomUUID);
            FeatureParser parser = new FeatureParser(bus::generateId);

            FeatureSupplier featureSupplier = new FeaturePathFeatureSupplier(junitTestClass::getClassLoader, runtimeOptions, parser);
            final List<Feature> cucumberFeatures = featureSupplier.get();
            final Filters filters = new Filters(runtimeOptions);
            EventBus eventBus = new TimeServiceEventBus(Clock.systemUTC(), UUID::randomUUID);
            ObjectFactoryServiceLoader objectFactoryServiceLoader = new ObjectFactoryServiceLoader(runtimeOptions);
            ObjectFactorySupplier objectFactorySupplier = new ThreadLocalObjectFactorySupplier(objectFactoryServiceLoader);
            BackendSupplier backendSupplier = new BackendServiceLoader(junitTestClass::getClassLoader, objectFactorySupplier);
            TypeRegistryConfigurerSupplier typeRegistryConfigurerSupplier = new ScanningTypeRegistryConfigurerSupplier(junitTestClass::getClassLoader, runtimeOptions);
            RunnerSupplier runnerSupplier = new SingletonRunnerSupplier(runtimeOptions, eventBus, backendSupplier, objectFactorySupplier, typeRegistryConfigurerSupplier);
            for (Feature feature : cucumberFeatures) {
                Log.getLogger().fine("Found feature \"" + feature.getName() + "\"");
                List<Pickle> pickles = feature.getPickles();
                for (Pickle pickle : pickles) {
                    if (!filters.test(pickle)) continue;
                    Description description = new Description(
                        feature.getName() + " : " + pickle.getName(),
                        junitTestClass);
                    Log.getLogger().fine("Found \"" + description.getName() + "\"");
                    result.add(new ScenarioTestUnit(description, pickle, runnerSupplier, eventBus));
                }
            }

            return result;

        }

        return Collections.emptyList();
    }
 
Example #25
Source File: CourgetteRunResult.java    From courgette-jvm with MIT License 4 votes vote down vote up
public Feature getFeature() {
    return feature;
}
 
Example #26
Source File: CourgetteRuntimeOptions.java    From courgette-jvm with MIT License 4 votes vote down vote up
private String getFeatureId(Feature feature) {
    return String.format("%s_%s", feature.hashCode(), instanceId);
}
 
Example #27
Source File: CourgetteRunnerInfo.java    From courgette-jvm with MIT License 4 votes vote down vote up
public CourgetteRunnerInfo(CourgetteProperties courgetteProperties, Feature feature, Integer lineId) {
    this.feature = feature;
    this.courgetteRuntimeOptions = new CourgetteRuntimeOptions(courgetteProperties, feature);
    this.lineId = lineId;
    this.courgetteRunLevel = courgetteProperties.getCourgetteOptions().runLevel();
}
 
Example #28
Source File: CourgetteLoader.java    From courgette-jvm with MIT License 4 votes vote down vote up
public Map<PickleLocation, Feature> getCucumberScenarios() {
    return filterCucumberScenarios(features);
}
 
Example #29
Source File: CourgetteLoader.java    From courgette-jvm with MIT License 4 votes vote down vote up
public List<Feature> getFeatures() {
    return filterFeatures();
}
 
Example #30
Source File: CourgetteRunnerInfo.java    From courgette-jvm with MIT License 4 votes vote down vote up
public Feature getFeature() {
    return feature;
}