io.cucumber.core.options.RuntimeOptions Java Examples

The following examples show how to use io.cucumber.core.options.RuntimeOptions. 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: AllureCucumber5JvmTest.java    From allure-java with Apache License 2.0 7 votes vote down vote up
private byte runFeature(final AllureResultsWriterStub writer,
                        final String featureResource,
                        final String... moreOptions) {

    final AllureLifecycle lifecycle = new AllureLifecycle(writer);
    final AllureCucumber5Jvm cucumber5Jvm = new AllureCucumber5Jvm(lifecycle);
    Supplier<ClassLoader> classLoader = ClassLoaders::getDefaultClassLoader;
    final List<String> opts = new ArrayList<>(Arrays.asList(
            "--glue", "io.qameta.allure.cucumber5jvm.samples",
            "--plugin", "null_summary"
    ));
    opts.addAll(Arrays.asList(moreOptions));
    FeatureWithLines featureWithLines = FeatureWithLines.parse("src/test/resources/"+featureResource);
    final RuntimeOptions options = new CommandlineOptionsParser().parse(opts).addFeature(featureWithLines).build();
    boolean mt = options.isMultiThreaded();

    EventBus bus = new TimeServiceEventBus(Clock.systemUTC(), UUID::randomUUID);
    FeatureParser parser = new FeatureParser(bus::generateId);
    FeaturePathFeatureSupplier supplier = new FeaturePathFeatureSupplier(classLoader, options, parser);

    final Runtime runtime = Runtime.builder()
            .withClassLoader(classLoader)
            .withRuntimeOptions(options)
            .withAdditionalPlugins(cucumber5Jvm)
            .withFeatureSupplier(supplier)
            .build();

    runtime.run();
    return runtime.exitStatus();
}
 
Example #2
Source File: FeatureBuilder.java    From cucumber-performance with MIT License 6 votes vote down vote up
public static RuntimeOptions createRuntimeOptions(List<String> args) {
	RuntimeOptions propertiesFileOptions = new CucumberPropertiesParser().parse(CucumberProperties.fromPropertiesFile()).build();
	RuntimeOptions systemOptions = new CucumberPropertiesParser().parse(CucumberProperties.fromSystemProperties()) .build(propertiesFileOptions);
	RuntimeOptions envOptions = new CucumberPropertiesParser().parse(CucumberProperties.fromEnvironment()).build(systemOptions);
	RuntimeOptions runtimeOptions = new CommandlineOptionsParser().parse(args).build(envOptions);
	return runtimeOptions;
}
 
Example #3
Source File: CourgetteRuntimeOptions.java    From courgette-jvm with MIT License 6 votes vote down vote up
public RuntimeOptions getRuntimeOptions() {
    return new CommandlineOptionsParser().parse(runtimeOptions).build();
}
 
Example #4
Source File: CucumberPerf.java    From cucumber-performance with MIT License 6 votes vote down vote up
private void warnProgressFormatter(RuntimeOptions runtimeOptions)
{
	for(Plugin plugin: runtimeOptions.plugins())
	{
		if (plugin.pluginString().equalsIgnoreCase("progress"))
		{
			options.disableDisplay();
			System.out.println("WARNING: Cucumber options contains Progress formatter.");
			System.out.println(	"	This is enabled by default in Cucumber when no formatter is passed in.");
			System.out.println(	"	Disabling all display printers. To enable pass in plugin \"cucumber.formatter.NullFormatter\"");
		} else if (plugin.pluginString().equalsIgnoreCase("default_summary"))
		{
			options.disableDisplay();
			System.out.println("WARNING: Cucumber options contains default summary.");
			System.out.println(	"	This is enabled by default in Cucumber when no formatter is passed in.");
			System.out.println(	"	Disabling all display printers. To enable pass in plugin \"null_summary\"");
		}
	}
}
 
Example #5
Source File: AllureCucumber4JvmTest.java    From allure-java with Apache License 2.0 6 votes vote down vote up
private byte runFeature(final AllureResultsWriterStub writer,
                        final String featureResource,
                        final String... moreOptions) {

    final AllureLifecycle lifecycle = new AllureLifecycle(writer);
    final AllureCucumber4Jvm cucumber4Jvm = new AllureCucumber4Jvm(lifecycle);
    final ClassLoader classLoader = currentThread().getContextClassLoader();
    final ResourceLoader resourceLoader = new MultiLoader(classLoader);
    final ClassFinder classFinder = new ResourceLoaderClassFinder(resourceLoader, classLoader);
    final List<String> opts = new ArrayList<>(Arrays.asList(
            "--glue", "io.qameta.allure.cucumber4jvm.samples",
            "--plugin", "null_summary"
    ));
    opts.addAll(Arrays.asList(moreOptions));
    final RuntimeOptions options = new CommandlineOptionsParser().parse(opts).build();
    boolean mt = options.isMultiThreaded();

    FeatureSupplier featureSupplier = () -> {
        try {
            final String gherkin = readResource(featureResource);
            Parser<GherkinDocument> parser = new Parser<>(new AstBuilder());
            TokenMatcher matcher = new TokenMatcher();
            GherkinDocument gherkinDocument = parser.parse(gherkin, matcher);
            List<PickleEvent> pickleEvents = compilePickles(gherkinDocument, featureResource);
            CucumberFeature feature = new CucumberFeature(gherkinDocument, URI.create(featureResource), gherkin, pickleEvents);

            return Collections.singletonList(feature);
        } catch (IOException e) {
            return Collections.EMPTY_LIST;
        }
    };
    final Runtime runtime = Runtime.builder()
            .withResourceLoader(resourceLoader)
            .withClassFinder(classFinder)
            .withClassLoader(classLoader)
            .withRuntimeOptions(options)
            .withAdditionalPlugins(cucumber4Jvm)
            .withFeatureSupplier(featureSupplier)
            .build();

    runtime.run();
    return runtime.exitStatus();
}
 
Example #6
Source File: FeatureBuilder.java    From cucumber-performance with MIT License 5 votes vote down vote up
public static RuntimeOptions createRuntimeOptions(Class<?> clazz) {
	RuntimeOptions propertiesFileOptions = new CucumberPropertiesParser().parse(CucumberProperties.fromPropertiesFile()).build();
	RuntimeOptions systemOptions = new CucumberPropertiesParser().parse(CucumberProperties.fromSystemProperties()) .build(propertiesFileOptions);
	RuntimeOptions envOptions = new CucumberPropertiesParser().parse(CucumberProperties.fromEnvironment()).build(systemOptions);
	RuntimeOptions runtimeOptions = new CucumberOptionsAnnotationParser().withOptionsProvider(new CucumberOptionsProvider()).parse(clazz).build(envOptions);
	return runtimeOptions;
}
 
Example #7
Source File: CucumberPerf.java    From cucumber-performance with MIT License 5 votes vote down vote up
/**
 * Create a new CucumberPerf instance using a existing class for the cucumber options.
 * All expected features and scenarios must be included in options.
 * Other wise that group will be skipped.
 * @param clazz An existing class with cucumber options (annotations) and cucumber perf options
 */
public CucumberPerf(Class<?> clazz) {
	this.clazz = clazz;
	this.options = new PerfRuntimeOptionsFactory(clazz).create();
	RuntimeOptions ro =  FeatureBuilder.createRuntimeOptions(clazz);
	this.buildRuntime(ro);
}
 
Example #8
Source File: CourgetteLoader.java    From courgette-jvm with MIT License 5 votes vote down vote up
public CourgetteLoader(CourgetteProperties courgetteProperties) {
    this.courgetteProperties = courgetteProperties;

    RuntimeOptions runtimeOptions = createRuntimeOptions();
    this.filters = new Filters(runtimeOptions);

    EventBus eventBus = new TimeServiceEventBus(Clock.systemUTC(), UUID::randomUUID);
    FeatureParser parser = new FeatureParser(eventBus::generateId);
    Supplier<ClassLoader> classLoader = ClassLoaders::getDefaultClassLoader;
    FeaturePathFeatureSupplier featureSupplier = new FeaturePathFeatureSupplier(classLoader, runtimeOptions, parser);

    this.features = featureSupplier.get();
}
 
Example #9
Source File: CucumberPerf.java    From cucumber-performance with MIT License 5 votes vote down vote up
private void buildRuntime(RuntimeOptions ro)
{
	this.features = FeatureBuilder.getFeatures(ro);
	this.featureFilter = new FeatureFilter(this.features);
	this.warnProgressFormatter(ro);
	this.filters = new Filters(this.options);
	PluginFactory pf = new PluginFactory();
	this.plugins = new Plugins(this.getClass().getClassLoader(), pf, this.options);
	this.plugins.setEventBusOnPlugins(this.eventBus);
}
 
Example #10
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 #11
Source File: CourgetteLoader.java    From courgette-jvm with MIT License 4 votes vote down vote up
private RuntimeOptions createRuntimeOptions() {
    return new CourgetteRuntimeOptions(courgetteProperties).getRuntimeOptions();
}
 
Example #12
Source File: JustTestLahRunner.java    From justtestlah with Apache License 2.0 4 votes vote down vote up
/**
 * This is the code taken from {@link io.cucumber.junit.Cucumber}
 *
 * @param clazz {@link Class}
 * @throws InitializationError {@link InitializationError}
 */
private void initCucumber(Class<?> clazz) throws InitializationError {
  Assertions.assertNoCucumberAnnotatedMethods(clazz);

  // Parse the options early to provide fast feedback about invalid options
  RuntimeOptions propertiesFileOptions =
      new CucumberPropertiesParser().parse(CucumberProperties.fromPropertiesFile()).build();

  RuntimeOptions annotationOptions =
      new CucumberOptionsAnnotationParser()
          .withOptionsProvider(new JUnitCucumberOptionsProvider())
          .parse(clazz)
          .build(propertiesFileOptions);

  RuntimeOptions environmentOptions =
      new CucumberPropertiesParser()
          .parse(CucumberProperties.fromEnvironment())
          .build(annotationOptions);

  RuntimeOptions runtimeOptions =
      new CucumberPropertiesParser()
          .parse(CucumberProperties.fromSystemProperties())
          .addDefaultSummaryPrinterIfAbsent()
          .build(environmentOptions);

  if (!runtimeOptions.isStrict()) {
    LOG.warn(
        "By default Cucumber is running in --non-strict mode.\n"
            + "This default will change to --strict and --non-strict will be removed.\n"
            + "You can use --strict or @CucumberOptions(strict = true) to suppress this warning");
  }

  // Next parse the junit options
  JUnitOptions junitPropertiesFileOptions =
      new JUnitOptionsParser().parse(CucumberProperties.fromPropertiesFile()).build();

  JUnitOptions junitAnnotationOptions =
      new JUnitOptionsParser().parse(clazz).build(junitPropertiesFileOptions);

  JUnitOptions junitEnvironmentOptions =
      new JUnitOptionsParser()
          .parse(CucumberProperties.fromEnvironment())
          .build(junitAnnotationOptions);

  JUnitOptions junitOptions =
      new JUnitOptionsParser()
          .parse(CucumberProperties.fromSystemProperties())
          .setStrict(runtimeOptions.isStrict())
          .build(junitEnvironmentOptions);

  this.bus = new TimeServiceEventBus(Clock.systemUTC(), UUID::randomUUID);

  // Parse the features early. Don't proceed when there are lexer errors
  FeatureParser parser = new FeatureParser(bus::generateId);
  Supplier<ClassLoader> classLoader = ClassLoaders::getDefaultClassLoader;
  FeaturePathFeatureSupplier featureSupplier =
      new FeaturePathFeatureSupplier(classLoader, runtimeOptions, parser);
  this.features = featureSupplier.get();

  // Create plugins after feature parsing to avoid the creation of empty files on
  // lexer errors.
  this.plugins = new Plugins(new PluginFactory(), runtimeOptions);

  ObjectFactoryServiceLoader objectFactoryServiceLoader =
      new ObjectFactoryServiceLoader(runtimeOptions);
  ObjectFactorySupplier objectFactorySupplier =
      new ThreadLocalObjectFactorySupplier(objectFactoryServiceLoader);
  BackendSupplier backendSupplier =
      new BackendServiceLoader(clazz::getClassLoader, objectFactorySupplier);
  TypeRegistryConfigurerSupplier typeRegistryConfigurerSupplier =
      new ScanningTypeRegistryConfigurerSupplier(classLoader, runtimeOptions);
  ThreadLocalRunnerSupplier runnerSupplier =
      new ThreadLocalRunnerSupplier(
          runtimeOptions,
          bus,
          backendSupplier,
          objectFactorySupplier,
          typeRegistryConfigurerSupplier);
  Predicate<Pickle> filters = new Filters(runtimeOptions);
  this.children =
      features.stream()
          .map(feature -> FeatureRunner.create(feature, filters, runnerSupplier, junitOptions))
          .filter(runner -> !runner.isEmpty())
          .collect(toList());

  LOG.info(
      "Found {} feature(s) in {}: {}",
      features.size(),
      System.getProperty("cucumber.features"),
      features);
}
 
Example #13
Source File: CucumberRuntime.java    From cucumber-performance with MIT License 4 votes vote down vote up
ExitStatus(RuntimeOptions runtimeOptions) {
    this.runtimeOptions = runtimeOptions;
}
 
Example #14
Source File: CucumberRuntime.java    From cucumber-performance with MIT License 4 votes vote down vote up
public Builder withRuntimeOptions(final RuntimeOptions runtimeOptions) {
    this.runtimeOptions = runtimeOptions;
    return this;
}
 
Example #15
Source File: CucumberPerf.java    From cucumber-performance with MIT License 4 votes vote down vote up
/**
 * Create a new CucumberPerf instance using passed in perf runtime options.
 * @param options Cucumber perf runtime options.
 */
public CucumberPerf(PerfRuntimeOptions options) {
	this.options = options;
	RuntimeOptions ro =  FeatureBuilder.createRuntimeOptions(options.getCucumberOptions());
	this.buildRuntime(ro);
}
 
Example #16
Source File: FeatureBuilder.java    From cucumber-performance with MIT License 4 votes vote down vote up
public static List<Feature> getFeatures(RuntimeOptions runtimeOptions) {
	Supplier<ClassLoader> classLoader = FeatureBuilder.class::getClassLoader;
	FeatureParser parser = new FeatureParser(UUID::randomUUID);
	return new FeaturePathFeatureSupplier(classLoader, runtimeOptions,parser).get();
}
 
Example #17
Source File: CucumberPerf.java    From cucumber-performance with MIT License 3 votes vote down vote up
/**
 * Create a new CucumberPerf instance using a existing class for the cucumber options.
 * All expected features and scenarios must be included in options.
 * Other wise that group will be skipped.
 * @param clazz An existing class with cucumber options (annotations) and option cucumber perf options
 * @param options The performance runtime options.
 */
public CucumberPerf(Class<?> clazz, PerfRuntimeOptions options) {
	this.clazz = clazz;
	this.options = options;
	RuntimeOptions ro =  FeatureBuilder.createRuntimeOptions(clazz);
	this.buildRuntime(ro);
}
 
Example #18
Source File: CucumberPerf.java    From cucumber-performance with MIT License 2 votes vote down vote up
/**
 * Create a new CucumberPerf instance using CLI arguments for the cucumber options.
 * All expected features and scenarios must be included in options.
 * Other wise that group will be skipped.
 * @param args Combined cucumber and cucumber performance CLI arguments.
 */
public CucumberPerf(String[] args) {
	options = new PerfRuntimeOptions(Arrays.asList(args));
	RuntimeOptions ro = FeatureBuilder.createRuntimeOptions(options.getCucumberOptions());
	this.buildRuntime(ro);
}