Search in sources :

Example 21 with ScreenShot

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());
}
Also used : ScreenShot(com.seleniumtests.driver.screenshots.ScreenShot) ScreenshotUtil(com.seleniumtests.driver.screenshots.ScreenshotUtil) Test(org.testng.annotations.Test) GenericMultiBrowserTest(com.seleniumtests.it.driver.support.GenericMultiBrowserTest)

Example 22 with ScreenShot

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());
}
Also used : ScreenShot(com.seleniumtests.driver.screenshots.ScreenShot) ScreenshotUtil(com.seleniumtests.driver.screenshots.ScreenshotUtil) MockitoTest(com.seleniumtests.MockitoTest) Test(org.testng.annotations.Test)

Example 23 with ScreenShot

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");
}
Also used : CustomEventFiringWebDriver(com.seleniumtests.driver.CustomEventFiringWebDriver) SnapshotTarget(com.seleniumtests.driver.screenshots.SnapshotTarget) ScreenShot(com.seleniumtests.driver.screenshots.ScreenShot) BrowserInfo(com.seleniumtests.browserfactory.BrowserInfo) Dimension(org.openqa.selenium.Dimension) Point(org.openqa.selenium.Point) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 24 with ScreenShot

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();
}
Also used : TestStep(com.seleniumtests.reporter.logger.TestStep) Snapshot(com.seleniumtests.reporter.logger.Snapshot) ScreenShot(com.seleniumtests.driver.screenshots.ScreenShot) File(java.io.File) GenericFile(com.seleniumtests.reporter.logger.GenericFile) Test(org.testng.annotations.Test) GenericTest(com.seleniumtests.GenericTest)

Example 25 with ScreenShot

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();
}
Also used : TestStep(com.seleniumtests.reporter.logger.TestStep) Snapshot(com.seleniumtests.reporter.logger.Snapshot) ScreenShot(com.seleniumtests.driver.screenshots.ScreenShot) File(java.io.File) GenericFile(com.seleniumtests.reporter.logger.GenericFile) Test(org.testng.annotations.Test) GenericTest(com.seleniumtests.GenericTest)

Aggregations

ScreenShot (com.seleniumtests.driver.screenshots.ScreenShot)63 Test (org.testng.annotations.Test)45 File (java.io.File)37 GenericTest (com.seleniumtests.GenericTest)35 Snapshot (com.seleniumtests.reporter.logger.Snapshot)24 TestStep (com.seleniumtests.reporter.logger.TestStep)24 ArrayList (java.util.ArrayList)14 ScreenshotUtil (com.seleniumtests.driver.screenshots.ScreenshotUtil)10 GenericFile (com.seleniumtests.reporter.logger.GenericFile)8 GenericMultiBrowserTest (com.seleniumtests.it.driver.support.GenericMultiBrowserTest)6 BeforeMethod (org.testng.annotations.BeforeMethod)6 CustomEventFiringWebDriver (com.seleniumtests.driver.CustomEventFiringWebDriver)5 TestAction (com.seleniumtests.reporter.logger.TestAction)5 BrowserInfo (com.seleniumtests.browserfactory.BrowserInfo)3 BasicIssue (com.atlassian.jira.rest.client.api.domain.BasicIssue)2 User (com.atlassian.jira.rest.client.api.domain.User)2 IssueInput (com.atlassian.jira.rest.client.api.domain.input.IssueInput)2 ConfigurationException (com.seleniumtests.customexception.ConfigurationException)2 ScenarioException (com.seleniumtests.customexception.ScenarioException)2 SnapshotTarget (com.seleniumtests.driver.screenshots.SnapshotTarget)2