Search in sources :

Example 1 with ScenarioLogger

use of com.seleniumtests.util.logging.ScenarioLogger in project seleniumRobot by bhecquet.

the class SeleniumRobotTestPlan method finishTestMethod.

/**
 * According to TestNG doc, this method will be executed after the \@AfterMethod inside test classes
 * #issue 136: This will close any remaining browser for this thread and forbid user to create a new driver in other \@AfterXXX
 */
@AfterMethod(alwaysRun = true)
public void finishTestMethod(Method method, ITestResult testResult) {
    // stop video capture and log file
    File videoFile = WebUIDriver.stopVideoCapture();
    if (videoFile != null) {
        VideoUtils.extractReferenceForSteps(videoFile, TestStepManager.getInstance().getTestSteps(), Paths.get(SeleniumTestsContextManager.getThreadContext().getOutputDirectory()));
        if (SeleniumTestsContextManager.getThreadContext().getVideoCapture() == VideoCaptureMode.TRUE || (SeleniumTestsContextManager.getThreadContext().getVideoCapture() == VideoCaptureMode.ON_SUCCESS && testResult.isSuccess()) || (SeleniumTestsContextManager.getThreadContext().getVideoCapture() == VideoCaptureMode.ON_ERROR && !testResult.isSuccess())) {
            ((ScenarioLogger) logger).logFileToTestEnd(videoFile.getAbsoluteFile(), "Video capture");
            Info lastStateInfo = TestNGResultUtils.getTestInfo(testResult).get(TestStepManager.LAST_STATE_NAME);
            if (lastStateInfo != null) {
                ((MultipleInfo) lastStateInfo).addInfo(new VideoLinkInfo(TestNGResultUtils.getUniqueTestName(testResult) + "/videoCapture.avi"));
            }
            logger.info("Video file copied to " + videoFile.getAbsolutePath());
        } else {
            try {
                Files.delete(Paths.get(videoFile.getAbsolutePath()));
            } catch (IOException e) {
                logger.warn(String.format("Video file %s not deleted: %s", videoFile.getAbsoluteFile(), e.getMessage()));
            }
        }
    }
    WebUIDriver.cleanUp();
    SeleniumTestsContextManager.getThreadContext().setDriverCreationBlocked(true);
    SeleniumRobotTestListener.getCurrentListener().onTestFullyFinished(testResult);
}
Also used : ScenarioLogger(com.seleniumtests.util.logging.ScenarioLogger) MultipleInfo(com.seleniumtests.reporter.info.MultipleInfo) IOException(java.io.IOException) Info(com.seleniumtests.reporter.info.Info) MultipleInfo(com.seleniumtests.reporter.info.MultipleInfo) VideoLinkInfo(com.seleniumtests.reporter.info.VideoLinkInfo) VideoLinkInfo(com.seleniumtests.reporter.info.VideoLinkInfo) File(java.io.File) AfterMethod(org.testng.annotations.AfterMethod)

Example 2 with ScenarioLogger

use of com.seleniumtests.util.logging.ScenarioLogger in project seleniumRobot by bhecquet.

the class StubTestClassForListener5 method startDriver.

private void startDriver() {
    WebDriver driver = WebUIDriver.getWebDriver(true);
    driver.get("file:///" + Thread.currentThread().getContextClassLoader().getResource("tu/test.html").getFile());
    ((ScenarioLogger) logger).logScreenshot(new ScreenshotUtil(driver).capture(SnapshotTarget.PAGE, ScreenShot.class));
}
Also used : WebDriver(org.openqa.selenium.WebDriver) ScreenShot(com.seleniumtests.driver.screenshots.ScreenShot) ScreenshotUtil(com.seleniumtests.driver.screenshots.ScreenshotUtil) ScenarioLogger(com.seleniumtests.util.logging.ScenarioLogger)

Example 3 with ScenarioLogger

use of com.seleniumtests.util.logging.ScenarioLogger in project seleniumRobot by bhecquet.

the class StubTestClass method testInError.

@Test(groups = "stub")
public void testInError() {
    TestStep step1 = new TestStep("step 1", Reporter.getCurrentTestResult(), new ArrayList<>(), maskPassword);
    TestStepManager.setCurrentRootTestStep(step1);
    TestStepManager.getParentTestStep().addAction(new TestAction("click button", false, new ArrayList<>()));
    TestStepManager.getParentTestStep().addMessage(new TestMessage("click ok", MessageType.INFO));
    logger.warn("Some warning message");
    logger.info("Some Info message");
    logger.error("Some Error message");
    ((ScenarioLogger) logger).log("Some log message");
    ((ScenarioLogger) logger).logTestValue("key", "we found a value of", "10");
    TestStepManager.getParentTestStep().addAction(new TestAction("send keyboard action", false, new ArrayList<>()));
    TestStepManager.logTestStep(TestStepManager.getCurrentRootTestStep());
    Assert.fail("error");
}
Also used : TestStep(com.seleniumtests.reporter.logger.TestStep) ArrayList(java.util.ArrayList) ScenarioLogger(com.seleniumtests.util.logging.ScenarioLogger) TestMessage(com.seleniumtests.reporter.logger.TestMessage) TestAction(com.seleniumtests.reporter.logger.TestAction) Test(org.testng.annotations.Test)

Aggregations

ScenarioLogger (com.seleniumtests.util.logging.ScenarioLogger)3 ScreenShot (com.seleniumtests.driver.screenshots.ScreenShot)1 ScreenshotUtil (com.seleniumtests.driver.screenshots.ScreenshotUtil)1 Info (com.seleniumtests.reporter.info.Info)1 MultipleInfo (com.seleniumtests.reporter.info.MultipleInfo)1 VideoLinkInfo (com.seleniumtests.reporter.info.VideoLinkInfo)1 TestAction (com.seleniumtests.reporter.logger.TestAction)1 TestMessage (com.seleniumtests.reporter.logger.TestMessage)1 TestStep (com.seleniumtests.reporter.logger.TestStep)1 File (java.io.File)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 WebDriver (org.openqa.selenium.WebDriver)1 AfterMethod (org.testng.annotations.AfterMethod)1 Test (org.testng.annotations.Test)1