cucumber.runtime.RuntimeOptions Java Examples

The following examples show how to use cucumber.runtime.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: 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 #2
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 #3
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 #4
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 #5
Source File: QuantumReportiumListener.java    From Quantum with MIT License 5 votes vote down vote up
@Override
protected String[] getTags(ITestResult testResult) {

	RuntimeOptions cucumberOptions = getCucumberOptions(testResult);
	List<String> optionsList = cucumberOptions.getFilters().stream().map(object -> Objects.toString(object, null))
			.collect(Collectors.toList());
	optionsList.addAll(cucumberOptions.getFeaturePaths());
	optionsList.addAll(cucumberOptions.getGlue());

	return ArrayUtils.addAll(super.getTags(testResult), optionsList.toArray(new String[optionsList.size()]));
}
 
Example #6
Source File: QuantumReportiumListener.java    From Quantum with MIT License 5 votes vote down vote up
private RuntimeOptions getCucumberOptions(ITestResult testResult) {
	try {
		return new RuntimeOptionsFactory(Class.forName(testResult.getTestClass().getName())).create();
	} catch (ClassNotFoundException e) {
		e.printStackTrace();
	}
	return null;
}
 
Example #7
Source File: CucumberReportAdapter.java    From openCypher with Apache License 2.0 5 votes vote down vote up
private void initCucumberPlugins() {
    PluginFactory pluginFactory = new PluginFactory();
    RuntimeOptions options = new RuntimeOptions("");
    options.getPluginFormatterNames()
        .stream()
        .map(pluginFactory::create)
        .filter(EventListener.class::isInstance)
        .map(EventListener.class::cast)
        .forEach(json -> json.setEventPublisher(bus));
}
 
Example #8
Source File: ReplacementAspect.java    From bdt with Apache License 2.0 5 votes vote down vote up
@After(value = "runnerInit(bus, backends, runtimeOptions)")
public void runnerInitGlue(JoinPoint jp, EventBus bus, Collection<? extends Backend> backends, RuntimeOptions runtimeOptions) throws Throwable {
    glue = new Glue(bus);
    for (Backend backend : backends) {
        backend.loadGlue(glue, runtimeOptions.getGlue());
    }
}
 
Example #9
Source File: ParameterizedCucumber.java    From senbot with MIT License 5 votes vote down vote up
private ThreadAwareReporter(ThreadAwareFormatter threadAwareWrappedFormatter, 
		final ClassLoader classLoader,
		final RuntimeOptions runtimeOptions) {
	this.threadAwareWrappedFormatter = threadAwareWrappedFormatter;
	this.classLoader = classLoader;
	this.runtimeOptions = runtimeOptions;
	threadLocal = new ThreadLocal<Reporter>() {
      		@Override
      		protected Reporter initialValue() {
      			return runtimeOptions.reporter(classLoader);
      		}
      	};
}
 
Example #10
Source File: ParameterizedCucumber.java    From senbot with MIT License 5 votes vote down vote up
private ThreadAwareFormatter(final RuntimeOptions runtimeOptions, final ClassLoader classLoader) {
			this.runtimeOptions = runtimeOptions;
			this.classLoader = classLoader;
			wrapped = new ThreadLocal<Formatter>() {
        		@Override
        		protected Formatter initialValue() {
        			Formatter created = FORMATTER_FACTORY.create("json:target/test-results/result_" + Thread.currentThread().getId() + ".json");
        			known.add(created);
					return created;
//        			Formatter formatter = runtimeOptions.formatter(classLoader);
//        			return formatter;
        		}
        	};
		}
 
Example #11
Source File: ReplacementAspect.java    From bdt with Apache License 2.0 4 votes vote down vote up
@Pointcut("execution (cucumber.runner.Runner.new(..)) && "
        + "args (bus, backends, runtimeOptions)")
protected void runnerInit(EventBus bus, Collection<? extends Backend> backends, RuntimeOptions runtimeOptions) {
}
 
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);
            }           
        }

    }
 
Example #13
Source File: CucumberLoadRunner.java    From cukes with Apache License 2.0 2 votes vote down vote up
/**
 * Create the Runtime. Can be overridden to customize the runtime or backend.
 *
 * @param resourceLoader used to load resources
 * @param classLoader    used to load classes
 * @param runtimeOptions configuration
 * @return a new runtime
 */
protected Runtime createRuntime(ResourceLoader resourceLoader, ClassLoader classLoader, RuntimeOptions
    runtimeOptions) {
    ClassFinder classFinder = new ResourceLoaderClassFinder(resourceLoader, classLoader);
    return new Runtime(resourceLoader, classFinder, classLoader, runtimeOptions);
}