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 File: InitializeWebDrive.java    From SeleniumCucumber with 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 File: CommonG.java    From bdt with 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 #3
Source File: Print.java    From qa-automation-samples with 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 #4
Source File: HookGSpec.java    From bdt with 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 #5
Source File: InitialSetupHooks.java    From akita with 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 File: AllureHelper.java    From qa-automation-samples with 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 #7
Source File: CommonG.java    From bdt with 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 #8
Source File: AllureHelper.java    From qa-automation-samples with 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 #9
Source File: AkitaPageTest.java    From akita with 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 #10
Source File: AkitaScenarioTest.java    From akita with 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 #11
Source File: AkitaEnvironmentTest.java    From akita with 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 #12
Source File: PagesTest.java    From akita with 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 #13
Source File: RoundUpStepsTest.java    From akita with 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 #14
Source File: ManageBrowserCookieStepsTest.java    From akita with 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 #15
Source File: HookGSpec.java    From bdt with 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 #16
Source File: BaseMethodsTest.java    From akita with 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 #17
Source File: InputFieldStepsTest.java    From akita with 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 #18
Source File: ManageBrowserStepsTest.java    From akita with 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 #19
Source File: MdpSimulatorHooks.java    From java-cme-mdp3-handler with GNU Lesser General Public License v3.0 5 votes vote down vote up
@After("@mdpsim")
public void afterSimScenario(final Scenario scenario) {
    mdpFeedSimHelper.release();
    try {
        Thread.currentThread().sleep(TimeUnit.SECONDS.toMillis(1));
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
}
 
Example #20
Source File: CucumberHooks.java    From blog with 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 #21
Source File: CucumberHelperTestSteps.java    From espresso-cucumber with Apache License 2.0 4 votes vote down vote up
public static Scenario getScenario() {
    return CucumberHelperTestSteps.scenario;
}
 
Example #22
Source File: CucumberHooks.java    From blog with MIT License 4 votes vote down vote up
private boolean isTagged(Scenario scenario) {
	Collection<String> tags = scenario.getSourceTagNames();
	return tags.contains(TAG);
}
 
Example #23
Source File: ConfigurationSteps.java    From oxTrust with MIT License 4 votes vote down vote up
@After
public void clear(Scenario scenario) {
	homePage.takeScreenShot(scenario);
	stopRecorder();
	homePage.clear();
}
 
Example #24
Source File: LoadRunnerFilter.java    From cukes with Apache License 2.0 4 votes vote down vote up
@Before
public void beforeScenario(Scenario scenario) {
    createLoadRunnerTransaction(scenario.getName());
}
 
Example #25
Source File: HookGSpec.java    From bdt with Apache License 2.0 4 votes vote down vote up
private boolean isTagIncludedInScenario(Scenario scenario, String customTAG) {
    Collection<String> tags = scenario.getSourceTagNames();
    return tags.contains(customTAG);
}
 
Example #26
Source File: CucumberReportingExtension.java    From senbot with MIT License 4 votes vote down vote up
@Before
public void beforeScenario(Scenario scenario) {
    log.debug("Scenarion started");
    ScenarioGlobals startNewScenario = getCucumberManager().startNewScenario();
}
 
Example #27
Source File: ProfileSteps.java    From oxTrust with MIT License 4 votes vote down vote up
@After
public void clear(Scenario scenario) {
	homePage.takeScreenShot(scenario);
	stopRecorder();
	homePage.clear();
}
 
Example #28
Source File: PickleStepDefinitionMatch.java    From bdt with Apache License 2.0 4 votes vote down vote up
@Override
public void dryRunStep(Scenario scenario) throws Throwable {
    // Do nothing
}
 
Example #29
Source File: CustomScriptSteps.java    From oxTrust with MIT License 4 votes vote down vote up
@Before
public void setup(Scenario scenario) {
	startRecorder(scenario);
}
 
Example #30
Source File: OpenIdConnectSteps.java    From oxTrust with MIT License 4 votes vote down vote up
@After
public void clear(Scenario scenario) {
	homePage.takeScreenShot(scenario);
	stopRecorder();
	homePage.clear();
}