use of com.seleniumtests.reporter.logger.Snapshot 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();
}
use of com.seleniumtests.reporter.logger.Snapshot 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.reporter.logger.Snapshot 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.reporter.logger.Snapshot in project seleniumRobot by bhecquet.
the class TestTestNGResultUtil method testChangeTestResultWithSnapshot.
private void testChangeTestResultWithSnapshot(String snapshotName, SnapshotCheckType snapshotCheckType, SnapshotComparisonResult comparisonResult) throws IOException {
// create a step with snapshot that should be compared
TestStep step1 = new TestStep("step 1", Reporter.getCurrentTestResult(), new ArrayList<>(), true);
File tmpImg = File.createTempFile("img", "_with_very_very_very_long_name_to_be_shortened.png");
File tmpHtml = File.createTempFile("html", "_with_very_very_very_long_name_to_be_shortened.html");
ScreenShot screenshot = new ScreenShot();
screenshot.setImagePath("screenshot/" + tmpImg.getName());
screenshot.setHtmlSourcePath("htmls/" + tmpHtml.getName());
FileUtils.copyFile(tmpImg, new File(screenshot.getFullImagePath()));
FileUtils.copyFile(tmpHtml, new File(screenshot.getFullHtmlPath()));
step1.addSnapshot(new Snapshot(screenshot, snapshotName, snapshotCheckType), 1, null);
SeleniumTestsContext context = SeleniumTestsContextManager.getThreadContext();
context.getTestStepManager().logTestStep(step1);
when(testResult.getStatus()).thenReturn(ITestResult.SUCCESS);
when(testResult.getAttribute("testContext")).thenReturn(context);
// make this test successful, it will be changed to failed
List<ITestNGMethod> methods = new ArrayList<>();
methods.add(testNGMethod);
when(passedTests.getAllMethods()).thenReturn(methods);
// be sure we will do comparison
SeleniumTestsContextManager.getGlobalContext().setSeleniumRobotServerCompareSnapshotBehaviour("changeTestResult");
SeleniumTestsContextManager.getGlobalContext().setSeleniumRobotServerActive(true);
SeleniumTestsContextManager.getGlobalContext().setSeleniumRobotServerCompareSnapshot(true);
PowerMockito.when(SeleniumRobotSnapshotServerConnector.getInstance()).thenReturn(snapshotServerConnector);
when(snapshotServerConnector.checkSnapshotHasNoDifferences(any(Snapshot.class), anyString(), anyString())).thenReturn(comparisonResult);
TestNGResultUtils.changeTestResultWithSnapshotComparison(testResult);
}
Aggregations