cucumber.runtime.io.MultiLoader Java Examples
The following examples show how to use
cucumber.runtime.io.MultiLoader.
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 |
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 |
/** * 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: AllureCucumber2JvmTest.java From allure-java with Apache License 2.0 | 5 votes |
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 #4
Source File: AllureCucumberJvmTest.java From allure-java with Apache License 2.0 | 5 votes |
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 #5
Source File: AllureCucumber3JvmTest.java From allure-java with Apache License 2.0 | 5 votes |
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 #6
Source File: CucumberRunner.java From bdt with Apache License 2.0 | 5 votes |
/** * Bootstrap the cucumber runtime * * @param clazz Which has the cucumber.api.CucumberOptions and org.testng.annotations.Test annotations */ public CucumberRunner(Class clazz) throws IOException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException, URISyntaxException { ClassLoader classLoader = clazz.getClassLoader(); ResourceLoader resourceLoader = new MultiLoader(classLoader); RuntimeOptionsFactory runtimeOptionsFactory = new RuntimeOptionsFactory(clazz); runtimeOptions = runtimeOptionsFactory.create(); String testSuffix = System.getProperty("TESTSUFFIX"); String targetExecutionsPath = "target/executions/"; if (testSuffix != null) { targetExecutionsPath = targetExecutionsPath + testSuffix + "/"; } new File(targetExecutionsPath).mkdirs(); CucumberReporter reporterTestNG = new CucumberReporter(targetExecutionsPath, clazz.getCanonicalName()); addGlue(); ClassFinder classFinder = new ResourceLoaderClassFinder(resourceLoader, classLoader); BackendModuleBackendSupplier backendSupplier = new BackendModuleBackendSupplier(resourceLoader, classFinder, runtimeOptions); bus = new TimeServiceEventBus(TimeService.SYSTEM); plugins = new Plugins(classLoader, new PluginFactory(), runtimeOptions); plugins.addPlugin(reporterTestNG); Set<Class<? extends ConcurrentEventListener>> implementers = new Reflections("com.stratio.qa.utils").getSubTypesOf(ConcurrentEventListener.class); for (Class<? extends ConcurrentEventListener> implementerClazz : implementers) { Constructor<?> ctor = implementerClazz.getConstructor(); ctor.setAccessible(true); Object newPlugin = ctor.newInstance(); plugins.addPlugin((ConcurrentEventListener) newPlugin); } FeatureLoader featureLoader = new FeatureLoader(resourceLoader); filters = new Filters(runtimeOptions); this.runnerSupplier = new ThreadLocalRunnerSupplier(runtimeOptions, bus, backendSupplier); featureSupplier = new FeaturePathFeatureSupplier(featureLoader, runtimeOptions); }
Example #7
Source File: ParameterizedCucumber.java From senbot with MIT License | 4 votes |
/** * 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); } } }