use of com.seleniumtests.driver.screenshots.ScreenShot in project seleniumRobot by bhecquet.
the class WebUIDriver method logFinalDriverState.
/**
* Logs current state of the browser
*/
private void logFinalDriverState(ITestResult testResult) {
if (driver != null) {
try {
// issue #414: capture the whole screen
driver.switchTo().defaultContent();
// force screenshotUtil to use the driver of this WebUiDriver, not the currently selected one
for (ScreenShot screenshot : new ScreenshotUtil(driver).capture(SnapshotTarget.PAGE, ScreenShot.class, true, true)) {
scenarioLogger.logScreenshot(screenshot, null, name, SnapshotCheckType.FALSE);
// add the last screenshots to TestInfo so that there is a quicklink on reports
Info lastStateInfo = TestNGResultUtils.getTestInfo(testResult).get(TestStepManager.LAST_STATE_NAME);
if (lastStateInfo != null) {
((MultipleInfo) lastStateInfo).addInfo(new ImageLinkInfo(TestNGResultUtils.getUniqueTestName(testResult) + "/" + screenshot.getImagePath()));
}
}
} catch (Exception e) {
scenarioLogger.log("Error while logging: " + e.getMessage());
}
}
try {
// stop HAR capture
if (config.getBrowserMobProxy() != null) {
Har har = config.getBrowserMobProxy().endHar();
scenarioLogger.logNetworkCapture(har, name);
}
} catch (Exception e) {
scenarioLogger.log("Error while logging: " + e.getMessage());
} finally {
config.setBrowserMobProxy(null);
}
}
use of com.seleniumtests.driver.screenshots.ScreenShot in project seleniumRobot by bhecquet.
the class TestJiraConnector method init.
@BeforeMethod(groups = { "no-ti" })
public void init() throws IOException {
File tmpImg = File.createTempFile("img", ".png");
File tmpHtml = File.createTempFile("html", ".html");
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 = new TestStep("step 1", null, new ArrayList<>(), false);
step1.addSnapshot(new Snapshot(screenshot, "main", SnapshotCheckType.FULL), 1, null);
step2 = new TestStep("step 2", null, new ArrayList<>(), false);
step2.setFailed(true);
step2.addAction(new TestAction("action1", false, new ArrayList<>()));
step2.addAction(new TestAction("action2", false, new ArrayList<>()));
step2.addSnapshot(new Snapshot(screenshot, "main", SnapshotCheckType.FULL), 1, null);
stepEnd = new TestStep("Test end", null, new ArrayList<>(), false);
stepEnd.addSnapshot(new Snapshot(screenshot, "end", SnapshotCheckType.FULL), 1, null);
stepEnd.addSnapshot(new Snapshot(screenshot, "end2", SnapshotCheckType.FULL), 1, null);
}
use of com.seleniumtests.driver.screenshots.ScreenShot in project seleniumRobot by bhecquet.
the class TestSeleniumRobotSnapshotServerConnector method testCreateSnapshot.
/**
* create a snapshot
* @throws IOException
*/
@Test(groups = { "it" })
public void testCreateSnapshot() throws IOException {
Integer sessionId = connector.createSession("Session1");
Integer testCaseId = connector.createTestCase("Test 2");
Integer testCaseInSessionId = connector.createTestCaseInSession(sessionId, testCaseId, "Test 2");
Integer testStepId = connector.createTestStep("Step 1", testCaseInSessionId);
Integer stepResultId = connector.recordStepResult(true, "logs", 1, sessionId, testCaseInSessionId, testStepId);
File image = Paths.get(SeleniumTestsContextManager.getThreadContext().getOutputDirectory(), "img.png").toFile();
image.deleteOnExit();
FileUtils.copyInputStreamToFile(getClass().getClassLoader().getResourceAsStream("tu/images/ffLogoConcat.png"), image);
ScreenShot screenshot = new ScreenShot();
screenshot.setImagePath(image.getName());
Snapshot snapshot = new Snapshot(screenshot, "img", SnapshotCheckType.TRUE);
Integer snapshotId = connector.createSnapshot(snapshot, sessionId, testCaseInSessionId, stepResultId);
Assert.assertNotNull(snapshotId);
}
use of com.seleniumtests.driver.screenshots.ScreenShot in project seleniumRobot by bhecquet.
the class TestBrowserSnapshot method testSnapshotWithJavascriptErrors.
/**
* issue #272: Test taking snapshot inside an iframe when some javascript error occurs. This happens with some website where access to iframe seems denied
* We want to get source and title, even if picture is not get
* @throws Exception
*/
@Test(groups = { "it" })
public void testSnapshotWithJavascriptErrors() throws Exception {
driver.switchTo().frame(DriverTestPage.iframe.getElement());
// get real capture
generateCaptureFilePath();
CustomEventFiringWebDriver mockedDriver = (CustomEventFiringWebDriver) spy(driver);
ScreenshotUtil screenshotUtil = spy(new ScreenshotUtil(mockedDriver));
doThrow(JavascriptException.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 testMultipleWindowsCaptureWithError.
/**
* Check that when an error occurs when communicating with driver, a desktop capture is taken
*/
@Test(groups = { "it" })
public void testMultipleWindowsCaptureWithError() {
DriverTestPage.link.click();
WebDriver mockedDriver = spy(driver);
ScreenshotUtil screenshotUtil = spy(new ScreenshotUtil(mockedDriver));
when(mockedDriver.getWindowHandles()).thenThrow(WebDriverException.class);
List<ScreenShot> screenshots = screenshotUtil.capture(SnapshotTarget.PAGE, ScreenShot.class, true, false);
Assert.assertEquals(screenshots.size(), 1);
verify(screenshotUtil).captureDesktop();
}
Aggregations