Search in sources :

Example 6 with VideoRecorder

use of com.seleniumtests.util.video.VideoRecorder in project seleniumRobot by bhecquet.

the class SeleniumRobotTestListener method logLastStep.

/**
 * On test end, will take a snap shot and store it
 */
private void logLastStep(ITestResult testResult) {
    // finalize manual steps if we use this mode
    try {
        TestTasks.addStep(null);
    } catch (ConfigurationException e) {
    // no problem as it's to close the previous manual step
    }
    TestStep tearDownStep = new TestStep(TestStepManager.LAST_STEP_NAME, testResult, new ArrayList<>(), true);
    scenarioLogger.logTestInfo(TestStepManager.LAST_STATE_NAME, new MultipleInfo(TestStepManager.LAST_STATE_NAME));
    // add step to video
    VideoRecorder videoRecorder = WebUIDriver.getThreadVideoRecorder();
    if (videoRecorder != null) {
        CustomEventFiringWebDriver.displayStepOnScreen(tearDownStep.getName(), SeleniumTestsContextManager.getThreadContext().getRunMode(), SeleniumTestsContextManager.getThreadContext().getSeleniumGridConnector(), videoRecorder);
    }
    TestStepManager.setCurrentRootTestStep(tearDownStep);
    if (testResult.isSuccess()) {
        scenarioLogger.log("Test is OK");
    } else if (testResult.getStatus() == ITestResult.FAILURE) {
        // issue #289: allow retry in case SO_TIMEOUT is raised
        if (SeleniumTestsContextManager.getThreadContext().getRunMode() != DriverMode.LOCAL && testResult.getThrowable() != null && testResult.getThrowable() instanceof WebDriverException && testResult.getThrowable().getMessage().contains("SO_TIMEOUT")) {
            logger.info("Test is retried due to SO_TIMEOUT");
            increaseMaxRetry();
        }
        String error = testResult.getThrowable() != null ? ExceptionUtility.getExceptionMessage(testResult.getThrowable()) : "no error found";
        scenarioLogger.log("Test is KO with error: " + error);
    } else {
        scenarioLogger.log("Test has not started or has been skipped");
    }
    logThrowableToTestEndStep(testResult);
    WebUIDriver.logFinalDriversState(testResult);
    tearDownStep.updateDuration();
    TestStepManager.logTestStep(tearDownStep);
}
Also used : TestStep(com.seleniumtests.reporter.logger.TestStep) ConfigurationException(com.seleniumtests.customexception.ConfigurationException) VideoRecorder(com.seleniumtests.util.video.VideoRecorder) MultipleInfo(com.seleniumtests.reporter.info.MultipleInfo) WebDriverException(org.openqa.selenium.WebDriverException)

Example 7 with VideoRecorder

use of com.seleniumtests.util.video.VideoRecorder in project seleniumRobot by bhecquet.

the class TestVideoRecorder method testVideoRecording.

/**
 * check file is created
 * @throws IOException
 */
@Test(groups = "it")
public void testVideoRecording() throws IOException {
    VideoRecorder recorder = new VideoRecorder(new File(SeleniumTestsContextManager.getThreadContext().getOutputDirectory()), "testFile.avi");
    recorder.start();
    // check JFrame is displayed
    Assert.assertNotNull(recorder.getLabel());
    Assert.assertEquals(recorder.getLabel().getText(), "Starting");
    Assert.assertTrue(recorder.getWindow().isShowing());
    Assert.assertNotNull(recorder.getWindow());
    WaitHelper.waitForSeconds(2);
    File recorded = recorder.stop();
    Assert.assertTrue("testFile.avi".equals(recorded.getName()));
    Assert.assertTrue(Paths.get(SeleniumTestsContextManager.getThreadContext().getOutputDirectory(), "testFile.avi").toFile().exists());
    Assert.assertEquals(new File(SeleniumTestsContextManager.getThreadContext().getOutputDirectory()).listFiles().length, 1);
    // check JFrame is reset
    Assert.assertFalse(recorder.getWindow().isShowing());
}
Also used : VideoRecorder(com.seleniumtests.util.video.VideoRecorder) File(java.io.File) Test(org.testng.annotations.Test) ReporterTest(com.seleniumtests.it.reporter.ReporterTest)

Aggregations

VideoRecorder (com.seleniumtests.util.video.VideoRecorder)7 File (java.io.File)4 TestStep (com.seleniumtests.reporter.logger.TestStep)3 Test (org.testng.annotations.Test)3 GenericTest (com.seleniumtests.GenericTest)2 MockitoTest (com.seleniumtests.MockitoTest)2 ScenarioException (com.seleniumtests.customexception.ScenarioException)2 WebUIDriver (com.seleniumtests.driver.WebUIDriver)2 ArrayList (java.util.ArrayList)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 NLWebDriver (com.neotys.selenium.proxies.NLWebDriver)1 BrowserInfo (com.seleniumtests.browserfactory.BrowserInfo)1 ConfigurationException (com.seleniumtests.customexception.ConfigurationException)1 ReporterTest (com.seleniumtests.it.reporter.ReporterTest)1 MultipleInfo (com.seleniumtests.reporter.info.MultipleInfo)1 TestAction (com.seleniumtests.reporter.logger.TestAction)1 PageObject (com.seleniumtests.uipage.PageObject)1 HeadlessException (java.awt.HeadlessException)1 Date (java.util.Date)1 BrowserMobProxy (net.lightbody.bmp.BrowserMobProxy)1