Search in sources :

Example 56 with ScenarioException

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

the class CustomEventFiringWebDriver method writeToDesktop.

/**
 * write text to desktop.
 * @param textToWrite	text to write
 * @return
 */
public static void writeToDesktop(String textToWrite, DriverMode driverMode, SeleniumGridConnector gridConnector) {
    if (driverMode == DriverMode.LOCAL) {
        try {
            Keyboard keyboard = new Keyboard();
            keyboard.typeKeys(textToWrite);
        } catch (AWTException e) {
            throw new ScenarioException("writeToDesktop: could not initialize robot to type keys: " + e.getMessage());
        }
    } else if (driverMode == DriverMode.GRID && gridConnector != null) {
        gridConnector.writeText(textToWrite);
    } else {
        throw new ScenarioException("driver supports writeToDesktop only in local and grid mode");
    }
}
Also used : ScenarioException(com.seleniumtests.customexception.ScenarioException) AWTException(java.awt.AWTException)

Example 57 with ScenarioException

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

the class CustomEventFiringWebDriver method uploadFileUsingKeyboardTyping.

/**
 * Upload file typing file path directly
 * @param tempFile
 */
public static void uploadFileUsingKeyboardTyping(File tempFile) {
    try {
        Keyboard keyboard = new Keyboard();
        Robot robot = keyboard.getRobot();
        WaitHelper.waitForSeconds(1);
        // // Press Enter
        // robot.keyPress(KeyEvent.VK_ENTER);
        // 
        // // Release Enter
        // robot.keyRelease(KeyEvent.VK_ENTER);
        keyboard.typeKeys(tempFile.getAbsolutePath());
        WaitHelper.waitForSeconds(1);
        // Press Enter
        robot.keyPress(KeyEvent.VK_ENTER);
        robot.keyRelease(KeyEvent.VK_ENTER);
    } catch (AWTException e) {
        throw new ScenarioException("could not initialize robot to upload file typing keys: " + e.getMessage());
    }
}
Also used : Robot(java.awt.Robot) ScenarioException(com.seleniumtests.customexception.ScenarioException) AWTException(java.awt.AWTException)

Example 58 with ScenarioException

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

the class CustomEventFiringWebDriver method uploadFileUsingClipboard.

/**
 * Use copy to clipboard and copy-paste keyboard shortcut to write something on upload window
 */
public static void uploadFileUsingClipboard(File tempFile) {
    // Copy to clipboard
    Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new StringSelection(tempFile.getAbsolutePath()), null);
    Robot robot;
    try {
        robot = new Robot();
        WaitHelper.waitForSeconds(1);
        // // Press Enter
        // robot.keyPress(KeyEvent.VK_ENTER);
        // 
        // // Release Enter
        // robot.keyRelease(KeyEvent.VK_ENTER);
        // Press CTRL+V
        robot.keyPress(KeyEvent.VK_CONTROL);
        robot.keyPress(KeyEvent.VK_V);
        // Release CTRL+V
        robot.keyRelease(KeyEvent.VK_CONTROL);
        robot.keyRelease(KeyEvent.VK_V);
        WaitHelper.waitForSeconds(1);
        // Press Enter
        robot.keyPress(KeyEvent.VK_ENTER);
        robot.keyRelease(KeyEvent.VK_ENTER);
    } catch (AWTException e) {
        throw new ScenarioException("could not initialize robot to upload file: " + e.getMessage());
    }
}
Also used : Robot(java.awt.Robot) ScenarioException(com.seleniumtests.customexception.ScenarioException) StringSelection(java.awt.datatransfer.StringSelection) AWTException(java.awt.AWTException)

Example 59 with ScenarioException

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

the class CustomEventFiringWebDriver method leftClicOnDesktopAt.

public static void leftClicOnDesktopAt(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);
        } catch (AWTException e) {
            throw new ScenarioException("leftClicOnDesktopAt: problem using Robot: " + e.getMessage());
        }
    } else if (driverMode == DriverMode.GRID && gridConnector != null) {
        gridConnector.leftClic(onlyMainScreen, x, y);
    } else {
        throw new ScenarioException("driver supports leftClicOnDesktopAt only in local and grid mode");
    }
}
Also used : Robot(java.awt.Robot) ScenarioException(com.seleniumtests.customexception.ScenarioException) AWTException(java.awt.AWTException)

Example 60 with ScenarioException

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

the class TestNGResultUtils method changeTestResultWithSnapshotComparison.

/**
 * Change the test result when snapshot comparison fails
 * @param testResult
 */
public static void changeTestResultWithSnapshotComparison(final ITestResult testResult) {
    if (// test is already failed
    testResult.getStatus() == ITestResult.FAILURE || !Boolean.TRUE.equals(SeleniumTestsContextManager.getGlobalContext().getSeleniumRobotServerActive()) || // as the comparison result is only displayed, do not retry
    SeleniumTestsContextManager.getGlobalContext().getSeleniumRobotServerCompareSnapshotBehaviour() == SnapshotComparisonBehaviour.DISPLAY_ONLY || // complicated to set the test failed, and then success again
    SeleniumTestsContextManager.getGlobalContext().getSeleniumRobotServerCompareSnapshotBehaviour() == SnapshotComparisonBehaviour.ADD_TEST_RESULT || !SeleniumTestsContextManager.getGlobalContext().getSeleniumRobotServerCompareSnapshot()) {
        return;
    }
    SeleniumRobotSnapshotServerConnector serverConnector = SeleniumRobotSnapshotServerConnector.getInstance();
    List<TestStep> testSteps = getSeleniumRobotTestContext(testResult).getTestStepManager().getTestSteps();
    if (testSteps == null) {
        return;
    }
    for (TestStep testStep : testSteps) {
        for (Snapshot snapshot : new ArrayList<>(testStep.getSnapshots())) {
            if (snapshot.getCheckSnapshot().recordSnapshotOnServerForComparison()) {
                if (snapshot.getName() == null || snapshot.getName().isEmpty()) {
                    logger.warn("Snapshot hasn't any name, it won't be sent to server");
                    continue;
                }
                try {
                    SnapshotComparisonResult comparisonResult = serverConnector.checkSnapshotHasNoDifferences(snapshot, CommonReporter.getTestCaseName(testResult), testStep.getName());
                    if (comparisonResult == SnapshotComparisonResult.KO) {
                        testResult.setStatus(ITestResult.FAILURE);
                        testResult.setThrowable(new ScenarioException("Snapshot comparison failed"));
                        // move test from passedTests to failedTests if test is not already in failed tests
                        if (testResult.getTestContext().getPassedTests().getAllMethods().contains(testResult.getMethod())) {
                            testResult.getTestContext().getPassedTests().removeResult(testResult);
                            testResult.getTestContext().getFailedTests().addResult(testResult, testResult.getMethod());
                        }
                        return;
                    }
                } catch (SeleniumRobotServerException e) {
                    logger.error("Could not create snapshot on server", e);
                }
            }
        }
    }
}
Also used : TestStep(com.seleniumtests.reporter.logger.TestStep) Snapshot(com.seleniumtests.reporter.logger.Snapshot) ArrayList(java.util.ArrayList) SeleniumRobotSnapshotServerConnector(com.seleniumtests.connectors.selenium.SeleniumRobotSnapshotServerConnector) ScenarioException(com.seleniumtests.customexception.ScenarioException) SnapshotComparisonResult(com.seleniumtests.connectors.selenium.SeleniumRobotSnapshotServerConnector.SnapshotComparisonResult) SeleniumRobotServerException(com.seleniumtests.customexception.SeleniumRobotServerException)

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