Search in sources :

Example 41 with ScreenShot

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());
}
Also used : CustomEventFiringWebDriver(com.seleniumtests.driver.CustomEventFiringWebDriver) 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 42 with ScreenShot

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());
}
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 43 with ScreenShot

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());
}
Also used : ScreenShot(com.seleniumtests.driver.screenshots.ScreenShot) ScreenshotUtil(com.seleniumtests.driver.screenshots.ScreenshotUtil) File(java.io.File) Test(org.testng.annotations.Test) ReporterTest(com.seleniumtests.it.reporter.ReporterTest)

Example 44 with ScreenShot

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();
}
Also used : TestStep(com.seleniumtests.reporter.logger.TestStep) Snapshot(com.seleniumtests.reporter.logger.Snapshot) ScreenShot(com.seleniumtests.driver.screenshots.ScreenShot) ArrayList(java.util.ArrayList) TestMessage(com.seleniumtests.reporter.logger.TestMessage) File(java.io.File) TestAction(com.seleniumtests.reporter.logger.TestAction) WebDriverException(org.openqa.selenium.WebDriverException) Test(org.testng.annotations.Test)

Example 45 with ScreenShot

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

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