Search in sources :

Example 11 with TestStep

use of com.seleniumtests.reporter.logger.TestStep in project seleniumRobot by bhecquet.

the class TestTestLogging method testError.

@Test(groups = { "ut" })
public void testError() {
    TestStepManager.setCurrentRootTestStep(new TestStep("step", null, new ArrayList<>(), true));
    logger.error("message");
    Assert.assertEquals(((TestMessage) (TestStepManager.getParentTestStep().getStepActions().get(0))).getMessageType(), MessageType.ERROR);
}
Also used : TestStep(com.seleniumtests.reporter.logger.TestStep) ArrayList(java.util.ArrayList) Test(org.testng.annotations.Test) GenericTest(com.seleniumtests.GenericTest)

Example 12 with TestStep

use of com.seleniumtests.reporter.logger.TestStep in project seleniumRobot by bhecquet.

the class TestTestLogging method testLogScreenshotOk.

@Test(groups = { "ut" })
public void testLogScreenshotOk() {
    TestStepManager.setCurrentRootTestStep(new TestStep("step", null, new ArrayList<>(), true));
    logger.logScreenshot(new ScreenShot());
    Assert.assertEquals(TestStepManager.getParentTestStep().getSnapshots().size(), 1);
}
Also used : TestStep(com.seleniumtests.reporter.logger.TestStep) ScreenShot(com.seleniumtests.driver.screenshots.ScreenShot) ArrayList(java.util.ArrayList) Test(org.testng.annotations.Test) GenericTest(com.seleniumtests.GenericTest)

Example 13 with TestStep

use of com.seleniumtests.reporter.logger.TestStep in project seleniumRobot by bhecquet.

the class TestTestLogging method testRelocateHarNull.

/**
 * Test no error is raised is outputDirectory is null
 * @throws IOException
 */
@Test(groups = { "ut" })
public void testRelocateHarNull() throws IOException {
    try {
        TestStepManager.setCurrentRootTestStep(new TestStep("step", null, new ArrayList<>(), true));
        Har har = new Har(new HarLog());
        har.getLog().addPage(new HarPage("title", "a title"));
        logger.logNetworkCapture(har, "main");
        File initialFile = TestStepManager.getParentTestStep().getHarCaptures().get(0).getFile();
        // file exists before moving
        Assert.assertTrue(initialFile.exists());
        // relocate
        TestStepManager.getParentTestStep().getHarCaptures().get(0).relocate(null);
    } finally {
        FileUtils.deleteQuietly(new File(SeleniumTestsContextManager.getThreadContext().getOutputDirectory()));
    }
}
Also used : TestStep(com.seleniumtests.reporter.logger.TestStep) HarLog(net.lightbody.bmp.core.har.HarLog) ArrayList(java.util.ArrayList) Har(net.lightbody.bmp.core.har.Har) HarPage(net.lightbody.bmp.core.har.HarPage) File(java.io.File) Test(org.testng.annotations.Test) GenericTest(com.seleniumtests.GenericTest)

Example 14 with TestStep

use of com.seleniumtests.reporter.logger.TestStep in project seleniumRobot by bhecquet.

the class TestTestLogging method testInfo.

@Test(groups = { "ut" })
public void testInfo() {
    TestStepManager.setCurrentRootTestStep(new TestStep("step", null, new ArrayList<>(), true));
    logger.info("message");
    Assert.assertEquals(TestStepManager.getParentTestStep().getStepActions().size(), 1);
    Assert.assertTrue(TestStepManager.getParentTestStep().getStepActions().get(0) instanceof TestMessage);
    Assert.assertEquals(((TestMessage) (TestStepManager.getParentTestStep().getStepActions().get(0))).getMessageType(), MessageType.INFO);
}
Also used : TestStep(com.seleniumtests.reporter.logger.TestStep) ArrayList(java.util.ArrayList) TestMessage(com.seleniumtests.reporter.logger.TestMessage) Test(org.testng.annotations.Test) GenericTest(com.seleniumtests.GenericTest)

Example 15 with TestStep

use of com.seleniumtests.reporter.logger.TestStep in project seleniumRobot by bhecquet.

the class TestTestLogging method testRelocateScreenshotSamePath.

@Test(groups = { "ut" })
public void testRelocateScreenshotSamePath() throws IOException {
    try {
        TestStepManager.setCurrentRootTestStep(new TestStep("step", null, new ArrayList<>(), true));
        ScreenShot screenshot = new ScreenShot();
        String imgSourcePath = Paths.get(SeleniumTestsContextManager.getThreadContext().getOutputDirectory(), ScreenshotUtil.SCREENSHOT_DIR, "capture.png").toString();
        FileUtils.write(new File(imgSourcePath), "<img>");
        // copied from ScreeshotUtils class
        screenshot.setImagePath(String.format("%s/%s.png", ScreenshotUtil.SCREENSHOT_DIR, "capture"));
        logger.logScreenshot(screenshot);
        File initialFile = new File(TestStepManager.getParentTestStep().getSnapshots().get(0).getScreenshot().getFullImagePath());
        // file exists before moving
        Assert.assertTrue(initialFile.exists());
        Assert.assertEquals(TestStepManager.getParentTestStep().getSnapshots().get(0).getScreenshot().getHtmlSource(), "");
        // check no error is raised if we ask the files to be moved at the same place
        TestStepManager.getParentTestStep().getSnapshots().get(0).relocate(SeleniumTestsContextManager.getThreadContext().getOutputDirectory());
    } finally {
        FileUtils.deleteQuietly(new File(SeleniumTestsContextManager.getThreadContext().getOutputDirectory()));
        FileUtils.deleteQuietly(new File(SeleniumTestsContextManager.getThreadContext().getOutputDirectory() + "_moved"));
    }
}
Also used : TestStep(com.seleniumtests.reporter.logger.TestStep) ScreenShot(com.seleniumtests.driver.screenshots.ScreenShot) ArrayList(java.util.ArrayList) File(java.io.File) Test(org.testng.annotations.Test) GenericTest(com.seleniumtests.GenericTest)

Aggregations

TestStep (com.seleniumtests.reporter.logger.TestStep)190 Test (org.testng.annotations.Test)148 GenericTest (com.seleniumtests.GenericTest)120 ArrayList (java.util.ArrayList)80 TestAction (com.seleniumtests.reporter.logger.TestAction)47 File (java.io.File)37 ScreenShot (com.seleniumtests.driver.screenshots.ScreenShot)25 Snapshot (com.seleniumtests.reporter.logger.Snapshot)24 ErrorCause (com.seleniumtests.core.testanalysis.ErrorCause)19 TestMessage (com.seleniumtests.reporter.logger.TestMessage)16 GenericFile (com.seleniumtests.reporter.logger.GenericFile)15 MockitoTest (com.seleniumtests.MockitoTest)12 HashMap (java.util.HashMap)12 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)12 ITestResult (org.testng.ITestResult)10 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)9 Uft (com.seleniumtests.connectors.extools.Uft)8 DriverExceptions (com.seleniumtests.customexception.DriverExceptions)8 ConfigurationException (com.seleniumtests.customexception.ConfigurationException)7 SeleniumRobotServerException (com.seleniumtests.customexception.SeleniumRobotServerException)6