use of com.seleniumtests.driver.screenshots.ScreenShot 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();
}
use of com.seleniumtests.driver.screenshots.ScreenShot 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();
}
use of com.seleniumtests.driver.screenshots.ScreenShot 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>");
}
use of com.seleniumtests.driver.screenshots.ScreenShot 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));
}
use of com.seleniumtests.driver.screenshots.ScreenShot in project seleniumRobot by bhecquet.
the class TestTestStep method testSnapshotInSubStep.
/**
* issue #409: Check that renaming takes into account the index of the parent
* step
*
* @throws IOException
*/
@Test(groups = { "ut" })
public void testSnapshotInSubStep() 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);
TestStep subStep = new TestStep("step1", null, new ArrayList<>(), true);
ScreenShot screenshotSubStep = new ScreenShot();
File tmpImgFileSubStep = File.createTempFile("img", ".png");
File tmpImgFileSubStep2 = Paths.get(tmpImgFileSubStep.getParent(), "screenshots", tmpImgFileSubStep.getName()).toFile();
FileUtils.moveFile(tmpImgFileSubStep, tmpImgFileSubStep2);
File tmpHtmlFileSubStep = File.createTempFile("html", ".html");
File tmpHtmlFileSubStep2 = Paths.get(tmpHtmlFileSubStep.getParent(), "htmls", tmpHtmlFileSubStep.getName()).toFile();
FileUtils.moveFile(tmpHtmlFileSubStep, tmpHtmlFileSubStep2);
screenshotSubStep.setOutputDirectory(tmpImgFileSubStep.getParent());
screenshotSubStep.setLocation("http://mysite.com");
screenshotSubStep.setTitle("mysite");
screenshotSubStep.setImagePath("screenshots/" + tmpImgFileSubStep2.getName());
screenshotSubStep.setHtmlSourcePath("htmls/" + tmpHtmlFileSubStep2.getName());
step.addStep(subStep);
subStep.addSnapshot(new Snapshot(screenshotSubStep, "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));
Assert.assertEquals(subStep.getSnapshots().get(0).getScreenshot().getImagePath(), "screenshots/N-A_0-11_step1--" + tmpImgFileSubStep2.getName().substring(tmpImgFileSubStep2.getName().length() - 10));
Assert.assertEquals(subStep.getSnapshots().get(0).getScreenshot().getHtmlSourcePath(), "htmls/N-A_0-11_step1--" + tmpHtmlFileSubStep2.getName().substring(tmpHtmlFileSubStep2.getName().length() - 10));
tmpImgFile.deleteOnExit();
tmpHtmlFile.deleteOnExit();
tmpImgFileSubStep.deleteOnExit();
tmpHtmlFileSubStep.deleteOnExit();
}
Aggregations