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");
}
}
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());
}
}
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());
}
}
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");
}
}
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);
}
}
}
}
}
Aggregations