com.codeborne.selenide.logevents.SelenideLogger Java Examples

The following examples show how to use com.codeborne.selenide.logevents.SelenideLogger. 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: AllureSelenideTest.java    From allure-java with Apache License 2.0 6 votes vote down vote up
@AllureFeatures.Steps
@Test
void shouldLogPassedSteps() {
    final AllureResults results = runWithinTestContext(() -> {
        final AllureSelenide selenide = new AllureSelenide()
                .savePageSource(false)
                .screenshots(false);
        SelenideLogger.addListener(UUID.randomUUID().toString(), selenide);
        final SelenideLog log = SelenideLogger.beginStep(
                "dummy source",
                "dummyMethod()",
                "param1",
                "param2"
        );
        SelenideLogger.commitStep(log, LogEvent.EventStatus.PASS);
    });

    final StepResult selenideStep = extractStepFromResults(results);
    assertThat(selenideStep)
            .extracting(StepResult::getName, StepResult::getStatus)
            .containsExactly(
                    "$(\"dummy source\") dummy method()([param1, param2])",
                    Status.PASSED
            );
}
 
Example #2
Source File: AllureSelenideTest.java    From allure-java with Apache License 2.0 6 votes vote down vote up
@AllureFeatures.Steps
@Test
void shouldNotLogSelenideLocatorSteps() {
    final AllureResults results = runWithinTestContext(() -> {
        final AllureSelenide selenide = new AllureSelenide()
                .savePageSource(false)
                .screenshots(false)
                .includeSelenideSteps(false);
        SelenideLogger.addListener(UUID.randomUUID().toString(), selenide);
        Allure.step("step1");
        final SelenideLog log = SelenideLogger.beginStep(
                "dummy source",
                "dummyMethod()"
        );
        SelenideLogger.commitStep(log, LogEvent.EventStatus.PASS);
        Allure.step("step2");
    });

    List<StepResult> steps = extractAllStepsFromResults(results);
    assertThat(steps).hasSize(2);
    assertThat(steps.get(0).getName()).isEqualTo("step1");
    // no selenide steps in between
    assertThat(steps.get(1).getName()).isEqualTo("step2");
}
 
Example #3
Source File: AllureSelenideTest.java    From allure-java with Apache License 2.0 6 votes vote down vote up
@AllureFeatures.Attachments
@Test
void shouldNotFailIfBrowserIsNotOpened() {
    final AllureResults results = runWithinTestContext(() -> {
        final AllureSelenide selenide = new AllureSelenide()
            .savePageSource(false)
            .screenshots(true);
        SelenideLogger.addListener(UUID.randomUUID().toString(), selenide);
        final SelenideLog log = SelenideLogger.beginStep(
            "open",
            "https://some.url"
        );
        SelenideLogger.commitStep(log, new WebDriverException("failed to open a browser"));
    });

    final StepResult selenideStep = extractStepFromResults(results);
    assertThat(selenideStep.getStatus()).isEqualTo(Status.BROKEN);
    assertThat(selenideStep.getStatusDetails().getMessage()).startsWith("failed to open a browser");
    assertThat(selenideStep.getName()).isEqualTo("$(\"open\") https://some.url");
    assertThat(selenideStep.getStage()).isEqualTo(Stage.FINISHED);
    assertThat(selenideStep.getAttachments()).hasSize(0);
}
 
Example #4
Source File: DemoIntegrationAT.java    From n2o-framework with Apache License 2.0 5 votes vote down vote up
@BeforeAll
public static void configure() {
    SelenideLogger.addListener("AllureSelenide", new AllureSelenide());

    System.setProperty("chromeoptions.args", "--no-sandbox,--verbose,--whitelisted-ips=''");

    headless = true;
    browserSize = "1920x1200";
}
 
Example #5
Source File: AllureSelenideTest.java    From allure-java with Apache License 2.0 5 votes vote down vote up
@AllureFeatures.Steps
@Test
void shouldLogStepTimings() {
    final AllureResults results = runWithinTestContext(() -> {
        final AllureSelenide selenide = new AllureSelenide()
                .savePageSource(false)
                .screenshots(false);
        SelenideLogger.addListener(UUID.randomUUID().toString(), selenide);
        final SelenideLog log = SelenideLogger.beginStep(
                "dummy source",
                "dummyMethod()",
                "param1",
                "param2"
        );
        SelenideLogger.commitStep(log, LogEvent.EventStatus.PASS);
    });

    final StepResult selenideStep = extractStepFromResults(results);
    assertThat(selenideStep)
            .as("start timestamp")
            .extracting(StepResult::getStart)
            .isNotNull();

    assertThat(selenideStep)
            .as("stop timestamp")
            .extracting(StepResult::getStop)
            .isNotNull();
}
 
Example #6
Source File: AllureSelenideTest.java    From allure-java with Apache License 2.0 5 votes vote down vote up
@AllureFeatures.Attachments
@Test
void shouldSaveScreenshotsOnFail() {
    final ChromeDriver wdMock = mock(ChromeDriver.class);
    WebDriverRunner.setWebDriver(wdMock);
    doReturn("hello".getBytes(StandardCharsets.UTF_8))
            .when(wdMock).getScreenshotAs(OutputType.BYTES);

    final AllureResults results = runWithinTestContext(() -> {
        final AllureSelenide selenide = new AllureSelenide()
                .savePageSource(false)
                .screenshots(true);
        SelenideLogger.addListener(UUID.randomUUID().toString(), selenide);
        final SelenideLog log = SelenideLogger.beginStep(
                "dummy source",
                "dummyMethod()",
                "param1",
                "param2"
        );
        SelenideLogger.commitStep(log, new Exception("something went wrong"));
    });

    final StepResult selenideStep = extractStepFromResults(results);
    assertThat(selenideStep.getAttachments())
            .hasSize(1);

    final Attachment attachment = selenideStep.getAttachments().iterator().next();
    assertThat(results.getAttachments())
            .containsKey(attachment.getSource());

    final String attachmentContent = new String(
            results.getAttachments().get(attachment.getSource()),
            StandardCharsets.UTF_8
    );

    assertThat(attachmentContent)
            .isEqualTo("hello");
}
 
Example #7
Source File: AllureSelenideTest.java    From allure-java with Apache License 2.0 5 votes vote down vote up
@AllureFeatures.Attachments
@Test
void shouldSavePageSourceOnFail() {
    final ChromeDriver wdMock = mock(ChromeDriver.class);
    WebDriverRunner.setWebDriver(wdMock);
    doReturn("dummy-page-source")
            .when(wdMock).getPageSource();

    final AllureResults results = runWithinTestContext(() -> {
        final AllureSelenide selenide = new AllureSelenide()
                .screenshots(false)
                .savePageSource(true);
        SelenideLogger.addListener(UUID.randomUUID().toString(), selenide);
        final SelenideLog log = SelenideLogger.beginStep(
                "dummy source",
                "dummyMethod()",
                "param1",
                "param2"
        );
        SelenideLogger.commitStep(log, new Exception("something went wrong"));
    });

    final StepResult selenideStep = extractStepFromResults(results);
    assertThat(selenideStep.getAttachments())
            .hasSize(1);

    final Attachment attachment = selenideStep.getAttachments().iterator().next();
    assertThat(results.getAttachments())
            .containsKey(attachment.getSource());

    final String attachmentContent = new String(
            results.getAttachments().get(attachment.getSource()),
            StandardCharsets.UTF_8
    );

    assertThat(attachmentContent)
            .isEqualTo("dummy-page-source");
}
 
Example #8
Source File: AllureSelenideTest.java    From allure-java with Apache License 2.0 5 votes vote down vote up
@AllureFeatures.Steps
@Test
void shouldLogFailedSteps() {
    final AllureResults results = runWithinTestContext(() -> {
        final AllureSelenide selenide = new AllureSelenide()
                .savePageSource(false)
                .screenshots(false);
        SelenideLogger.addListener(UUID.randomUUID().toString(), selenide);
        final SelenideLog log = SelenideLogger.beginStep(
                "dummy source",
                "dummyMethod()",
                "param1",
                "param2"
        );
        SelenideLogger.commitStep(log, new Exception("something went wrong"));
    });

    final StepResult selenideStep = extractStepFromResults(results);
    assertThat(selenideStep)
            .extracting(StepResult::getName, StepResult::getStatus)
            .containsExactly(
                    "$(\"dummy source\") dummy method()([param1, param2])",
                    Status.BROKEN
            );

    assertThat(selenideStep)
            .extracting(s -> s.getStatusDetails().getMessage())
            .isEqualTo("something went wrong");
}
 
Example #9
Source File: AllureSelenideTest.java    From allure-java with Apache License 2.0 5 votes vote down vote up
@AllureFeatures.Steps
@Test
void shouldSupportNestedSteps() {
    final AllureResults results = runWithinTestContext(() -> {
        final AllureSelenide selenide = new AllureSelenide()
                .savePageSource(false)
                .screenshots(false);
        SelenideLogger.addListener(UUID.randomUUID().toString(), selenide);
        final SelenideLog log = SelenideLogger.beginStep(
                "dummy source",
                "dummyMethod()",
                "param1",
                "param2"
        );

        Allure.step("child1");
        Allure.step("child2");
        Allure.step("child3");

        SelenideLogger.commitStep(log, LogEvent.EventStatus.PASS);
    });

    final StepResult selenideStep = extractStepFromResults(results);
    assertThat(selenideStep.getSteps())
            .extracting(StepResult::getName)
            .containsExactly("child1", "child2", "child3");
}
 
Example #10
Source File: SelenideAddons.java    From neodymium-library with MIT License 5 votes vote down vote up
/**
 * The missing wrapper to generate screenshots and save the html source code if a jUnit assertion fails.<br>
 * <br>
 * <p>
 * Sample: Assert that page title is correct and dump the page source and a screenshot in case of a mismatch
 * <code> wrapAssertionError(()-&gt;{Assert.assertEquals("MyPageTitle", Selenide.title());});</code>
 * </p>
 * 
 * @param runnable
 *            The lambda containing an assertion
 */
public static void wrapAssertionError(final Runnable runnable)
{
    try
    {
        runnable.run();
    }
    catch (AssertionError e)
    {
        Driver driver = WebDriverRunner.driver();
        String message = "No error message provided by the Assertion.";
        if (StringUtils.isNotBlank(e.getMessage()))
        {
            message = e.getMessage();
        }
        else
        {
            AssertionError wrapper = new AssertionError(message, e.getCause());
            wrapper.setStackTrace(e.getStackTrace());
            e = wrapper;
        }
        SelenideLogger.commitStep(new SelenideLog("Assertion error", message), e);
        if (!driver.config().assertionMode().equals(AssertionMode.SOFT))
        {
            throw UIAssertionError.wrap(driver, e, 0);
        }
    }
}
 
Example #11
Source File: AutoTestBase.java    From n2o-framework with Apache License 2.0 4 votes vote down vote up
public static void configureSelenide() {
    SelenideLogger.addListener("AllureSelenide", new AllureSelenide());
    System.setProperty("chromeoptions.args", "--no-sandbox,--verbose,--whitelisted-ips=''");
    headless = true;
}
 
Example #12
Source File: AllureSelenideTest.java    From allure-java with Apache License 2.0 4 votes vote down vote up
@AllureFeatures.Attachments
@Test
void shouldSaveLogs() {
    final LogEntry logEntry = new LogEntry(Level.ALL, 10, "SIMPLE LOG");
    final LogEntries logEntries = new LogEntries(Collections.singletonList(logEntry));
    final ChromeDriver wdMock = mock(ChromeDriver.class);
    final Logs logsMock = mock(Logs.class);
    final Options optionsMock = mock(Options.class);

    WebDriverRunner.setWebDriver(wdMock);

    doReturn(optionsMock).when(wdMock).manage();
    doReturn(logsMock).when(optionsMock).logs();
    doReturn(logEntries).when(logsMock).get(LogType.BROWSER.toString());

    final AllureResults results = runWithinTestContext(() -> {
        final AllureSelenide selenide = new AllureSelenide()
                .enableLogs(LogType.BROWSER, Level.ALL)
                .savePageSource(false)
                .screenshots(false);

        SelenideLogger.addListener(UUID.randomUUID().toString(), selenide);

        final SelenideLog log = SelenideLogger.beginStep(
            "dummy source",
            "dummyMethod()",
            "param1",
            "param2");

        SelenideLogger.commitStep(log, new Exception("something went wrong"));
    });

    final StepResult selenideStep = extractStepFromResults(results);
    final Attachment attachment = selenideStep.getAttachments().iterator().next();
    final String attachmentContent = new String(
        results.getAttachments().get(attachment.getSource()),
        StandardCharsets.UTF_8
    );

    assertThat(selenideStep.getAttachments()).hasSize(1);
    assertThat(results.getAttachments()).containsKey(attachment.getSource());
    assertThat(attachmentContent).isEqualTo(logEntry.toString());
}
 
Example #13
Source File: NeodymiumCucumberRunListener.java    From neodymium-library with MIT License 4 votes vote down vote up
public NeodymiumCucumberRunListener()
{
    SelenideLogger.addListener(LISTENER_NAME, new AllureSelenide());
}
 
Example #14
Source File: NeodymiumRunner.java    From neodymium-library with MIT License 4 votes vote down vote up
public NeodymiumRunner(Class<?> klass) throws InitializationError
{
    super(klass);
    SelenideLogger.addListener(LISTENER_NAME, new AllureSelenide());
}
 
Example #15
Source File: CucumberSupport.java    From neodymium-library with MIT License 4 votes vote down vote up
@Then("^validate the AllureSelenide listener is active$")
public void validateAllureSelenideListenerIsActive()
{
    Assert.assertTrue(" AllureSelenide listener is not attached", SelenideLogger.hasListener(NeodymiumCucumberRunListener.LISTENER_NAME));
}
 
Example #16
Source File: AllureSelenideListenerIsActiveForJava.java    From neodymium-library with MIT License 4 votes vote down vote up
@Test
public void testWaitingAnimationSelectorUnconfigured()
{
    Assert.assertTrue(" AllureSelenide listener is not attached", SelenideLogger.hasListener(NeodymiumRunner.LISTENER_NAME));
}