
com.github.becausetesting.cucumber.BecauseCucumber Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of commons Show documentation
Show all versions of commons Show documentation
A common libraries used for testing framework.
package com.github.becausetesting.cucumber;
import cucumber.api.CucumberOptions;
import cucumber.runtime.ClassFinder;
import cucumber.runtime.CucumberException;
import cucumber.runtime.Runtime;
import cucumber.runtime.RuntimeOptions;
import cucumber.runtime.RuntimeOptionsFactory;
import cucumber.runtime.formatter.PluginFactory;
import cucumber.runtime.io.MultiLoader;
import cucumber.runtime.io.ResourceLoader;
import cucumber.runtime.io.ResourceLoaderClassFinder;
import cucumber.runtime.model.CucumberFeature;
import gherkin.formatter.Formatter;
import gherkin.formatter.Reporter;
import org.apache.log4j.Logger;
import org.junit.runner.Description;
import org.junit.runner.notification.RunNotifier;
import org.junit.runners.ParentRunner;
import org.junit.runners.model.InitializationError;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.RemoteWebDriver;
import com.github.becausetesting.reflections.RefelectionUtils;
import com.google.common.collect.Lists;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
*
* Classes annotated with {@code @RunWith(Cucumber.class)} will run a Cucumber
* Feature. The class should implement the BecauseCucumberHook interface, which
* will let you to invoke the cucumber behaviours in runtime
*
*
* Cucumber will look for a {@code .feature} file on the classpath, using the
* same resource path as the annotated class ({@code .class} substituted by
* {@code .feature}). also you can use the properties file to
*
* Additional hints can be given to Cucumber by annotating the class with
* {@link CucumberOptions}.
*
* @see CucumberOptions
*/
public class BecauseCucumber extends ParentRunner {
private static final Logger logger = Logger.getLogger(BecauseCucumber.class);
private final List children = new ArrayList();
private final Runtime runtime;
private BecauseCucumberReporter becauseCucumberReporter;
public Reporter reporter;
public Formatter formatter;
public boolean isStrict = false;
public static Object reportInstance = null;
public static String METHOD_BEFORERUN = "beforeRun";
public static String METHOD_AFTERRUN = "afterRun";
public static String METHOD_BEFORESCENARIO = "beforeEachScenario";
public static String METHOD_AFTERSCENARIO = "afterEachScenario";
public static String METHOD_BEFOREFEATURE = "beforeEachFeature";
public static String METHOD_CUCUMBERFEATUREPATHS = "setCucumberFeatureFilePaths";
public static String METHOD_SETREPORTFORMATS = "setCucumberReportFormatters";
public static String METHOD_SETSTEPDEFINITIONS = "setCucumberStepDefinitionPaths";
public static String METHOD_SETCUCUMBERTAGS = "setCucumberTags";
public static String METHOD_SETSELENIUMDRIVER = "setSeleniumDriver";
public static WebDriver driver;
/**
* 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 BecauseCucumber(Class clazz) throws InitializationError, IOException {
super(clazz);
ClassLoader classLoader = clazz.getClassLoader();
ResourceLoader resourceLoader = new MultiLoader(classLoader);
Assertions.assertNoCucumberAnnotatedMethods(clazz);
RuntimeOptionsFactory runtimeOptionsFactory = new RuntimeOptionsFactory(clazz);
RuntimeOptions runtimeOptions = runtimeOptionsFactory.create();
reporter = runtimeOptions.reporter(classLoader);
formatter = runtimeOptions.formatter(classLoader);
isStrict = runtimeOptions.isStrict();
// report formats
String[] formatArrays = new String[] { "html:target/cucumber/cucumber-html-report",
"json:target/cucumber/cucumber-json-report/cucumber.json",
"junit:target/cucumber/cucumber-junit-report/cucumber.xml",
"testng:target/cucumber/cucumber-testng-report/cucumber.xml",
"rerun:target/cucumber/cucumber-failed-report/failed,rerun.txt" };
List reportformatList = Arrays.asList(formatArrays);
// get the step definition paths
String[] stepArrays = new String[] { "classpath:", "com.github.becausetesting.cucumber.selenium" };
List stepdefinitionList = Arrays.asList(stepArrays);
// the cucumber feature files
List cucumberFeatures;
List featurePaths = Lists.newArrayList();
List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy