Search in sources :

Example 1 with ScreenShot

use of com.seleniumtests.driver.screenshots.ScreenShot in project seleniumRobot by bhecquet.

the class TestTestLogging method testBuildScreenshotStringWithoutLocation.

@Test(groups = { "ut" })
public void testBuildScreenshotStringWithoutLocation() {
    ScreenShot screenshot = new ScreenShot();
    screenshot.setTitle("title");
    screenshot.setHtmlSourcePath("file.html");
    screenshot.setImagePath("file.png");
    Snapshot snapshotLogger = new Snapshot(screenshot, "main", SnapshotCheckType.TRUE);
    String screenshotStr = snapshotLogger.buildScreenshotLog().replace("\n", "").replaceAll(">\\s+<", "><");
    Matcher matcher = Pattern.compile(".*<img id\\=\"(.+)\" src\\=.*").matcher(screenshotStr);
    String imageId = "";
    if (matcher.matches()) {
        imageId = matcher.group(1);
    } else {
        throw new IndexOutOfBoundsException("no match");
    }
    Assert.assertEquals(screenshotStr, String.format("<div class=\"text-center\">" + "<a href=\"#\" onclick=\"$('#imagepreview').attr('src', $('#%s').attr('src'));$('#imagemodal').modal('show');\">" + "<img id=\"%s\" src=\"file.png\" style=\"width: 300px\">" + "</a>" + "</div>" + "<div class=\"text-center\">main: title</div>" + "<div class=\"text-center font-weight-lighter\"> | <a href='file.html' target=html>HTML Source</a></div>", imageId, imageId));
}
Also used : Snapshot(com.seleniumtests.reporter.logger.Snapshot) Matcher(java.util.regex.Matcher) ScreenShot(com.seleniumtests.driver.screenshots.ScreenShot) Test(org.testng.annotations.Test) GenericTest(com.seleniumtests.GenericTest)

Example 2 with ScreenShot

use of com.seleniumtests.driver.screenshots.ScreenShot 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 3 with ScreenShot

use of com.seleniumtests.driver.screenshots.ScreenShot in project seleniumRobot by bhecquet.

the class TestTestLogging method testBuildScreenshotStringWithoutInfo.

@Test(groups = { "ut" })
public void testBuildScreenshotStringWithoutInfo() {
    ScreenShot screenshot = new ScreenShot();
    Snapshot snapshotLogger = new Snapshot(screenshot, "main", SnapshotCheckType.FALSE);
    String screenshotStr = snapshotLogger.buildScreenshotLog().replace("\n", "");
    Assert.assertEquals(screenshotStr, "<div class=\"text-center\">main</div>" + "<div class=\"text-center font-weight-lighter\"></div>");
}
Also used : Snapshot(com.seleniumtests.reporter.logger.Snapshot) ScreenShot(com.seleniumtests.driver.screenshots.ScreenShot) Test(org.testng.annotations.Test) GenericTest(com.seleniumtests.GenericTest)

Example 4 with ScreenShot

use of com.seleniumtests.driver.screenshots.ScreenShot 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)

Example 5 with ScreenShot

use of com.seleniumtests.driver.screenshots.ScreenShot in project seleniumRobot by bhecquet.

the class TestTestLogging method testRelocateScreenshotImageOnly.

/**
 * Check image file is moved
 * @throws IOException
 */
@Test(groups = { "ut" })
public void testRelocateScreenshotImageOnly() 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(), "");
        // relocate
        TestStepManager.getParentTestStep().getSnapshots().get(0).relocate(SeleniumTestsContextManager.getThreadContext().getOutputDirectory() + "_moved");
        File movedFile = Paths.get(SeleniumTestsContextManager.getThreadContext().getOutputDirectory() + "_moved", ScreenshotUtil.SCREENSHOT_DIR, "N-A_0-1_step--apture.png").toFile();
        Assert.assertTrue(movedFile.exists());
        Assert.assertFalse(initialFile.exists());
        Assert.assertEquals(new File(TestStepManager.getParentTestStep().getSnapshots().get(0).getScreenshot().getFullImagePath()), 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) ScreenShot(com.seleniumtests.driver.screenshots.ScreenShot) ArrayList(java.util.ArrayList) File(java.io.File) Test(org.testng.annotations.Test) GenericTest(com.seleniumtests.GenericTest)

Aggregations

ScreenShot (com.seleniumtests.driver.screenshots.ScreenShot)63 Test (org.testng.annotations.Test)45 File (java.io.File)37 GenericTest (com.seleniumtests.GenericTest)35 Snapshot (com.seleniumtests.reporter.logger.Snapshot)24 TestStep (com.seleniumtests.reporter.logger.TestStep)24 ArrayList (java.util.ArrayList)14 ScreenshotUtil (com.seleniumtests.driver.screenshots.ScreenshotUtil)10 GenericFile (com.seleniumtests.reporter.logger.GenericFile)8 GenericMultiBrowserTest (com.seleniumtests.it.driver.support.GenericMultiBrowserTest)6 BeforeMethod (org.testng.annotations.BeforeMethod)6 CustomEventFiringWebDriver (com.seleniumtests.driver.CustomEventFiringWebDriver)5 TestAction (com.seleniumtests.reporter.logger.TestAction)5 BrowserInfo (com.seleniumtests.browserfactory.BrowserInfo)3 BasicIssue (com.atlassian.jira.rest.client.api.domain.BasicIssue)2 User (com.atlassian.jira.rest.client.api.domain.User)2 IssueInput (com.atlassian.jira.rest.client.api.domain.input.IssueInput)2 ConfigurationException (com.seleniumtests.customexception.ConfigurationException)2 ScenarioException (com.seleniumtests.customexception.ScenarioException)2 SnapshotTarget (com.seleniumtests.driver.screenshots.SnapshotTarget)2