Search in sources :

Example 21 with Snapshot

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

the class TestErrorCauseFinder method init.

@BeforeMethod(alwaysRun = true)
public void init() throws Exception {
    step1 = new TestStep("step 1", Reporter.getCurrentTestResult(), new ArrayList<>(), false);
    step1.setStepResultId(0);
    step1.setPosition(0);
    File image = GenericTest.createFileFromResource("tu/images/driverTestPage.png");
    imgStep1Ref = File.createTempFile("img", ".png");
    imgStep1 = File.createTempFile("img", ".png");
    File tmpHtml = File.createTempFile("html", ".html");
    ScreenShot screenshot = new ScreenShot();
    screenshot.setImagePath("screenshot/" + imgStep1Ref.getName());
    screenshot.setHtmlSourcePath("htmls/" + tmpHtml.getName());
    FileUtils.copyFile(imgStep1Ref, new File(screenshot.getFullImagePath()));
    FileUtils.copyFile(tmpHtml, new File(screenshot.getFullHtmlPath()));
    step1.addSnapshot(new Snapshot(screenshot, null, SnapshotCheckType.REFERENCE_ONLY), 1, null);
    ScreenShot screenshot2 = new ScreenShot();
    screenshot2.setImagePath("screenshot/" + imgStep1.getName());
    screenshot2.setHtmlSourcePath("htmls/" + tmpHtml.getName());
    FileUtils.copyFile(imgStep1, new File(screenshot.getFullImagePath()));
    FileUtils.copyFile(tmpHtml, new File(screenshot.getFullHtmlPath()));
    step1.addSnapshot(new Snapshot(screenshot2, null, SnapshotCheckType.FALSE), 1, null);
    stepFailed = new TestStep("step 2", Reporter.getCurrentTestResult(), new ArrayList<>(), false);
    stepFailed.setStepResultId(1);
    stepFailed.setFailed(true);
    stepFailed.setPosition(1);
    imgStep2Ref = File.createTempFile("img", ".png");
    ScreenShot screenshot3 = new ScreenShot();
    screenshot3.setImagePath("screenshot/" + imgStep2Ref.getName());
    screenshot3.setHtmlSourcePath("htmls/" + tmpHtml.getName());
    FileUtils.copyFile(imgStep2Ref, new File(screenshot3.getFullImagePath()));
    FileUtils.copyFile(tmpHtml, new File(screenshot3.getFullHtmlPath()));
    stepFailed.addSnapshot(new Snapshot(screenshot3, null, SnapshotCheckType.REFERENCE_ONLY), 1, null);
    lastStep = new TestStep(TestStepManager.LAST_STEP_NAME, Reporter.getCurrentTestResult(), new ArrayList<>(), false);
    lastStep.setPosition(2);
    imgLastStep = File.createTempFile("img", ".png");
    File tmpHtml2 = File.createTempFile("html", ".html");
    ScreenShot screenshot4 = new ScreenShot();
    screenshot4.setImagePath("screenshot/" + imgStep1.getName());
    screenshot4.setHtmlSourcePath("htmls/" + tmpHtml.getName());
    FileUtils.copyFile(imgLastStep, new File(screenshot4.getFullImagePath()));
    FileUtils.copyFile(tmpHtml2, new File(screenshot4.getFullHtmlPath()));
    lastStep.addSnapshot(new Snapshot(screenshot4, "main", SnapshotCheckType.FALSE), 1, null);
    lastStep.setStepResultId(10);
    PowerMockito.mockStatic(SeleniumRobotSnapshotServerConnector.class);
    PowerMockito.when(SeleniumRobotSnapshotServerConnector.getInstance()).thenReturn(serverConnector);
    // reference image for step 1
    referenceImgStep1 = File.createTempFile("img", ".png");
    FileUtils.copyFile(image, referenceImgStep1);
    // reference image for step 2
    referenceImgStep2 = File.createTempFile("img", ".png");
    FileUtils.copyFile(image, referenceImgStep2);
    when(serverConnector.getReferenceSnapshot(0)).thenReturn(referenceImgStep1);
    when(serverConnector.getReferenceSnapshot(1)).thenReturn(referenceImgStep2);
}
Also used : TestStep(com.seleniumtests.reporter.logger.TestStep) Snapshot(com.seleniumtests.reporter.logger.Snapshot) ScreenShot(com.seleniumtests.driver.screenshots.ScreenShot) ArrayList(java.util.ArrayList) File(java.io.File) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 22 with Snapshot

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

the class TestTestStep method testSnapshotRenamingWithSubFolder.

@Test(groups = { "ut" })
public void testSnapshotRenamingWithSubFolder() throws IOException {
    TestStep step = new TestStep("step1", null, new ArrayList<>(), true);
    ScreenShot screenshot = new ScreenShot();
    File tmpImgFile = File.createTempFile("img", ".png");
    File tmpImgFile2 = Paths.get(tmpImgFile.getParent(), "screenshots", tmpImgFile.getName()).toFile();
    FileUtils.moveFile(tmpImgFile, tmpImgFile2);
    File tmpHtmlFile = File.createTempFile("html", ".html");
    File tmpHtmlFile2 = Paths.get(tmpHtmlFile.getParent(), "htmls", tmpHtmlFile.getName()).toFile();
    FileUtils.moveFile(tmpHtmlFile, tmpHtmlFile2);
    screenshot.setOutputDirectory(tmpImgFile.getParent());
    screenshot.setLocation("http://mysite.com");
    screenshot.setTitle("mysite");
    screenshot.setImagePath("screenshots/" + tmpImgFile2.getName());
    screenshot.setHtmlSourcePath("htmls/" + tmpHtmlFile2.getName());
    step.addSnapshot(new Snapshot(screenshot, "main", SnapshotCheckType.TRUE), 0, null);
    Assert.assertEquals(step.getSnapshots().get(0).getScreenshot().getImagePath(), "screenshots/N-A_0-1_step1--" + tmpImgFile2.getName().substring(tmpImgFile2.getName().length() - 10));
    Assert.assertEquals(step.getSnapshots().get(0).getScreenshot().getHtmlSourcePath(), "htmls/N-A_0-1_step1--" + tmpHtmlFile2.getName().substring(tmpHtmlFile2.getName().length() - 10));
    tmpImgFile.deleteOnExit();
    tmpHtmlFile.deleteOnExit();
}
Also used : TestStep(com.seleniumtests.reporter.logger.TestStep) Snapshot(com.seleniumtests.reporter.logger.Snapshot) ScreenShot(com.seleniumtests.driver.screenshots.ScreenShot) File(java.io.File) GenericFile(com.seleniumtests.reporter.logger.GenericFile) Test(org.testng.annotations.Test) GenericTest(com.seleniumtests.GenericTest)

Example 23 with Snapshot

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

the class TestTestStep method testSnapshotRenamingWithCustomName.

/**
 * Test that when adding a snapshot to a test step, with a custom name, it's
 * renamed with this custom name Custom name contains forbidden characters
 *
 * @throws IOException
 */
@Test(groups = { "ut" })
public void testSnapshotRenamingWithCustomName() throws IOException {
    TestStep step = new TestStep("step1", null, new ArrayList<>(), true);
    ScreenShot screenshot = new ScreenShot();
    File tmpImgFile = File.createTempFile("img", ".png");
    File tmpHtmlFile = File.createTempFile("html", ".html");
    screenshot.setOutputDirectory(tmpImgFile.getParent());
    screenshot.setLocation("http://mysite.com");
    screenshot.setTitle("mysite");
    screenshot.setImagePath(tmpImgFile.getName());
    screenshot.setHtmlSourcePath(tmpHtmlFile.getName());
    step.addSnapshot(new Snapshot(screenshot, "main", SnapshotCheckType.FALSE), 0, "my snapshot <name>");
    Assert.assertEquals(step.getSnapshots().get(0).getScreenshot().getImagePath(), "my_snapshot_-name--" + tmpImgFile.getName().substring(tmpImgFile.getName().length() - 10));
    Assert.assertEquals(step.getSnapshots().get(0).getScreenshot().getHtmlSourcePath(), "my_snapshot_-name--" + tmpHtmlFile.getName().substring(tmpHtmlFile.getName().length() - 10));
    tmpImgFile.deleteOnExit();
    tmpHtmlFile.deleteOnExit();
}
Also used : TestStep(com.seleniumtests.reporter.logger.TestStep) Snapshot(com.seleniumtests.reporter.logger.Snapshot) ScreenShot(com.seleniumtests.driver.screenshots.ScreenShot) File(java.io.File) GenericFile(com.seleniumtests.reporter.logger.GenericFile) Test(org.testng.annotations.Test) GenericTest(com.seleniumtests.GenericTest)

Example 24 with Snapshot

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

the class TestTestLogging method testBuildScreenshotStringWithoutImage.

@Test(groups = { "ut" })
public void testBuildScreenshotStringWithoutImage() {
    ScreenShot screenshot = new ScreenShot();
    screenshot.setTitle("title");
    screenshot.setLocation("http://location");
    screenshot.setHtmlSourcePath("file.html");
    Snapshot snapshotLogger = new Snapshot(screenshot, "main", SnapshotCheckType.TRUE);
    String screenshotStr = snapshotLogger.buildScreenshotLog().replace("\n", "").replaceAll(">\\s+<", "><");
    Assert.assertEquals(screenshotStr, "<div class=\"text-center\">main: title</div><div class=\"text-center font-weight-lighter\"><a href='http://location' target=url>URL</a> | <a href='file.html' target=html>HTML Source</a></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 25 with Snapshot

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

the class TestTestLogging method testBuildScreenshotString.

@Test(groups = { "ut" })
public void testBuildScreenshotString() {
    ScreenShot screenshot = new ScreenShot();
    screenshot.setTitle("title");
    screenshot.setLocation("http://location");
    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='http://location' target=url>URL</a> | <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)

Aggregations

Snapshot (com.seleniumtests.reporter.logger.Snapshot)29 ScreenShot (com.seleniumtests.driver.screenshots.ScreenShot)23 TestStep (com.seleniumtests.reporter.logger.TestStep)22 File (java.io.File)18 Test (org.testng.annotations.Test)18 GenericTest (com.seleniumtests.GenericTest)15 ArrayList (java.util.ArrayList)11 GenericFile (com.seleniumtests.reporter.logger.GenericFile)8 TestAction (com.seleniumtests.reporter.logger.TestAction)5 SeleniumRobotServerException (com.seleniumtests.customexception.SeleniumRobotServerException)4 BeforeMethod (org.testng.annotations.BeforeMethod)4 Matcher (java.util.regex.Matcher)3 Field (com.seleniumtests.connectors.selenium.fielddetector.Field)2 Label (com.seleniumtests.connectors.selenium.fielddetector.Label)2 ConfigurationException (com.seleniumtests.customexception.ConfigurationException)2 IOException (java.io.IOException)2 Path (java.nio.file.Path)2 HashMap (java.util.HashMap)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 Rectangle (org.openqa.selenium.Rectangle)2