use of com.seleniumtests.driver.screenshots.ScreenShot in project seleniumRobot by bhecquet.
the class TestBrowserSnapshot method testCurrentWindowsCapture2.
/**
* Check that only main window is captured when no argument is given
*/
@Test(groups = { "it" })
public void testCurrentWindowsCapture2() {
DriverTestPage.link.click();
ScreenShot screenshot = new ScreenshotUtil(driver).capture(SnapshotTarget.PAGE, ScreenShot.class);
Assert.assertNotNull(screenshot.getImagePath());
}
use of com.seleniumtests.driver.screenshots.ScreenShot in project seleniumRobot by bhecquet.
the class TestHtmlUnitBrowserSnapshot method testHtmlUnitCapture.
/**
* Check no error is raised
*/
@Test(groups = { "it" })
public void testHtmlUnitCapture() {
ScreenshotUtil screenshotUtil = new ScreenshotUtil();
ScreenShot screenshot = screenshotUtil.capture(SnapshotTarget.PAGE, ScreenShot.class);
Assert.assertNull(screenshot.getImagePath());
}
use of com.seleniumtests.driver.screenshots.ScreenShot in project seleniumRobot by bhecquet.
the class TestSelectList2 method init.
@BeforeMethod(groups = { "ut" })
private void init() throws IOException {
SeleniumTestsContextManager.getGlobalContext().setCucumberImplementationPackage("com.seleniumtests.ut.core.runner.cucumber");
SeleniumTestsContextManager.getThreadContext().setBrowser("firefox");
SeleniumTestsContextManager.getThreadContext().setExplicitWaitTimeout(1);
SeleniumTestsContextManager.getThreadContext().setImplicitWaitTimeout(1);
SeleniumTestsContextManager.getThreadContext().setReplayTimeout(2);
eventDriver = spy(new CustomEventFiringWebDriver(driver));
when(eventDriver.switchTo()).thenReturn(target);
when(driver.findElement(By.id("select"))).thenReturn(element);
when(driver.navigate()).thenReturn(navigation);
when(driver.getCurrentUrl()).thenReturn("http://foo");
when(driver.manage()).thenReturn(driverOptions);
when(element.getTagName()).thenReturn("select");
when(driverOptions.timeouts()).thenReturn(timeouts);
when(element.getSize()).thenReturn(new Dimension(10, 10));
when(element.getLocation()).thenReturn(new Point(5, 5));
when(targetLocator.alert()).thenReturn(alert);
when(alert.getText()).thenReturn("alert text");
when(driver.switchTo()).thenReturn(targetLocator);
PowerMockito.mockStatic(WebUIDriver.class);
when(WebUIDriver.getCurrentWebUiDriverName()).thenReturn("main");
when(WebUIDriver.getWebDriver(anyBoolean(), eq(BrowserType.FIREFOX), eq("main"), isNull())).thenReturn(eventDriver);
when(WebUIDriver.getWebDriver(anyBoolean())).thenReturn(eventDriver);
when(eventDriver.executeScript("if (document.readyState === \"complete\") { return \"ok\"; }")).thenReturn("ok");
when(eventDriver.getBrowserInfo()).thenReturn(new BrowserInfo(BrowserType.FIREFOX, "78.0"));
when(screenshotUtil.capture(any(SnapshotTarget.class), ArgumentMatchers.<Class<ScreenShot>>any())).thenReturn(screenshot);
when(screenshot.getHtmlSourcePath()).thenReturn("foo");
}
use of com.seleniumtests.driver.screenshots.ScreenShot in project seleniumRobot by bhecquet.
the class TestTestStep method testMultipleSnapshotsInStep.
@Test(groups = { "ut" })
public void testMultipleSnapshotsInStep() 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);
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.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(step.getSnapshots().get(1).getScreenshot().getImagePath(), "screenshots/N-A_0-2_step1--" + tmpImgFileSubStep2.getName().substring(tmpImgFileSubStep2.getName().length() - 10));
Assert.assertEquals(step.getSnapshots().get(1).getScreenshot().getHtmlSourcePath(), "htmls/N-A_0-2_step1--" + tmpHtmlFileSubStep2.getName().substring(tmpHtmlFileSubStep2.getName().length() - 10));
tmpImgFile.deleteOnExit();
tmpHtmlFile.deleteOnExit();
tmpImgFileSubStep.deleteOnExit();
tmpHtmlFileSubStep.deleteOnExit();
}
use of com.seleniumtests.driver.screenshots.ScreenShot in project seleniumRobot by bhecquet.
the class TestTestStep method testSnapshotRenamingNoRandom.
/**
* Check case where random part of attachment is removed
* @throws IOException
*/
@Test(groups = { "ut" })
public void testSnapshotRenamingNoRandom() throws IOException {
SeleniumTestsContextManager.getThreadContext().setRandomInAttachmentNames(false);
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-.png");
Assert.assertEquals(step.getSnapshots().get(0).getScreenshot().getHtmlSourcePath(), "N-A_0-1_step1-.html");
tmpImgFile.deleteOnExit();
tmpHtmlFile.deleteOnExit();
}
Aggregations