Search in sources :

Example 1 with HarPage

use of net.lightbody.bmp.core.har.HarPage 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 2 with HarPage

use of net.lightbody.bmp.core.har.HarPage in project seleniumRobot by bhecquet.

the class TestTestLogging method testBuildHarLog.

@Test(groups = { "ut" })
public void testBuildHarLog() throws IOException {
    TestStepManager.setCurrentRootTestStep(new TestStep("step", null, new ArrayList<>(), true));
    Har har = new Har(new HarLog());
    har.getLog().addPage(new HarPage("title", "a title"));
    HarCapture capture = new HarCapture(har, "main");
    Assert.assertEquals(capture.buildHarLog(), "Network capture 'main' browser: <a href='main-networkCapture.har'>HAR file</a>");
}
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) HarCapture(com.seleniumtests.reporter.logger.HarCapture) HarPage(net.lightbody.bmp.core.har.HarPage) Test(org.testng.annotations.Test) GenericTest(com.seleniumtests.GenericTest)

Example 3 with HarPage

use of net.lightbody.bmp.core.har.HarPage in project seleniumRobot by bhecquet.

the class TestTestLogging method testRelocateHar.

@Test(groups = { "ut" })
public void testRelocateHar() 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(SeleniumTestsContextManager.getThreadContext().getOutputDirectory() + "_moved");
        File movedFile = Paths.get(SeleniumTestsContextManager.getThreadContext().getOutputDirectory() + "_moved", "main-networkCapture.har").toFile();
        Assert.assertTrue(movedFile.exists());
        Assert.assertFalse(initialFile.exists());
        Assert.assertEquals(TestStepManager.getParentTestStep().getHarCaptures().get(0).getFile(), movedFile);
    } finally {
        FileUtils.deleteQuietly(new File(SeleniumTestsContextManager.getThreadContext().getOutputDirectory()));
        FileUtils.deleteQuietly(new File(SeleniumTestsContextManager.getThreadContext().getOutputDirectory() + "_moved"));
    }
}
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 4 with HarPage

use of net.lightbody.bmp.core.har.HarPage in project seleniumRobot by bhecquet.

the class TestTestLogging method testLogHarOk.

@Test(groups = { "ut" })
public void testLogHarOk() {
    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");
    Assert.assertFalse(TestStepManager.getParentTestStep().getHarCaptures().isEmpty());
    Assert.assertTrue(Paths.get(SeleniumTestsContextManager.getThreadContext().getOutputDirectory(), "main-networkCapture.har").toFile().exists());
}
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) Test(org.testng.annotations.Test) GenericTest(com.seleniumtests.GenericTest)

Example 5 with HarPage

use of net.lightbody.bmp.core.har.HarPage in project seleniumRobot by bhecquet.

the class TestTestStep method testTestStepEncodeXmlHarKept.

@Test(groups = { "ut" })
public void testTestStepEncodeXmlHarKept() throws IOException {
    Har har = new Har(new HarLog());
    har.getLog().addPage(new HarPage("title", "a title"));
    HarCapture cap = new HarCapture(har, "main");
    TestStep step = new TestStep("step1 \"'<>&", null, new ArrayList<>(), true);
    step.setHarCaptures(Arrays.asList(cap));
    TestStep encodedTestStep = step.encode("xml");
    Assert.assertEquals(encodedTestStep.getHarCaptures().get(0), cap);
}
Also used : TestStep(com.seleniumtests.reporter.logger.TestStep) HarLog(net.lightbody.bmp.core.har.HarLog) Har(net.lightbody.bmp.core.har.Har) HarCapture(com.seleniumtests.reporter.logger.HarCapture) HarPage(net.lightbody.bmp.core.har.HarPage) Test(org.testng.annotations.Test) GenericTest(com.seleniumtests.GenericTest)

Aggregations

GenericTest (com.seleniumtests.GenericTest)8 TestStep (com.seleniumtests.reporter.logger.TestStep)8 Har (net.lightbody.bmp.core.har.Har)8 HarLog (net.lightbody.bmp.core.har.HarLog)8 HarPage (net.lightbody.bmp.core.har.HarPage)8 Test (org.testng.annotations.Test)8 ArrayList (java.util.ArrayList)6 HarCapture (com.seleniumtests.reporter.logger.HarCapture)5 GenericFile (com.seleniumtests.reporter.logger.GenericFile)2 TestAction (com.seleniumtests.reporter.logger.TestAction)2 TestMessage (com.seleniumtests.reporter.logger.TestMessage)2 File (java.io.File)2 JSONObject (org.json.JSONObject)1