io.cucumber.java.Scenario Java Examples

The following examples show how to use io.cucumber.java.Scenario. 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: InjectEnvVarsHook.java    From yaks with Apache License 2.0 6 votes vote down vote up
@Before
public void injectEnvVars(Scenario scenario) {
    runner.run(new AbstractTestAction() {
        @Override
        public void doExecute(TestContext context) {
            if (scenario != null) {
                context.setVariable("SCENARIO_ID", scenario.getId());
                context.setVariable("SCENARIO_NAME", scenario.getName());
            }

            Optional<String> namespaceEnv = getEnvSetting(YAKS_NAMESPACE);
            Optional<String> domainEnv = getEnvSetting(CLUSTER_WILDCARD_DOMAIN);

            if (namespaceEnv.isPresent()) {
                context.setVariable(YAKS_NAMESPACE, namespaceEnv.get());

                if (!domainEnv.isPresent()) {
                    context.setVariable(CLUSTER_WILDCARD_DOMAIN, namespaceEnv.get() + DEFAULT_DOMAIN_SUFFIX);
                }
            }

            domainEnv.ifPresent(var -> context.setVariable(CLUSTER_WILDCARD_DOMAIN, var));
        }
    });
}
 
Example #2
Source File: HttpClientSteps.java    From yaks with Apache License 2.0 6 votes vote down vote up
@Before
public void before(Scenario scenario) {
    if (httpClient == null && citrus.getCitrusContext().getReferenceResolver().resolveAll(HttpClient.class).size() == 1L) {
        httpClient = citrus.getCitrusContext().getReferenceResolver().resolve(HttpClient.class);
    } else {
        httpClient = new HttpClientBuilder().build();
    }

    timeout = httpClient.getEndpointConfiguration().getTimeout();

    requestHeaders = new HashMap<>();
    responseHeaders = new HashMap<>();
    requestParams = new HashMap<>();
    requestMessageType = CitrusSettings.DEFAULT_MESSAGE_TYPE;
    responseMessageType = CitrusSettings.DEFAULT_MESSAGE_TYPE;
    requestBody = null;
    responseBody = null;
    bodyValidationExpressions = new HashMap<>();
    outboundDictionary = null;
    inboundDictionary = null;
}
 
Example #3
Source File: HttpServerSteps.java    From yaks with Apache License 2.0 6 votes vote down vote up
@Before
public void before(Scenario scenario) {
    if (httpServer == null && citrus.getCitrusContext().getReferenceResolver().resolveAll(HttpServer.class).size() == 1L) {
        httpServer = citrus.getCitrusContext().getReferenceResolver().resolve(HttpServer.class);
    } else {
        httpServer = new HttpServerBuilder().build();
    }

    requestHeaders = new HashMap<>();
    responseHeaders = new HashMap<>();
    requestParams = new HashMap<>();
    requestMessageType = CitrusSettings.DEFAULT_MESSAGE_TYPE;
    responseMessageType = CitrusSettings.DEFAULT_MESSAGE_TYPE;
    requestBody = null;
    responseBody = null;
    bodyValidationExpressions = new HashMap<>();
}
 
Example #4
Source File: OpenCVHooks.java    From justtestlah with Apache License 2.0 5 votes vote down vote up
@Override
public void before(Scenario scenario) {
  if (configuration.isOpenCvEnabled()) {
    try {
      // load OpenCV library
      OpenCV.loadShared();
      OpenCV.loadLocally();
      System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
    } catch (ExceptionInInitializerError exception) {
      LOG.error("Error loading OpenCV libraries", exception);
    }
  }
}
 
Example #5
Source File: Stepdefs.java    From testcontainers-java with MIT License 5 votes vote down vote up
@After
public void afterScenario(Scenario scenario) {
    container.afterTest(new TestDescription() {
        @Override
        public String getTestId() {
            return scenario.getId();
        }

        @Override
        public String getFilesystemFriendlyName() {
            return scenario.getName();
        }
    }, Optional.of(scenario).filter(Scenario::isFailed).map(__ -> new RuntimeException()));
}
 
Example #6
Source File: WebDriverUtils.java    From neodymium-library with MIT License 5 votes vote down vote up
static String getFirstMatchingBrowserTag(Scenario scenario)
{
    Collection<String> scenarioTags = scenario.getSourceTagNames();
    List<String> browserTags = browserStatement.get().getBrowserTags();

    String firstBrowserTagFound = "";
    for (String tag : scenarioTags)
    {
        String compareString = tag.substring(1);// substring to cut off leading '@'
        if (browserTags.contains(compareString))
        {
            if (StringUtils.isEmpty(firstBrowserTagFound))
            {
                firstBrowserTagFound = compareString;
            }
            else
            {
                throw new RuntimeException("Found more than one matching browser tag");
            }
        }
    }

    if (StringUtils.isEmpty(firstBrowserTagFound))
    {
        throw new RuntimeException("Could not find any tag that matches a browser tag");
    }
    else
    {
        return firstBrowserTagFound;
    }
}
 
Example #7
Source File: GalenHooks.java    From justtestlah with Apache License 2.0 5 votes vote down vote up
/**
 * Generate Galen reports.
 *
 * @param scenario Cucumber scenario
 */
@Override
public void after(Scenario scenario) {
  if (configuration.isGalenEnabled()) {
    LOG.info("Generating {} Galen reports", galenTests.get().size());
    try {
      new HtmlReportBuilder().build(galenTests.get(), getGalenReportDirectory());
    } catch (IOException exception) {
      throw new JustTestLahException("Error generating Galen reports.", exception);
    }
  }
}
 
Example #8
Source File: ApplitoolsHooks.java    From justtestlah with Apache License 2.0 5 votes vote down vote up
/**
 * Close the web driver and Applitools.
 *
 * @param scenario Cucumber scenario
 */
@Override
public void after(Scenario scenario) {
  if (configuration.isEyesEnabled() && eyes.getIsOpen()) {
    LOG.info("Closing Eyes");
    eyes.close();
  }
}
 
Example #9
Source File: ApplitoolsHooks.java    From justtestlah with Apache License 2.0 5 votes vote down vote up
/**
 * Initialise Applitools.
 *
 * @param scenario Cucumber scenario
 */
@Override
public void before(Scenario scenario) {
  if (configuration.isEyesEnabled()) {
    LOG.info("Initializing Eyes");
    eyes.open(
        WebDriverRunner.getAndCheckWebDriver(),
        configuration.getApplicationName(),
        configuration.getPlatform().name());
  }
}
 
Example #10
Source File: TestFailureHook.java    From yaks with Apache License 2.0 5 votes vote down vote up
@After(order = Integer.MAX_VALUE)
public void checkTestFailure(Scenario scenario) {
    if (scenario.isFailed()) {
        runner.run(new AbstractTestAction() {
            @Override
            public void doExecute(TestContext context) {
                context.getExceptions().add(new CitrusRuntimeException(
                        String.format("Scenario %s:%s status %s", scenario.getId(), scenario.getLine(), scenario.getStatus().toString())));
            }
        });
    }
}
 
Example #11
Source File: Hooks.java    From justtestlah with Apache License 2.0 5 votes vote down vote up
@After
public void notifyAfter(Scenario scenario) {
  for (CucumberHook hook : hooksRegister.getRegisteredHooks()) {
    hook.after(scenario);
  }
  hooksRegister.clear();
}
 
Example #12
Source File: Hooks.java    From justtestlah with Apache License 2.0 5 votes vote down vote up
@Before
public void notifyBefore(Scenario scenario) {
  initHooks();
  for (CucumberHook hook : hooksRegister.getRegisteredHooks()) {
    hook.before(scenario);
  }
}
 
Example #13
Source File: OpenApiSteps.java    From yaks with Apache License 2.0 5 votes vote down vote up
@Before
public void before(Scenario scenario) {
    clientSteps = new HttpClientSteps();
    CitrusAnnotations.injectAll(clientSteps, citrus);
    CitrusAnnotations.injectTestRunner(clientSteps, runner);
    clientSteps.before(scenario);

    operation = null;

    outboundDictionary = new JsonPathMappingDataDictionary();
    inboundDictionary = new JsonPathMappingDataDictionary();
}
 
Example #14
Source File: RpnCalculatorSteps.java    From pitest-cucumber-plugin with Apache License 2.0 4 votes vote down vote up
@After
public void after(Scenario scenario) {
    // scenario.write("HELLLLOO");
}
 
Example #15
Source File: AbstractCucumberHook.java    From justtestlah with Apache License 2.0 4 votes vote down vote up
@Override
public void before(Scenario scenario) {
  // do nothing
}
 
Example #16
Source File: AbstractCucumberHook.java    From justtestlah with Apache License 2.0 4 votes vote down vote up
@Override
public void after(Scenario scenario) {
  // do nothing
}
 
Example #17
Source File: WebDriverHooks.java    From justtestlah with Apache License 2.0 4 votes vote down vote up
/**
 * Close the web driver.
 *
 * @param scenario Cucumber scenario
 */
@Override
public void after(Scenario scenario) {
  LOG.info("Closing web driver");
  WebDriverRunner.closeWebDriver();
}
 
Example #18
Source File: WebDriverHooks.java    From justtestlah with Apache License 2.0 4 votes vote down vote up
/**
 * Initialise the web driver.
 *
 * @param scenario Cucumber scenario
 */
@Override
public void before(Scenario scenario) {
  LOG.info("Initializing web driver");
  configuration.initWebDriver();
}
 
Example #19
Source File: AttachmentSteps.java    From allure-java with Apache License 2.0 4 votes vote down vote up
@Before("@attachments")
public void setup(Scenario scenario)
{
    this.scenario = scenario;
}
 
Example #20
Source File: RpnCalculatorSteps.java    From pitest-cucumber-plugin with Apache License 2.0 4 votes vote down vote up
@Before("not @foo")
public void before(Scenario scenario) {
    scenario.write("Runs before scenarios *not* tagged with @foo");
}
 
Example #21
Source File: JdbcSteps.java    From yaks with Apache License 2.0 4 votes vote down vote up
@Before
public void before(Scenario scenario) {
    if (dataSource == null && citrus.getCitrusContext().getReferenceResolver().resolveAll(DataSource.class).size() == 1L) {
        dataSource = citrus.getCitrusContext().getReferenceResolver().resolve(DataSource.class);
    }
}
 
Example #22
Source File: CucumberSupport.java    From neodymium-library with MIT License 4 votes vote down vote up
@Before("@SetUpWithBrowserTag")
public static void setUp(Scenario scenario)
{
    WebDriverUtils.setUpWithBrowserTag(scenario);
}
 
Example #23
Source File: CucumberSupport.java    From neodymium-library with MIT License 4 votes vote down vote up
@After(order = 100)
public void tearDown(Scenario scenario)
{
    WebDriverUtils.tearDown(scenario);
}
 
Example #24
Source File: CucumberContextSteps.java    From neodymium-library with MIT License 4 votes vote down vote up
@After(order = 100)
public void teardown(Scenario scenario)
{
    WebDriverUtils.tearDown(scenario);
}
 
Example #25
Source File: WebDriverUtils.java    From neodymium-library with MIT License 2 votes vote down vote up
/**
 * @param scenario
 *            Scenario is a Cucumber API class that can be gathered in hooks via dependency injection
 * 
 *            <pre>
 *            public void setup(Scenario scenario)
 *            {
 *                WebDriverUtils.setUpWithBrowserTag(scenario);
 *            }
 *            </pre>
 **/
public static void setUpWithBrowserTag(Scenario scenario)
{
    String browserProfileName = getFirstMatchingBrowserTag(scenario);
    browserStatement.get().setUpTest(browserProfileName);
}
 
Example #26
Source File: WebDriverUtils.java    From neodymium-library with MIT License 2 votes vote down vote up
/**
 * @param scenario
 *            Scenario is a Cucumber API class that can be gathered in hooks via dependency injection
 * 
 *            <pre>
 *            &#64;cucumber.api.java.After(order = 100)
 *            public void tearDown(Scenario scenario)
 *            {
 *                WebDriverUtils.tearDown(scenario);
 *            }
 *            </pre>
 **/
public static void tearDown(Scenario scenario)
{
    tearDown(scenario.isFailed());
}
 
Example #27
Source File: CucumberHook.java    From justtestlah with Apache License 2.0 2 votes vote down vote up
/**
 * Add steps that are to be executed before the start of a scenario.
 *
 * @param scenario Cucumber scenario
 */
public void before(Scenario scenario);
 
Example #28
Source File: CucumberHook.java    From justtestlah with Apache License 2.0 2 votes vote down vote up
/**
 * Add steps that are to be executed after the end of a scenario.
 *
 * @param scenario Cucumber scenario
 */
public void after(Scenario scenario);