use of com.seleniumtests.customexception.ScenarioException in project seleniumRobot by bhecquet.
the class TestTasks method executeCommand.
/**
* Execute a command
* If test is run locally, you can execute any command, limit is the rights given to the user
* If test is run through seleniumRobot grid, only commands allowed by grid will be allowed
* @param program program to execute
* @param charset the charset used to read program output
* @param timeout timeout in seconds. After this duration, program will be terminated
* @param args arguments to give to program
*/
public static String executeCommand(String program, int timeout, Charset charset, String... args) {
if (SeleniumTestsContextManager.getThreadContext().getRunMode() == DriverMode.LOCAL) {
String[] cmd = new String[] { program };
cmd = ArrayUtils.addAll(cmd, args);
return OSCommand.executeCommandAndWait(cmd, timeout, charset);
} else if (SeleniumTestsContextManager.getThreadContext().getRunMode() == DriverMode.GRID) {
SeleniumGridConnector gridConnector = SeleniumTestsContextManager.getThreadContext().getSeleniumGridConnector();
if (gridConnector != null) {
return gridConnector.executeCommand(program, timeout, args);
} else {
throw new ScenarioException(ERROR_NO_GRID_CONNECTOR_ACTIVE);
}
} else {
throw new ScenarioException("command execution only supported in local and grid mode");
}
}
use of com.seleniumtests.customexception.ScenarioException in project seleniumRobot by bhecquet.
the class ScreenshotUtil method captureAllImages.
/**
* Capture all images and returns them as BufferedImages
* @param target
* @param allWindows
* @return
*/
private List<NamedBufferedImage> captureAllImages(SnapshotTarget target, boolean allWindows, int scrollDelay) {
List<NamedBufferedImage> capturedImages = new ArrayList<>();
// capture desktop
if (target.isScreenTarget() && SeleniumTestsContextManager.isDesktopWebTest()) {
capturedImages.add(new NamedBufferedImage(captureDesktop(), ""));
// capture desktop
} else if (target.isMainScreenTarget() && SeleniumTestsContextManager.isDesktopWebTest()) {
capturedImages.add(new NamedBufferedImage(captureDesktop(true), ""));
// capture web with scrolling
} else if (target.isPageTarget() && SeleniumTestsContextManager.isWebTest()) {
removeAlert();
capturedImages.addAll(captureWebPages(allWindows, scrollDelay));
// capture web without scrolling on the main window
} else if (target.isViewportTarget() && SeleniumTestsContextManager.isWebTest()) {
removeAlert();
target.setSnapshotRectangle(new Rectangle(((CustomEventFiringWebDriver) driver).getScrollPosition(), ((CustomEventFiringWebDriver) driver).getViewPortDimensionWithoutScrollbar()));
// allow removing of scrollbar (a negative value would not remove it)
capturedImages.add(new NamedBufferedImage(capturePage(0, 0), ""));
// capture web with scrolling on the main window
} else if (target.isElementTarget() && SeleniumTestsContextManager.isWebTest()) {
removeAlert();
try {
target.setSnapshotRectangle(target.getElement().getRect());
} catch (WebDriverException e) {
throw new ScenarioException(String.format("Cannot check element %s snapshot as it is not available", target.getElement()));
}
capturedImages.addAll(captureWebPages(false, scrollDelay));
} else if ((target.isPageTarget() || target.isElementTarget() || target.isViewportTarget()) && SeleniumTestsContextManager.isAppTest()) {
capturedImages.add(new NamedBufferedImage(capturePage(-1, -1), ""));
} else {
throw new ScenarioException("Capturing page is only possible for web and application tests. Capturing desktop possible for desktop web tests only");
}
// if we want to capture an element only, crop the previous capture
if (target.isElementTarget() && target.getElement() != null && !capturedImages.isEmpty()) {
Rectangle elementPosition = target.getElement().getRect();
NamedBufferedImage wholeImage = capturedImages.remove(0);
BufferedImage elementImage = ImageProcessor.cropImage(wholeImage.image, elementPosition.x, elementPosition.y, elementPosition.width, elementPosition.height);
NamedBufferedImage namedElementImage = new NamedBufferedImage(elementImage, "");
namedElementImage.addElementMetaDataToImage(target.getElement());
capturedImages.add(0, namedElementImage);
}
return capturedImages;
}
use of com.seleniumtests.customexception.ScenarioException in project seleniumRobot by bhecquet.
the class TestWebUIDriver method testDriverCreationWithVideoInError.
@Test(groups = { "ut" })
public void testDriverCreationWithVideoInError() throws Exception {
SeleniumTestsContextManager.getThreadContext().setVideoCapture("true");
SeleniumTestsContextManager.getThreadContext().setBrowser("htmlunit");
PowerMockito.mockStatic(CustomEventFiringWebDriver.class);
PowerMockito.doThrow(new ScenarioException("error")).when(CustomEventFiringWebDriver.class, "startVideoCapture", eq(DriverMode.LOCAL), eq(null), any(File.class), eq("videoCapture.avi"));
WebDriver driver = WebUIDriver.getWebDriver(true);
Assert.assertTrue(driver instanceof CustomEventFiringWebDriver);
Assert.assertNull(WebUIDriver.getVideoRecorder().get());
}
use of com.seleniumtests.customexception.ScenarioException in project seleniumRobot by bhecquet.
the class PictureElement method isDriverCreated.
private WebUIDriver isDriverCreated() {
WebUIDriver uiDriver = WebUIDriver.getWebUIDriver(false);
if (uiDriver == null) {
throw new ScenarioException("Driver has not already been created");
}
CustomEventFiringWebDriver driver = (CustomEventFiringWebDriver) uiDriver.getDriver();
if (driver == null) {
throw new ScenarioException("Driver has not already been created");
}
return uiDriver;
}
use of com.seleniumtests.customexception.ScenarioException in project seleniumRobot by bhecquet.
the class PageObject method assertForValue.
@GenericStep
public <T extends PageObject> T assertForValue(String fieldName, String value) {
Element element = getElement(fieldName);
if (element instanceof HtmlElement) {
Assert.assertTrue(((HtmlElement) element).isElementPresent(0), String.format(ERROR_ELEMENT_NOT_PRESENT, fieldName));
Assert.assertTrue(((HtmlElement) element).getText().equals(value) || ((HtmlElement) element).getValue().equals(value), String.format("Value of element %s is not %s", fieldName, value));
} else {
throw new ScenarioException(String.format(ELEMENT_S_IS_NOT_AN_HTML_ELEMENT_SUBCLASS, fieldName));
}
return (T) this;
}
Aggregations