use of com.seleniumtests.driver.screenshots.ScreenShot in project seleniumRobot by bhecquet.
the class TestTestStep method testListAllAttachments.
/**
* Check we get all files from a step and its sub steps
*
* @throws IOException
*/
@Test(groups = { "ut" })
public void testListAllAttachments() throws IOException {
TestStep step = new TestStep("step1", null, new ArrayList<>(), true);
// create screenshot for main step
ScreenShot screenshot1 = 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);
tmpImgFile.deleteOnExit();
tmpHtmlFile.deleteOnExit();
screenshot1.setOutputDirectory(tmpImgFile.getParent());
screenshot1.setLocation("http://mysite.com");
screenshot1.setTitle("mysite");
screenshot1.setImagePath("screenshots/" + tmpImgFile2.getName());
screenshot1.setHtmlSourcePath("htmls/" + tmpHtmlFile2.getName());
step.addSnapshot(new Snapshot(screenshot1, "main", SnapshotCheckType.FALSE), 0, null);
TestStep subStep = new TestStep("subStep", null, new ArrayList<>(), true);
// create screenshot for sub step
ScreenShot screenshot2 = new ScreenShot();
File tmpImgFile3 = File.createTempFile("img", ".png");
File tmpImgFile4 = Paths.get(tmpImgFile3.getParent(), "screenshots", tmpImgFile3.getName()).toFile();
FileUtils.moveFile(tmpImgFile3, tmpImgFile4);
screenshot2.setOutputDirectory(tmpImgFile3.getParent());
screenshot2.setLocation("http://mysite.com");
screenshot2.setTitle("mysite");
screenshot2.setImagePath("screenshots/" + tmpImgFile4.getName());
subStep.addSnapshot(new Snapshot(screenshot2, "main", SnapshotCheckType.TRUE), 0, null);
subStep.addAction(new TestAction("action1", true, new ArrayList<>()));
step.addAction(new TestAction("action2", false, new ArrayList<>()));
step.addAction(subStep);
List<File> attachments = step.getAllAttachments();
Assert.assertEquals(attachments.size(), 3);
Assert.assertEquals(attachments.get(0).getName(), "N-A_0-1_step1--" + tmpHtmlFile2.getName().substring(tmpHtmlFile2.getName().length() - 10));
Assert.assertEquals(attachments.get(1).getName(), "N-A_0-1_step1--" + tmpImgFile2.getName().substring(tmpImgFile2.getName().length() - 10));
Assert.assertEquals(attachments.get(2).getName(), "N-A_0-1_subStep--" + tmpImgFile4.getName().substring(tmpImgFile4.getName().length() - 10));
}
use of com.seleniumtests.driver.screenshots.ScreenShot in project seleniumRobot by bhecquet.
the class TestTestStep method testDurationWithSnapshot.
@Test(groups = { "ut" })
public void testDurationWithSnapshot() {
TestStep step = new TestStep("step1", null, new ArrayList<>(), true);
step.setDuration(5000L);
step.setDurationToExclude(500L);
ScreenShot screenshot = new ScreenShot();
screenshot.setDuration(200);
Snapshot snapshot = new Snapshot(screenshot, "main", SnapshotCheckType.TRUE);
step.addSnapshot(snapshot, 0, "name");
Assert.assertEquals(step.getDuration(), (Long) 4300L);
}
use of com.seleniumtests.driver.screenshots.ScreenShot in project seleniumRobot by bhecquet.
the class TestScreenshot method testGetImageNameNull.
@Test(groups = { "ut" })
public void testGetImageNameNull() {
ScreenShot s = new ScreenShot(null);
Assert.assertEquals(s.getImageName(), "");
}
use of com.seleniumtests.driver.screenshots.ScreenShot in project seleniumRobot by bhecquet.
the class TestScreenshot method testRelocateExistingHtmlFile.
/**
* Check no error is raised if file already exists
* @throws IOException
*/
@Test(groups = { "ut" })
public void testRelocateExistingHtmlFile() throws IOException {
FileUtils.deleteDirectory(new File(SeleniumTestsContextManager.getThreadContext().getOutputDirectory()));
FileUtils.deleteDirectory(Paths.get(SeleniumTestsContextManager.getThreadContext().getDefaultOutputDirectory(), "out").toFile());
FileUtils.copyFile(createFileFromResource("tu/test.html"), Paths.get(SeleniumTestsContextManager.getThreadContext().getOutputDirectory(), ScreenshotUtil.HTML_DIR, "foo.html").toFile());
FileUtils.copyFile(createFileFromResource("tu/test.html"), Paths.get(SeleniumTestsContextManager.getThreadContext().getDefaultOutputDirectory(), "out", ScreenshotUtil.HTML_DIR, "foo.html").toFile());
ScreenShot s = new ScreenShot();
s.setHtmlSourcePath(ScreenshotUtil.HTML_DIR + "/foo.html");
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 testGetFullHtmlPath.
@Test(groups = { "ut" })
public void testGetFullHtmlPath() {
ScreenShot s = new ScreenShot("foo.jpg");
s.setHtmlSourcePath("foo.html");
Assert.assertEquals(s.getFullHtmlPath(), SeleniumTestsContextManager.getThreadContext().getOutputDirectory() + "/foo.html");
}
Aggregations