This repository has been archived by the owner on Nov 23, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 40
Adding Cucumber to JUnit project
mkrzyzanowski edited this page Oct 25, 2016
·
11 revisions
If you want to add Cucumber to JUnit project, you need to do few things:
<dependency>
<groupId>com.cognifide.qa.bb</groupId>
<artifactId>bb-cumber</artifactId>
<version>${bb.version}</version>
</dependency>
- create CucumberInjectorSource.java
import com.google.inject.Guice;
import com.google.inject.Injector;
import cucumber.api.guice.CucumberModules;
import cucumber.runtime.java.guice.InjectorSource;
public class CucumberInjectorSource implements InjectorSource {
@Override
public Injector getInjector() {
return Guice.createInjector(CucumberModules.SCENARIO, new GuiceModule());
}
}
- create
cucumber-guice.properties
undersrc/test/resources
with fully qualified name of yourCucumberInjectorSource
guice.injector-source=<your-package>.CucumberInjectorSource
-
create package 'hooks' under src/main/java/com.cognifide
-
create TakeScreenshot.java in hooks package
import com.google.inject.Inject;
import cucumber.api.Scenario;
import cucumber.api.java.After;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
/**
* A helper class that can create a screenshot file.
*/
public class TakeScreenshot {
/**
* Inject a WebDriver instance, because it will create the screenshot.
*/
@Inject
private WebDriver webDriver;
/**
* Creates the screenshot, embeds it in the scenario and closes webDriver.
*/
@After
public void takeScreenshotAndClose(Scenario scenario) {
if (scenario.isFailed() && webDriver instanceof TakesScreenshot) {
byte[] screenshot = ((TakesScreenshot) webDriver).getScreenshotAs(OutputType.BYTES);
scenario.embed(screenshot, "image/png");
}
webDriver.quit();
}
}
- create also WindowMaximize.java in hooks package
import com.google.inject.Inject;
import cucumber.api.java.Before;
import org.openqa.selenium.WebDriver;
/**
* A helper class that will maximize window
*/
public class WindowMaximize {
@Inject
private WebDriver webDriver;
@Before
public void maximize() {
webDriver.manage().window().maximize();
}
}
That's all! Now you can develop your test cases in JUnit and in Cucumber! Go to Getting Started to look how to do it.
- Configuring Bobcat
- Selenium enhancements
- Cucumber enhancements
- Traffic analyzer
- Email support
- Reporting
- Cloud integration
- Mobile integration
- Executing tests on different environments
- Working with multiple threads
- Tips and tricks
- Authoring tutorial - Classic
- AEM Classic Authoring Advanced usage
- Siteadmin
- Sidekick
- Aem Component
- Working with author pages
- Working with Publish pages
- Advanced component interactions
- Working with Context Menu
- Using Aem Content Tree
- Aem Content Finder
- Storing component configurations
- Working with packages
- Jcr Support
- Authoring tutorial - Touch UI
- Adding and editing a component
- Sites management tutorial