use of com.seleniumtests.driver.screenshots.ScreenShot in project seleniumRobot by bhecquet.
the class TestBrowserSnapshot method testSnapshotWithErrors.
/**
* Test that if an unexpected error occurs when snapshot is taken, take desktop
* @throws Exception
*/
@Test(groups = { "it" })
public void testSnapshotWithErrors() throws Exception {
driver.switchTo().frame(DriverTestPage.iframe.getElement());
// get real capture
generateCaptureFilePath();
CustomEventFiringWebDriver mockedDriver = (CustomEventFiringWebDriver) spy(driver);
ScreenshotUtil screenshotUtil = spy(new ScreenshotUtil(mockedDriver));
doThrow(WebDriverException.class).when(mockedDriver).scrollTop();
doThrow(JavascriptException.class).when(mockedDriver).scrollTo(anyInt(), anyInt());
ScreenShot screenshot = screenshotUtil.capture(SnapshotTarget.PAGE, ScreenShot.class);
Assert.assertNotNull(screenshot.getHtmlSourcePath());
Assert.assertNotNull(screenshot.getFullImagePath());
}
use of com.seleniumtests.driver.screenshots.ScreenShot in project seleniumRobot by bhecquet.
the class TestBrowserSnapshot method testCurrentWindowsCapture.
/**
* Check that only main window is captured
*/
@Test(groups = { "it" })
public void testCurrentWindowsCapture() {
String currentWindowHandle = driver.getWindowHandle();
DriverTestPage.link.click();
List<ScreenShot> screenshots = new ScreenshotUtil(driver).capture(SnapshotTarget.PAGE, ScreenShot.class, false, false);
Assert.assertEquals(screenshots.size(), 1);
Assert.assertEquals(currentWindowHandle, driver.getWindowHandle());
}
use of com.seleniumtests.driver.screenshots.ScreenShot in project seleniumRobot by bhecquet.
the class TestScreenshotUtil method testDesktopScreenshots.
/**
* issue #300: check that desktop capture is done
* @param testContext
* @throws Exception
*/
@Test(groups = { "it" })
public void testDesktopScreenshots(ITestContext testContext) throws Exception {
SeleniumTestsContextManager.getThreadContext().setTestType(TestType.WEB);
ScreenShot screenshot = new ScreenshotUtil(null).capture(SnapshotTarget.SCREEN, ScreenShot.class);
Assert.assertTrue(new File(screenshot.getFullImagePath()).exists());
}
use of com.seleniumtests.driver.screenshots.ScreenShot in project seleniumRobot by bhecquet.
the class StubTestClass method testAndSubActions.
@Test(groups = "stub", description = "a test with steps")
public void testAndSubActions() throws IOException {
TestStep step1 = new TestStep("step 1", Reporter.getCurrentTestResult(), new ArrayList<>(), maskPassword);
step1.addAction(new TestAction("click button", false, new ArrayList<>()));
step1.addAction(new TestAction("sendKeys to text field", true, new ArrayList<>()));
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, "main", SnapshotCheckType.FULL), 1, null);
ScreenShot screenshot2 = new ScreenShot();
screenshot2.setImagePath("screenshot/" + tmpImg.getName());
screenshot2.setHtmlSourcePath("htmls/" + tmpHtml.getName());
FileUtils.moveFile(tmpImg, new File(screenshot2.getFullImagePath()));
FileUtils.moveFile(tmpHtml, new File(screenshot2.getFullHtmlPath()));
step1.addSnapshot(new Snapshot(screenshot2, null, SnapshotCheckType.FULL), 1, null);
step1.setActionException(new WebDriverException("driver exception"));
TestStep subStep1 = new TestStep("step 1.3: open page", Reporter.getCurrentTestResult(), new ArrayList<>(), maskPassword);
subStep1.addAction(new TestAction("click link", false, new ArrayList<>()));
subStep1.addMessage(new TestMessage("a message", MessageType.LOG));
subStep1.addAction(new TestAction("sendKeys to password field", false, new ArrayList<>()));
step1.addAction(subStep1);
WaitHelper.waitForSeconds(3);
step1.setDuration(1230L);
TestStep step2 = new TestStep("step 2", Reporter.getCurrentTestResult(), new ArrayList<>(), maskPassword);
step2.setDuration(14030L);
TestStepManager.logTestStep(step1);
TestStepManager.logTestStep(step2);
tmpImg.deleteOnExit();
tmpHtml.deleteOnExit();
}
use of com.seleniumtests.driver.screenshots.ScreenShot 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);
}
Aggregations