cucumber.api.Scenario Java Examples

The following examples show how to use cucumber.api.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 Project: SeleniumCucumber   Author: rahulrathore44   File: InitializeWebDrive.java    License: GNU General Public License v3.0 6 votes vote down vote up
public void tearDownDriver(Scenario scenario) throws Exception {
	
	try {
		if (ObjectRepo.driver != null) {
			
			if(scenario.isFailed())
				scenario.write(new GenericHelper(ObjectRepo.driver).takeScreenShot(scenario.getName()));
			
			ObjectRepo.driver.quit();
			ObjectRepo.reader = null;
			ObjectRepo.driver = null;
			oLog.info("Shutting Down the driver");
		}
	} catch (Exception e) {
		oLog.error(e);
		throw e;
	}
}
 
Example #2
Source Project: qa-automation-samples   Author: concretesolutions   File: AllureHelper.java    License: MIT License 5 votes vote down vote up
private static void screenShot(String status, Scenario scenario) {
    byte[] screenshootBytes = ((TakesScreenshot) Page.getDriver()).getScreenshotAs(OutputType.BYTES);
    InputStream screenshootStream = new ByteArrayInputStream(screenshootBytes);
    Allure.addAttachment(scenario.getName() +" - "+ status, screenshootStream);
}
 
Example #3
Source Project: qa-automation-samples   Author: concretesolutions   File: AllureHelper.java    License: MIT License 5 votes vote down vote up
public static void saveScreenshootOfScenario(Scenario scenario) {
    if (!scenario.isFailed()) {
        screenShot("PASSED", scenario);

    } else {
        screenShot("FAILED", scenario);
    }
}
 
Example #4
Source Project: qa-automation-samples   Author: concretesolutions   File: Print.java    License: MIT License 5 votes vote down vote up
public static void takeScreenShot(Scenario scenario) {

        File scrFile = ((TakesScreenshot) DriverFactoryManager.getDriver()).getScreenshotAs(OutputType.FILE);

        try {
            FileUtils.copyFile(scrFile, (new File("./evidence", scenario.getName() + " - " + scenario.getStatus().toUpperCase() + ".png")));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
 
Example #5
Source Project: akita   Author: alfa-laboratory   File: InitialSetupHooks.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Если сценарий завершился со статусом "fail" будет создан скриншот и сохранен в директорию
 * {@code <project>/build/reports/tests}
 *
 * @param scenario текущий сценарий
 */
@After(order = 20)
public void takeScreenshot(Scenario scenario) {
    if (scenario.isFailed() && hasWebDriverStarted()) {
        AkitaScenario.sleep(1);
        final byte[] screenshot = ((TakesScreenshot) getWebDriver()).getScreenshotAs(OutputType.BYTES);
        scenario.embed(screenshot, "image/png");
    }
}
 
Example #6
Source Project: bdt   Author: Stratio   File: CommonG.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Add png file to cucumber report (it's embed on scenario)
 *
 * @param pngFile Screenshot file
 */
private void addPngFileToReport(File pngFile, Scenario scenario) {
    if (scenario != null) {
        try {
            BufferedImage bImage = ImageIO.read(pngFile);
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            ImageIO.write(bImage, "png", bos);
            scenario.embed(bos.toByteArray(), "image/png");
        } catch (IOException e) {
            logger.error("Error adding screenshot in cucumber report", e);
        }
    }
}
 
Example #7
Source Project: akita   Author: alfa-laboratory   File: AkitaPageTest.java    License: Apache License 2.0 5 votes vote down vote up
@BeforeAll
static void setup() {
    wpis = new WebPageInteractionSteps();
    akitaPageMock = new AkitaPageMock();
    AkitaScenario akitaScenario = AkitaScenario.getInstance();
    Scenario scenario = new StubScenario();
    akitaScenario.setEnvironment(new AkitaEnvironment(scenario));
    String inputFilePath = "src/test/resources/AkitaPageMock.html";
    String url = new File(inputFilePath).getAbsolutePath();
    akitaScenario.setVar("Page", "file://" + url);
    wpis.goToSelectedPageByLink("AkitaPageMock", akitaScenario.getVar("Page").toString());
    page = akitaScenario.getEnvironment().getPage("AkitaPageMock");
}
 
Example #8
Source Project: akita   Author: alfa-laboratory   File: AkitaScenarioTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
void getCurrentPagePositive() {
    AkitaScenario akitaScenario = AkitaScenario.getInstance();
    WebPageInteractionSteps wpis = new WebPageInteractionSteps();
    Scenario scenario = new StubScenario();
    akitaScenario.setEnvironment(new AkitaEnvironment(scenario));
    String inputFilePath = "src/test/resources/AkitaPageMock.html";
    String url = new File(inputFilePath).getAbsolutePath();
    akitaScenario.setVar("Page", "file://" + url);
    wpis.goToSelectedPageByLink("AkitaPageMock", akitaScenario.getVar("Page").toString());
    akitaScenario.setCurrentPage(akitaScenario.getPage("AkitaPageMock"));
    assertThat(akitaScenario.getCurrentPage(), is(notNullValue()));
    close();
}
 
Example #9
Source Project: akita   Author: alfa-laboratory   File: AkitaEnvironmentTest.java    License: Apache License 2.0 5 votes vote down vote up
@BeforeAll
static void prepare() {

    env = new AkitaEnvironment();
    AkitaScenario akitaScenario = AkitaScenario.getInstance();
    wpis = new WebPageInteractionSteps();
    Scenario scenario = new StubScenario();
    akitaScenario.setEnvironment(new AkitaEnvironment(scenario));
    String inputFilePath = "src/test/resources/AkitaPageMock.html";
    String url = new File(inputFilePath).getAbsolutePath();
    akitaScenario.setVar("Page", "file://" + url);
    wpis.goToSelectedPageByLink("AkitaPageMock", akitaScenario.getVar("Page").toString());
}
 
Example #10
Source Project: akita   Author: alfa-laboratory   File: PagesTest.java    License: Apache License 2.0 5 votes vote down vote up
@BeforeAll
static void init() {
    pages = new Pages();
    akitaPageMock = new AkitaPageMock();

    AkitaScenario akitaScenario = AkitaScenario.getInstance();
    WebPageInteractionSteps wpis = new WebPageInteractionSteps();
    Scenario scenario = new StubScenario();
    akitaScenario.setEnvironment(new AkitaEnvironment(scenario));
    String inputFilePath = "src/test/resources/AkitaPageMock.html";
    String url = new File(inputFilePath).getAbsolutePath();
    akitaScenario.setVar("Page", "file://" + url);
    wpis.goToSelectedPageByLink("AkitaPageMock", akitaScenario.getVar("Page").toString());
}
 
Example #11
Source Project: akita   Author: alfa-laboratory   File: RoundUpStepsTest.java    License: Apache License 2.0 5 votes vote down vote up
@BeforeAll
static void setup() {
    akitaScenario = AkitaScenario.getInstance();
    Scenario scenario = new StubScenario();
    akitaScenario.setEnvironment(new AkitaEnvironment(scenario));
    wpis = new WebPageInteractionSteps();
    elis = new ElementsVerificationSteps();
    rus = new RoundUpSteps();
    String inputFilePath = "src/test/resources/AkitaPageMock.html";
    String url = new File(inputFilePath).getAbsolutePath();
    akitaScenario.setVar("Page", "file://" + url);
    String inputFilePath2 = "src/test/resources/RedirectionPage.html";
    String url2 = new File(inputFilePath2).getAbsolutePath();
    akitaScenario.setVar("RedirectionPage", "file://" + url2);
}
 
Example #12
Source Project: akita   Author: alfa-laboratory   File: ManageBrowserCookieStepsTest.java    License: Apache License 2.0 5 votes vote down vote up
@BeforeAll
static void setup() {
    dmbs = new ManageBrowserSteps();
    akitaScenario = AkitaScenario.getInstance();
    Scenario scenario = new StubScenario();
    akitaScenario.setEnvironment(new AkitaEnvironment(scenario));
    wpis = new WebPageInteractionSteps();
    webDriver = mock(WebDriver.class);
    WebDriverRunner.setWebDriver(webDriver);
    when(webDriver.manage()).thenReturn(mock(WebDriver.Options.class));
}
 
Example #13
Source Project: bdt   Author: Stratio   File: HookGSpec.java    License: Apache License 2.0 5 votes vote down vote up
@Before
public void quit_if_tagged_scenario_failed(Scenario scenario) throws Throwable {
    if (prevScenarioFailed) {
        if (!isTagIncludedInScenario(scenario, alwaysTAG)) {
            commonspec.getLogger().warn("An important scenario has failed! TESTS EXECUTION ABORTED!");
            throw new SuppressableException("An important scenario has failed! TESTS EXECUTION ABORTED!", true);
        } else {
            loggerEnabled = true;
        }
    }
}
 
Example #14
Source Project: akita   Author: alfa-laboratory   File: BaseMethodsTest.java    License: Apache License 2.0 5 votes vote down vote up
@BeforeAll
static void setup() {
    akitaScenario = AkitaScenario.getInstance();
    Scenario scenario = new StubScenario();
    akitaScenario.setEnvironment(new AkitaEnvironment(scenario));
    bm = new BaseMethods();
    wpis = new WebPageInteractionSteps();
    String inputFilePath = "src/test/resources/AkitaPageMock.html";
    String url = new File(inputFilePath).getAbsolutePath();
    akitaScenario.setVar("Page", "file://" + url);
    String inputFilePath2 = "src/test/resources/RedirectionPage.html";
    String url2 = new File(inputFilePath2).getAbsolutePath();
    akitaScenario.setVar("RedirectionPage", "file://" + url2);
}
 
Example #15
Source Project: akita   Author: alfa-laboratory   File: InputFieldStepsTest.java    License: Apache License 2.0 5 votes vote down vote up
@BeforeAll
static void setup() {
    akitaScenario = AkitaScenario.getInstance();
    Scenario scenario = new StubScenario();
    akitaScenario.setEnvironment(new AkitaEnvironment(scenario));
    iis = new InputInteractionSteps();
    wpis = new WebPageInteractionSteps();
    String inputFilePath = "src/test/resources/AkitaPageMock.html";
    String url = new File(inputFilePath).getAbsolutePath();
    akitaScenario.setVar("Page", "file://" + url);
    String inputFilePath2 = "src/test/resources/RedirectionPage.html";
    String url2 = new File(inputFilePath2).getAbsolutePath();
    akitaScenario.setVar("RedirectionPage", "file://" + url2);
}
 
Example #16
Source Project: akita   Author: alfa-laboratory   File: ManageBrowserStepsTest.java    License: Apache License 2.0 5 votes vote down vote up
@BeforeAll
static void setup() {
    dmbs = new ManageBrowserSteps();
    akitaScenario = AkitaScenario.getInstance();
    Scenario scenario = new StubScenario();
    akitaScenario.setEnvironment(new AkitaEnvironment(scenario));
    wpis = new WebPageInteractionSteps();
    String inputFilePath = "src/test/resources/AkitaPageMock.html";
    String url = new File(inputFilePath).getAbsolutePath();
    akitaScenario.setVar("Page", "file://" + url);
    String inputFilePath2 = "src/test/resources/RedirectionPage.html";
    String url2 = new File(inputFilePath2).getAbsolutePath();
    akitaScenario.setVar("RedirectionPage", "file://" + url2);
}
 
Example #17
@After("@mdpsim")
public void afterSimScenario(final Scenario scenario) {
    mdpFeedSimHelper.release();
    try {
        Thread.currentThread().sleep(TimeUnit.SECONDS.toMillis(1));
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
}
 
Example #18
Source Project: blog   Author: DamienFremont   File: CucumberHooks.java    License: MIT License 5 votes vote down vote up
@After
public void watch_this_tagged_scenario(Scenario scenario) throws Exception {
	if (isTagged(scenario)) {
		boolean isFailed = scenario.isFailed();
		if (isFailed)
			prevScenarioFailed = isFailed;
	}
}
 
Example #19
Source Project: bdt   Author: Stratio   File: CommonG.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Looks for webelements inside a selenium context. This search will be made
 * by id, name and xpath expression matching an {@code locator} value
 *
 * @param method        class of element to be searched
 * @param element       webElement searched in selenium context
 * @param expectedCount integer. Expected number of elements.
 * @param scenario      Cucumber Scenario
 * @return List(WebElement)
 * @throws IllegalAccessException   exception
 * @throws IllegalArgumentException exception
 * @throws SecurityException        exception
 * @throws NoSuchFieldException     exception
 * @throws ClassNotFoundException   exception
 */
public List<WebElement> locateElement(String method, String element,
                                      Integer expectedCount, Scenario scenario) throws ClassNotFoundException, NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {

    List<WebElement> wel = null;

    if ("id".equals(method)) {
        logger.debug("Locating {} by id", element);
        wel = this.getDriver().findElements(By.id(element));
    } else if ("name".equals(method)) {
        logger.debug("Locating {} by name", element);
        wel = this.getDriver().findElements(By.name(element));
    } else if ("class".equals(method)) {
        logger.debug("Locating {} by class", element);
        wel = this.getDriver().findElements(By.className(element));
    } else if ("xpath".equals(method)) {
        logger.debug("Locating {} by xpath", element);
        wel = this.getDriver().findElements(By.xpath(element));
    } else if ("css".equals(method)) {
        wel = this.getDriver().findElements(By.cssSelector(element));
    } else {
        fail("Unknown search method: " + method);
    }

    if (expectedCount != -1) {
        PreviousWebElements pwel = new PreviousWebElements(wel);
        assertThat(this, scenario, pwel).as("Element count doesnt match").hasSize(expectedCount);
    }

    return wel;
}
 
Example #20
Source Project: bdt   Author: Stratio   File: HookGSpec.java    License: Apache License 2.0 5 votes vote down vote up
@After
public void afterScenario(Scenario scenario) throws Throwable {
    if (scenario.getStatus() == Result.Type.UNDEFINED) {
        if (!commonspec.getExceptions().isEmpty()) {
            scenario.write(commonspec.getExceptions().get(commonspec.getExceptions().size() - 1).toString());
        }
    }
}
 
Example #21
Source Project: qa-automation-samples   Author: concretesolutions   File: Hooks.java    License: MIT License 4 votes vote down vote up
@After
public void afterEachScenario(Scenario scenario) {
    AllureHelper.saveScreenshootOfScenario(scenario);
    Browsers.quitDriver();
}
 
Example #22
Source Project: demo-java   Author: saucelabs-training   File: StepDefinitions.java    License: MIT License 4 votes vote down vote up
@Before
public void setUp(Scenario scenario) {
    options.set(new SauceOptions());
    options.get().setName(scenario.getName());

    if (System.getenv("START_TIME") != null) {
        options.get().setBuild("Build Time: " + System.getenv("START_TIME"));
    }

    String platform;
    if (System.getProperty("platform") != null) {
        platform = System.getProperty("platform");
    } else {
        platform = "default";
    }

    switch(platform) {
        case "windows_10_edge":
            options.get().setPlatformName(SaucePlatform.WINDOWS_10);
            options.get().setBrowserName(Browser.EDGE);
            break;
        case "mac_sierra_chrome":
            options.get().setPlatformName(SaucePlatform.MAC_SIERRA);
            options.get().setBrowserName(Browser.CHROME);
            break;
        case "windows_8_ff":
            options.get().setPlatformName(SaucePlatform.WINDOWS_8);
            options.get().setBrowserName(Browser.FIREFOX);
            break;
        case "windows_8_1_ie":
            options.get().setPlatformName(SaucePlatform.WINDOWS_8_1);
            options.get().setBrowserName(Browser.INTERNET_EXPLORER);
            break;
        case "mac_mojave_safari":
            options.get().setPlatformName(SaucePlatform.MAC_MOJAVE);
            options.get().setBrowserName(Browser.SAFARI);
            break;
        default:
            // accept Sauce defaults
            break;
    }

    session.set(new SauceSession(options.get()));

    getSession().start();
    wait = new WebDriverWait(getDriver(), 10);
}
 
Example #23
Source Project: blog   Author: DamienFremont   File: StepDefinitions.java    License: MIT License 4 votes vote down vote up
@After
public void after(Scenario s) throws Exception {
	// Tell Cucumber to quit after this scenario is done - if it failed.
	CucumberHooks.wantsToQuit = true == s.isFailed();
}
 
Example #24
Source Project: bdt   Author: Stratio   File: Assertions.java    License: Apache License 2.0 4 votes vote down vote up
public static SeleniumAssert assertThat(CommonG common, Scenario scenario, WebElement actual) {
    return new SeleniumAssert(common, scenario, actual);
}
 
Example #25
Source Project: allure-java   Author: allure-framework   File: AttachmentSteps.java    License: Apache License 2.0 4 votes vote down vote up
@Before("@attachments")
public void setup(Scenario scenario)
{
    this.scenario = scenario;
}
 
Example #26
Source Project: NoraUi   Author: NoraUi   File: PickleStepDefinitionMatch.java    License: GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public void dryRunStep(Scenario scenario) throws Throwable {
    // Do nothing
}
 
Example #27
Source Project: oxTrust   Author: GluuFederation   File: ServerStatusSteps.java    License: MIT License 4 votes vote down vote up
@Before
public void setup(Scenario scenario) {
	startRecorder(scenario);
}
 
Example #28
Source Project: bdt   Author: Stratio   File: Assertions.java    License: Apache License 2.0 4 votes vote down vote up
public static SeleniumAssert assertThat(CommonG common, Scenario scenario, boolean actual) {
    return new SeleniumAssert(common, scenario, actual);
}
 
Example #29
Source Project: oxTrust   Author: GluuFederation   File: LogFileSteps.java    License: MIT License 4 votes vote down vote up
@After
public void clear(Scenario scenario) {
	homePage.takeScreenShot(scenario);
	stopRecorder();
	homePage.clear();
}
 
Example #30
Source Project: oxTrust   Author: GluuFederation   File: AttributesSteps.java    License: MIT License 4 votes vote down vote up
@Before
public void setup(Scenario scenario) {
	startRecorder(scenario);
}