cucumber.runtime.model.CucumberFeature Java Examples

The following examples show how to use cucumber.runtime.model.CucumberFeature. 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: 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 #2
Source File: CucumberLoadRunner.java    From cukes with Apache License 2.0 6 votes vote down vote up
/**
 * Constructor called by JUnit.
 *
 * @param clazz the class with the @RunWith annotation.
 * @throws java.io.IOException                         if there is a problem
 * @throws org.junit.runners.model.InitializationError if there is another problem
 */
public CucumberLoadRunner(Class clazz) throws InitializationError, IOException {
    super(clazz);

    System.setProperty(cukesProperty(CONTEXT_INFLATING_ENABLED), "false");
    System.setProperty(cukesProperty(ASSERTIONS_DISABLED), "true");
    System.setProperty(cukesProperty(LOADRUNNER_FILTER_BLOCKS_REQUESTS), "true");

    filter = SingletonObjectFactory.instance().getInstance(LoadRunnerFilter.class);

    ClassLoader classLoader = clazz.getClassLoader();
    Assertions.assertNoCucumberAnnotatedMethods(clazz);

    RuntimeOptionsFactory runtimeOptionsFactory = new RuntimeOptionsFactory(clazz);
    RuntimeOptions runtimeOptions = runtimeOptionsFactory.create();

    ResourceLoader resourceLoader = new MultiLoader(classLoader);
    runtime = createRuntime(resourceLoader, classLoader, runtimeOptions);

    final List<CucumberFeature> cucumberFeatures = runtimeOptions.cucumberFeatures(resourceLoader);
    jUnitReporter = new JUnitReporter(runtimeOptions.reporter(classLoader),
        runtimeOptions.formatter(classLoader), runtimeOptions.isStrict(), new JUnitOptions(runtimeOptions.getJunitOptions()));
    addChildren(cucumberFeatures);
}
 
Example #3
Source File: CucumberRunner.java    From bdt with Apache License 2.0 6 votes vote down vote up
/**
 * @return returns the cucumber scenarios as a two dimensional array of {@link PickleEventWrapper}
 * scenarios combined with their {@link CucumberFeatureWrapper} feature.
 */
public Object[][] provideScenarios() {
    try {
        List<Object[]> scenarios = new ArrayList<>();
        List<CucumberFeature> features = getFeatures();
        for (CucumberFeature feature : features) {
            for (PickleEvent pickle : feature.getPickles()) {
                if (filters.matchesFilters(pickle)) {
                    scenarios.add(new Object[]{new PickleEventWrapperImpl(pickle), new CucumberFeatureWrapperImpl(feature)});
                }
            }
        }
        return scenarios.toArray(new Object[][]{});
    } catch (CucumberException e) {
        return new Object[][]{new Object[]{new CucumberExceptionWrapper(e), null}};
    }
}
 
Example #4
Source File: ParameterizedCucumber.java    From senbot with MIT License 6 votes vote down vote up
public ThreadPoolFeatureRunnerScheduler(TestEnvironment environment, 
		CucumberFeature cucumberFeature,
		Runtime runtime, 
		JUnitReporter jUnitReporter,
		int featureFileTimout) throws InitializationError {
	super(cucumberFeature, runtime, jUnitReporter);
	this.environment = environment;
	this.cucumberFeature = cucumberFeature;
	this.jUnitReporter = jUnitReporter;
	this.featureFileTimout = featureFileTimout;
	
	Integer defaultNumThreads = SenBotContext.getSenBotContext().getCucumberManager().getParallelFeatureThreads();
	String threads = System.getProperty("junit.parallel.threads", defaultNumThreads.toString());
	int numThreads = Integer.parseInt(threads);
	executor = Executors.newFixedThreadPool(numThreads);
}
 
Example #5
Source File: AllureCucumber2JvmTest.java    From allure-java with Apache License 2.0 5 votes vote down vote up
private AllureResults runFeature(final String featureResource,
                                 final String... moreOptions) {
    final AllureResultsWriterStub writer = new AllureResultsWriterStub();
    final AllureLifecycle lifecycle = new AllureLifecycle(writer);
    final AllureCucumber2Jvm cucumber2Jvm = new AllureCucumber2Jvm(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.cucumber2jvm.samples",
            "--plugin", "null"
    ));
    opts.addAll(Arrays.asList(moreOptions));
    final RuntimeOptions options = new RuntimeOptions(opts);
    final Runtime runtime = new Runtime(resourceLoader, classFinder, classLoader, options);

    options.addPlugin(cucumber2Jvm);

    final String gherkin = readResource(featureResource);
    Parser<GherkinDocument> parser = new Parser<>(new AstBuilder());
    TokenMatcher matcher = new TokenMatcher();
    GherkinDocument gherkinDocument = parser.parse(gherkin, matcher);
    CucumberFeature feature = new CucumberFeature(gherkinDocument, featureResource, gherkin);

    feature.sendTestSourceRead(runtime.getEventBus());
    runtime.runFeature(feature);
    return writer;
}
 
Example #6
Source File: AllureCucumberJvmTest.java    From allure-java with Apache License 2.0 5 votes vote down vote up
private AllureResults runFeature(final String featureResource,
                                 final String... moreOptions) {
    final AllureResultsWriterStub writer = new AllureResultsWriterStub();
    final AllureLifecycle lifecycle = new AllureLifecycle(writer);
    final AllureCucumberJvm cucumberJvm = new AllureCucumberJvm(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.cucumberjvm.samples",
            "--plugin", "null",
            "src/test/resources/" + featureResource
    ));
    opts.addAll(Arrays.asList(moreOptions));
    final RuntimeOptions options = new RuntimeOptions(opts);
    final Runtime runtime = new Runtime(resourceLoader, classFinder, classLoader, options);

    options.addPlugin(cucumberJvm);

    final FeatureResultListener resultListener = new FeatureResultListener(
            options.reporter(classLoader),
            options.isStrict()
    );
    final List<CucumberFeature> features = options.cucumberFeatures(resourceLoader);
    features.forEach(cucumberFeature -> cucumberFeature.run(
            options.formatter(classLoader),
            resultListener,
            runtime)
    );
    return writer;
}
 
Example #7
Source File: AllureCucumber3JvmTest.java    From allure-java with Apache License 2.0 5 votes vote down vote up
private AllureResults runFeature(final String featureResource,
                                 final String... moreOptions) {
    final AllureResultsWriterStub writer = new AllureResultsWriterStub();
    final AllureLifecycle lifecycle = new AllureLifecycle(writer);
    final AllureCucumber3Jvm cucumber3Jvm = new AllureCucumber3Jvm(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.cucumber3jvm.samples",
            "--plugin", "null"
    ));
    opts.addAll(Arrays.asList(moreOptions));
    final RuntimeOptions options = new RuntimeOptions(opts);
    final Runtime runtime = new Runtime(resourceLoader, classFinder, classLoader, options);

    options.addPlugin(cucumber3Jvm);
    options.noSummaryPrinter();

    final String gherkin = readResource(featureResource);
    Parser<GherkinDocument> parser = new Parser<>(new AstBuilder());
    TokenMatcher matcher = new TokenMatcher();
    GherkinDocument gherkinDocument = parser.parse(gherkin, matcher);
    CucumberFeature feature = new CucumberFeature(gherkinDocument, featureResource, gherkin);

    feature.sendTestSourceRead(runtime.getEventBus());
    runtime.runFeature(feature);
    return writer;
}
 
Example #8
Source File: CucumberRunner.java    From bdt with Apache License 2.0 5 votes vote down vote up
List<CucumberFeature> getFeatures() {
    plugins.setSerialEventBusOnEventListenerPlugins(bus);

    List<CucumberFeature> features = featureSupplier.get();
    bus.send(new TestRunStarted(bus.getTime(), bus.getTimeMillis()));
    for (CucumberFeature feature : features) {
        feature.sendTestSourceRead(bus);
    }
    return features;
}
 
Example #9
Source File: CucumberLoadRunner.java    From cukes with Apache License 2.0 4 votes vote down vote up
private void addChildren(List<CucumberFeature> cucumberFeatures) throws InitializationError {
    for (CucumberFeature cucumberFeature : cucumberFeatures) {
        children.add(new LoadRunnerFeature(cucumberFeature, runtime, jUnitReporter, filter));
    }
}
 
Example #10
Source File: LoadRunnerFeature.java    From cukes with Apache License 2.0 4 votes vote down vote up
public LoadRunnerFeature(CucumberFeature cucumberFeature, Runtime runtime, JUnitReporter jUnitReporter,
                         LoadRunnerFilter filter) throws InitializationError {
    super(cucumberFeature, runtime, jUnitReporter);
    this.filter = filter;
    this.cucumberFeature = cucumberFeature;
}
 
Example #11
Source File: CucumberFeatureWrapperImpl.java    From bdt with Apache License 2.0 4 votes vote down vote up
CucumberFeatureWrapperImpl(CucumberFeature cucumberFeature) {
    this.cucumberFeature = cucumberFeature;
}
 
Example #12
Source File: ParameterizedCucumber.java    From senbot with MIT License 4 votes vote down vote up
/**
	 * Constructor looping though the {@link Parameterized} {@link Runner}'s and
	 * adding the {@link CucumberFeature}'s found as children to each one
	 * ensuring the {@link TestEnvironment} is available for each {@link Runner}
	 * .
	 * 
	 * @param klass
	 * @throws Throwable
	 */
	public ParameterizedCucumber(Class<?> klass) throws Throwable {
    	
    	super(klass);
        
        log.debug("Initializing the ParameterizedCucumber runner");

        final ClassLoader classLoader = klass.getClassLoader();
        Assertions.assertNoCucumberAnnotatedMethods(klass);

//        Class<? extends Annotation>[] annotationClasses = new Class[]{CucumberOptions.class, Options.class};
//        RuntimeOptionsFactory runtimeOptionsFactory = new RuntimeOptionsFactory(klass, annotationClasses);
        RuntimeOptionsFactory runtimeOptionsFactory = new RuntimeOptionsFactory(klass);
        final RuntimeOptions runtimeOptions = runtimeOptionsFactory.create();

        ResourceLoader resourceLoader = new MultiLoader(classLoader);
//        ClassFinder classFinder = new ResourceLoaderClassFinder(resourceLoader, classLoader);
//        runtime = new Runtime(resourceLoader, classFinder, classLoader, runtimeOptions);
        runtime = new Runtime(resourceLoader, classLoader, runtimeOptions);
        
        final ThreadAwareFormatter threadAwareWrappedFormatter = new ThreadAwareFormatter(runtimeOptions, classLoader);
        
        
        Reporter threadAwareReporter = new ThreadAwareReporter(threadAwareWrappedFormatter, classLoader, runtimeOptions);
        
		
		runtimeOptions.formatters.clear();
		runtimeOptions.formatters.add(threadAwareWrappedFormatter);
		
        jUnitReporter = new JUnitReporter(threadAwareReporter, threadAwareWrappedFormatter, runtimeOptions.strict);
        //overwrite the reporter so we can alter the path to write to
        
        List<CucumberFeature> cucumberFeatures = runtimeOptions.cucumberFeatures(resourceLoader);
        List<Runner> parameterizedChildren = super.getChildren();
        final SeleniumManager seleniumManager = SenBotContext.getSenBotContext().getSeleniumManager();
        final CucumberManager cucumberManager = SenBotContext.getSenBotContext().getCucumberManager();

        for (int i = 0; i < parameterizedChildren.size(); i++) {
        	BlockJUnit4ClassRunner paramRunner = (BlockJUnit4ClassRunner) parameterizedChildren.get(i);
        	final TestEnvironment environment = seleniumManager.getSeleniumTestEnvironments().get(i);
        
        	log.debug("Load runners for test envrironment: " + environment.toString());
        	
            for (final CucumberFeature cucumberFeature : cucumberFeatures) {
            	Feature originalFeature = cucumberFeature.getGherkinFeature();
            	
            	log.debug("Load runner for test cucumberFeature: " + originalFeature.getDescription() + " on evironment " + environment.toString());
                
            	ThreadPoolFeatureRunnerScheduler environmentFeatureRunner = new ThreadPoolFeatureRunnerScheduler(environment, 
            			cucumberFeature, 
            			runtime, 
            			jUnitReporter,
            			cucumberManager.getFeatureFileTimeout());
            	
            	setScheduler(environmentFeatureRunner);
				children.add(environmentFeatureRunner);
            }           
        }

    }