🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

io.cloudbeat.cucumber:cb-plugin-cucumber

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

io.cloudbeat.cucumber:cb-plugin-cucumber

CloudBeat plugin for Cucumber-Java

0.10.0
Source
Maven
Version published
Maintainers
1
Source

CloudBeat plugin for Cucumber-Java

Intro

This plugin allows executing Java based Cucumber tests using the CloudBeat platform.

Building

git clone https://github.com/oxygenhq/cb-framework-plugin-cucumber-java
cd cb-framework-plugin-cucumber-java
mvn install

Usage

Add the plugin to your project. If you are using a maven based project, you can directly add this library as a dependency:

<dependency>  
  <groupId>io.cloudbeat.cucumber</groupId>  
  <artifactId>cb-plugin-cucumber</artifactId>  
  <version>0.8.0</version>  
</dependency>

Add io.cloudbeat.cucumber.Plugin to Cucumber options and make sure the class annotated with @RunWith(Cucumber.class) extends CucumberRunner

@RunWith(Cucumber.class)
@CucumberOptions(plugin = {"pretty", "io.cloudbeat.cucumber.Plugin:"})
public class RunCucumberTest extends CucumberRunner {
}

Working with Selenium

Obtaining browser name

Browser name is set by the plugin as a system property, and can be obtained using System.getProperty:

String browserName = System.getProperty('browserName');

Automatic screenshots on failures

When using Selenium it might be beneficiary to be able to take browser screenshots in case of failures. This can be achieved in a three different ways. Please note that all 3 options are mutually exclusive.

  • By embedding screenshots manually from @After() method within the glue classes. Screenshot should be embedded as a Base64 string using the image/png mime type. See the examples below for more details.
  • By providing WebDriver instance to the plugin.
  • By providing WebDriver getter method to the plugin.
Embedding screenshots manually
public class SeleniumDefs {
    private final WebDriver driver = new ChromeDriver();

    @Given("^I am on the Google search page$")
    public void I_visit_google() {
        ...
    }

    @When("^I search for \"(.*)\"$")
    public void search_for(String query) {
        ...
    }

    @Then("^the page title should start with \"(.*)\"$")
    public void checkTitle(String titleStartsWith) {
        ...
    }

    @After()
    public void tearDown(Scenario scenario) {
        if (scenario.isFailed()) {
            try {
                final byte[] screenshot = ((TakesScreenshot)driver).getScreenshotAs(OutputType.BYTES);
                scenario.embed(screenshot, "image/png");
            } catch (Exception e){
                System.err.println("Couldn't take screenshot" + e);
            }
        }
        driver.quit();
    }
}
Providing WebDriver instance
@RunWith(Cucumber.class)
@CucumberOptions(plugin = {"pretty", "io.cloudbeat.cucumber.Plugin:"})
public class RunCucumberTest extends CucumberRunner {
    @BeforeClass
    public static void setUp() {
        WebDriver driver = ... // WebDriver initialization
        setWebDriver(driver);
    }
}
Providing WebDriver getter method
@RunWith(Cucumber.class)
@CucumberOptions(plugin = {"pretty", "io.cloudbeat.cucumber.Plugin:"})
public class RunCucumberTest extends CucumberRunner {
    @BeforeClass
    public static void setUp() {
       WebDriverProvider provider = new WebDriverProvider();
       // getter should have WebDriver as its return type and shouldn't expect any arguments
       setWebDriverGetter(provider::getWebDriver);
    }
}

public class WebDriverProvider {
    public WebDriver getWebDriver() {
       return driver;
    }
}

FAQs

Package last updated on 27 Oct 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts