Search in sources :

Example 1 with ScenarioException

use of com.seleniumtests.customexception.ScenarioException in project seleniumRobot by bhecquet.

the class CustomEventFiringWebDriver method startVideoCapture.

/**
 * Start video capture using VideoRecorder class
 * @param driverMode
 * @param gridConnector
 * @param videoName		name of the video to record so that it's unique. Only used locally. In remote, grid sessionId is used
 */
public static VideoRecorder startVideoCapture(DriverMode driverMode, SeleniumGridConnector gridConnector, File videoFolder, String videoName) {
    if (driverMode == DriverMode.LOCAL) {
        try {
            VideoRecorder recorder = new VideoRecorder(videoFolder, videoName);
            recorder.start();
            return recorder;
        } catch (HeadlessException e) {
            throw new ScenarioException("could not initialize video capture with headless robot: " + e.getMessage());
        }
    } else if (driverMode == DriverMode.GRID && gridConnector != null) {
        gridConnector.startVideoCapture();
        return new VideoRecorder(videoFolder, videoName, false);
    } else {
        throw new ScenarioException("driver supports startVideoCapture only in local and grid mode");
    }
}
Also used : HeadlessException(java.awt.HeadlessException) VideoRecorder(com.seleniumtests.util.video.VideoRecorder) ScenarioException(com.seleniumtests.customexception.ScenarioException)

Example 2 with ScenarioException

use of com.seleniumtests.customexception.ScenarioException in project seleniumRobot by bhecquet.

the class CustomEventFiringWebDriver method sendKeysToDesktop.

/**
 * send keys to desktop
 * This is useful for typing special keys like ENTER
 * @param keys	List of KeyEvent
 */
public static void sendKeysToDesktop(List<Integer> keyCodes, DriverMode driverMode, SeleniumGridConnector gridConnector) {
    if (driverMode == DriverMode.LOCAL) {
        try {
            Robot robot = new Robot();
            WaitHelper.waitForSeconds(1);
            for (Integer key : keyCodes) {
                robot.keyPress(key);
                robot.keyRelease(key);
            }
        } catch (AWTException e) {
            throw new ScenarioException("could not initialize robot to type keys: " + e.getMessage());
        }
    } else if (driverMode == DriverMode.GRID && gridConnector != null) {
        gridConnector.sendKeysWithKeyboard(keyCodes);
    } else {
        throw new ScenarioException("driver supports sendKeysToDesktop only in local and grid mode");
    }
}
Also used : Robot(java.awt.Robot) ScenarioException(com.seleniumtests.customexception.ScenarioException) AWTException(java.awt.AWTException)

Example 3 with ScenarioException

use of com.seleniumtests.customexception.ScenarioException in project seleniumRobot by bhecquet.

the class CustomEventFiringWebDriver method uploadFile.

public static void uploadFile(String fileName, String base64Content, DriverMode driverMode, SeleniumGridConnector gridConnector) throws IOException {
    if (driverMode == DriverMode.LOCAL) {
        byte[] byteArray = base64Content.getBytes();
        File tempFile = new File("tmp/" + fileName);
        byte[] decodeBuffer = Base64.decodeBase64(byteArray);
        FileUtils.writeByteArrayToFile(tempFile, decodeBuffer);
        try {
            uploadFileUsingClipboard(tempFile);
        } catch (IllegalStateException e) {
            uploadFileUsingKeyboardTyping(tempFile);
        }
    } else if (driverMode == DriverMode.GRID && gridConnector != null) {
        gridConnector.uploadFileToBrowser(fileName, base64Content);
    } else {
        throw new ScenarioException("driver supports uploadFile only in local and grid mode");
    }
}
Also used : File(java.io.File) ScenarioException(com.seleniumtests.customexception.ScenarioException)

Example 4 with ScenarioException

use of com.seleniumtests.customexception.ScenarioException in project seleniumRobot by bhecquet.

the class CustomEventFiringWebDriver method doubleClickOnDesktopAt.

public static void doubleClickOnDesktopAt(boolean onlyMainScreen, int x, int y, DriverMode driverMode, SeleniumGridConnector gridConnector) {
    if (driverMode == DriverMode.LOCAL) {
        try {
            Robot robot = new Robot();
            if (onlyMainScreen) {
                moveMouseMainScreen(robot, x, y);
            } else {
                moveMouse(robot, x, y);
            }
            robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
            robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
            robot.delay(10);
            robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
            robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
        } catch (AWTException e) {
            throw new ScenarioException("doubleClickOnDesktopAt: problem using Robot: " + e.getMessage());
        }
    } else if (driverMode == DriverMode.GRID && gridConnector != null) {
        gridConnector.doubleClick(onlyMainScreen, x, y);
    } else {
        throw new ScenarioException("driver supports doubleClickOnDesktopAt only in local and grid mode");
    }
}
Also used : Robot(java.awt.Robot) ScenarioException(com.seleniumtests.customexception.ScenarioException) AWTException(java.awt.AWTException)

Example 5 with ScenarioException

use of com.seleniumtests.customexception.ScenarioException in project seleniumRobot by bhecquet.

the class CustomEventFiringWebDriver method rightClicOnDesktopAt.

public static void rightClicOnDesktopAt(boolean onlyMainScreen, int x, int y, DriverMode driverMode, SeleniumGridConnector gridConnector) {
    if (driverMode == DriverMode.LOCAL) {
        try {
            Robot robot = new Robot();
            if (onlyMainScreen) {
                moveMouseMainScreen(robot, x, y);
            } else {
                moveMouse(robot, x, y);
            }
            robot.mousePress(InputEvent.BUTTON2_DOWN_MASK);
            robot.mouseRelease(InputEvent.BUTTON2_DOWN_MASK);
        } catch (AWTException e) {
            throw new ScenarioException("rightClicOnDesktopAt: problem using Robot: " + e.getMessage());
        }
    } else if (driverMode == DriverMode.GRID && gridConnector != null) {
        gridConnector.rightClic(onlyMainScreen, x, y);
    } else {
        throw new ScenarioException("driver supports sendKeysToDesktop only in local and grid mode");
    }
}
Also used : Robot(java.awt.Robot) ScenarioException(com.seleniumtests.customexception.ScenarioException) AWTException(java.awt.AWTException)

Aggregations

ScenarioException (com.seleniumtests.customexception.ScenarioException)68 ArrayList (java.util.ArrayList)17 WebElement (org.openqa.selenium.WebElement)14 UnirestException (kong.unirest.UnirestException)13 GenericPictureElement (com.seleniumtests.uipage.htmlelements.GenericPictureElement)12 IOException (java.io.IOException)12 JSONObject (kong.unirest.json.JSONObject)12 CheckBoxElement (com.seleniumtests.uipage.htmlelements.CheckBoxElement)11 Element (com.seleniumtests.uipage.htmlelements.Element)11 HtmlElement (com.seleniumtests.uipage.htmlelements.HtmlElement)11 LinkElement (com.seleniumtests.uipage.htmlelements.LinkElement)11 RadioButtonElement (com.seleniumtests.uipage.htmlelements.RadioButtonElement)11 File (java.io.File)10 List (java.util.List)9 HashMap (java.util.HashMap)8 ConfigurationException (com.seleniumtests.customexception.ConfigurationException)7 AWTException (java.awt.AWTException)7 Robot (java.awt.Robot)6 Map (java.util.Map)5 TestStep (com.seleniumtests.reporter.logger.TestStep)4