use of com.seleniumtests.driver.screenshots.ScreenShot in project seleniumRobot by bhecquet.
the class TestTestLogging method testBuildScreenshotStringWithoutSource.
@Test(groups = { "ut" })
public void testBuildScreenshotStringWithoutSource() {
ScreenShot screenshot = new ScreenShot();
screenshot.setTitle("title");
screenshot.setLocation("http://location");
screenshot.setImagePath("file.png");
Snapshot snapshotLogger = new Snapshot(screenshot, "main", SnapshotCheckType.FALSE);
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></div>", imageId, imageId));
}
use of com.seleniumtests.driver.screenshots.ScreenShot in project seleniumRobot by bhecquet.
the class TestTestLogging method testRelocateScreenshotHtmlOnly.
/**
* Check HTML page is moved
* @throws IOException
*/
@Test(groups = { "ut" })
public void testRelocateScreenshotHtmlOnly() throws IOException {
try {
TestStepManager.setCurrentRootTestStep(new TestStep("step", null, new ArrayList<>(), true));
ScreenShot screenshot = new ScreenShot();
String htmlSourcePath = Paths.get(SeleniumTestsContextManager.getThreadContext().getOutputDirectory(), ScreenshotUtil.HTML_DIR, "capture.html").toString();
FileUtils.write(new File(htmlSourcePath), "<html>");
// copied from ScreeshotUtils class
screenshot.setHtmlSourcePath(String.format("../%s/%s/%s.html", "testRelocateScreenshotHtmlOnly", ScreenshotUtil.HTML_DIR, "capture"));
logger.logScreenshot(screenshot);
File initialFile = new File(TestStepManager.getParentTestStep().getSnapshots().get(0).getScreenshot().getFullHtmlPath());
// file exists before moving
Assert.assertTrue(initialFile.exists());
Assert.assertNull(TestStepManager.getParentTestStep().getSnapshots().get(0).getScreenshot().getImagePath());
// relocate
TestStepManager.getParentTestStep().getSnapshots().get(0).relocate(SeleniumTestsContextManager.getThreadContext().getOutputDirectory() + "_moved");
File movedFile = Paths.get(SeleniumTestsContextManager.getThreadContext().getOutputDirectory() + "_moved", ScreenshotUtil.HTML_DIR, "N-A_0-1_step--pture.html").toFile();
Assert.assertTrue(movedFile.exists());
Assert.assertFalse(initialFile.exists());
Assert.assertEquals(new File(TestStepManager.getParentTestStep().getSnapshots().get(0).getScreenshot().getFullHtmlPath()), movedFile);
} finally {
FileUtils.deleteQuietly(new File(SeleniumTestsContextManager.getThreadContext().getOutputDirectory()));
FileUtils.deleteQuietly(new File(SeleniumTestsContextManager.getThreadContext().getOutputDirectory() + "_moved"));
}
}
use of com.seleniumtests.driver.screenshots.ScreenShot in project seleniumRobot by bhecquet.
the class TestTestStep method testSnapshotRenaming.
/**
* Test that when adding a snapshot to a test step, it's renamed with a name
* containing test name, step name and index
*
* @throws IOException
*/
@Test(groups = { "ut" })
public void testSnapshotRenaming() 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.TRUE), 0, null);
Assert.assertEquals(step.getSnapshots().get(0).getScreenshot().getImagePath(), "N-A_0-1_step1--" + tmpImgFile.getName().substring(tmpImgFile.getName().length() - 10));
Assert.assertEquals(step.getSnapshots().get(0).getScreenshot().getHtmlSourcePath(), "N-A_0-1_step1--" + 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 TestScreenshot method testRelocateNonExistingFile.
@Test(groups = { "ut" })
public void testRelocateNonExistingFile() throws IOException {
FileUtils.deleteDirectory(new File(SeleniumTestsContextManager.getThreadContext().getOutputDirectory()));
FileUtils.deleteDirectory(Paths.get(SeleniumTestsContextManager.getThreadContext().getDefaultOutputDirectory(), "out").toFile());
ScreenShot s = new ScreenShot(ScreenshotUtil.SCREENSHOT_DIR + "/foo.jpg");
s.relocate(Paths.get(SeleniumTestsContextManager.getThreadContext().getDefaultOutputDirectory(), "out").toString());
}
use of com.seleniumtests.driver.screenshots.ScreenShot in project seleniumRobot by bhecquet.
the class TestScreenshot method testGetHtmlSourceNonExistentFile.
@Test(groups = { "ut" })
public void testGetHtmlSourceNonExistentFile() throws IOException {
ScreenShot s = new ScreenShot();
s.setHtmlSourcePath(ScreenshotUtil.HTML_DIR + "/foo.html");
Assert.assertEquals(s.getHtmlSource(), "");
}
Aggregations