/** * @param browser * @param url */ public void initializeSelenium(String browser, String url) throws SAFSException { String id = getUniqueDriverID(); try { WDLibrary.startBrowser(browser, url, id, BROWSER_TIMEOUT, USE_REMOTE, BROWSER_PARMS); } catch (Throwable th) { String thmsg = "WDSPC initial session start() error: " + th.getMessage(); if (USE_REMOTE) { Log.info("WDSPC attempting to (re)start RemoteServer."); // if(WebDriverGUIUtilities.startRemoteServer()){ if (WebDriverGUIUtilities.startRemoteServer( Runner.driver().iDriver().getProjectRootDir())) { try { WDLibrary.startBrowser(browser, url, id, BROWSER_TIMEOUT, USE_REMOTE, BROWSER_PARMS); } catch (Throwable th2) { thmsg = "WDSPC second session start() error:" + th2.getMessage(); System.err.println(thmsg); Log.error(thmsg); throw new SAFSException(thmsg); } } } else { System.err.println(thmsg); Log.error(thmsg); throw new SAFSException(thmsg); } } Log.debug("Initialized browser: " + browser + " with ID: " + id); selenium = WDLibrary.getBrowserWithID(id); spcGUI.updateWindows(getWindows()); }
/** * <br> * <em>Purpose:</em> inputKeys and inputCharacters */ protected void inputKeystrokes() throws SAFSException { String keys = ""; if (params.size() < 1) { Log.error("Need at least one parameter."); paramsFailedMsg(windowName, compName); return; } keys = (String) iterator.next(); Log.debug("Input Parameter '" + keys + "'"); if (GenericMasterFunctions.INPUTKEYS_KEYWORD.equalsIgnoreCase(action)) { try { setFocusToWindow(); if (compObject == null) { Log.warn("component object is null."); } else { clearText(compObject); } Robot.inputKeys(keys); issuePassedSuccessUsing(keys); } catch (AWTException e) { Log.debug("Exception occur: " + e.getMessage()); issueActionFailure("Exception occur " + e.getMessage()); } } else { // InputCharacters try { if (compObject == null) { Log.debug("component object is null"); throw new SAFSException("component object is null"); } else { clearText(compObject); selenium.type(compObject.getLocator(), keys); issuePassedSuccessUsing(keys); } } catch (Exception e) { try { Log.debug("Can not input character by selenium API, try SAFS Robot."); Robot.inputChars(keys); issuePassedSuccessUsing(keys); } catch (AWTException awte) { Log.debug("Fail to inpu the character, Exception " + awte.getMessage()); issueActionFailure("Exception occur " + awte.getMessage()); } } } }
/** Minimize the current window */ protected void _minimize() throws SAFSException { String message = null; try { sUtils.minimizeWindow(testRecordData.getWindowGuiId()); return; } catch (Throwable se) { message = "Can not minimize window with native function. Exception=" + se.getMessage(); Log.warn(message); // If we fail to minimize window, try the SAFS Robot to do. try { super._minimize(); return; } catch (Exception e) { message = "Fail to minimize window by SAFS Robot. Exception=" + message; Log.error(message); throw new SAFSException(message); } } }
private String getUniqueDriverID() { String id = BROWSER_ID_ROOT; int index = 0; try { List<SessionInfo> list = RemoteDriver.getSessionsFromFile(); Log.info( "WDSPC getUniqueDriverID found " + list.size() + " existing remote sessions to process."); boolean matched = true; while (matched) { matched = false; for (SessionInfo info : list) { if (id.equals(info.id)) { matched = true; break; } } if (matched) id = BROWSER_ID_ROOT + String.valueOf(++index); } } catch (Exception x) { Log.error( "WDSPC getUniqueDriverID " + x.getClass().getSimpleName() + ": " + x.getMessage(), x); } return id; }
public void process() { String debugmsg = this.getClass().getName() + ".process(): "; // assume this for now.. sHelper = (STestRecordHelper) testRecordData; try { selenium = SApplicationMap.getSelenium(sHelper.getWindowName()); } catch (SAFSException e) { selenium = SApplicationMap.getSelenium(""); } testRecordData.setStatusCode(StatusCodes.SCRIPT_NOT_EXECUTED); try { getHelpers(); sUtils = (SeleniumGUIUtilities) utils; } catch (SAFSException ex) { testRecordData.setStatusCode(StatusCodes.GENERAL_SCRIPT_FAILURE); log.logMessage( testRecordData.getFac(), "SAFSException: " + ex.getClass().getName() + ", msg: " + ex.getMessage(), FAILED_MESSAGE); return; } winObject = sHelper.getWindowTestObject(); compObject = sHelper.getCompTestObject(); if (winObject == null) { Log.warn(debugmsg + " Window Object is null, try to get it through SeleniumGUIUtility. "); try { if (sUtils.waitForObject(mapname, windowName, windowName, secsWaitForWindow) == 0) { Log.debug(debugmsg + " we got the window object through SeleniumGUIUtility."); winObject = ((STestRecordHelper) testRecordData).getWindowTestObject(); } else { Log.debug( debugmsg + " can not get window object through SeleniumGUIUtility: waitForObject() error."); } } catch (SAFSObjectNotFoundException e) { Log.debug( debugmsg + " can not get window object through SeleniumGUIUtility: Exception=" + e.getMessage()); } if (winObject == null) { Log.error(debugmsg + " Window Object is still null"); testRecordData.setStatusCode(StatusCodes.GENERAL_SCRIPT_FAILURE); log.logMessage( testRecordData.getFac(), action + " failed, due to 'Window Object is null'", FAILED_MESSAGE); return; } } if (compObject == null) { Log.warn(debugmsg + " Component Object is null, try to get it through SeleniumGUIUtility."); if (!windowName.equals(compName)) { try { if (sUtils.waitForObject(mapname, windowName, compName, secsWaitForWindow) == 0) { Log.debug(debugmsg + " we get the component object through SeleniumGUIUtility."); compObject = ((STestRecordHelper) testRecordData).getCompTestObject(); } else { Log.debug( debugmsg + " can not get component object through SeleniumGUIUtility: waitForObject() error."); } } catch (SAFSObjectNotFoundException e) { Log.debug( debugmsg + " can not get component object through SeleniumGUIUtility: Exception=" + e.getMessage()); } if (compObject == null) { Log.warn(debugmsg + " Component Object is still null."); } } } // updateFromTestRecordData();//why this is commented? // do the work localProcess(); if (testRecordData.getStatusCode() == StatusCodes.SCRIPT_NOT_EXECUTED) { componentProcess(); // handle Generic keywords } else { Log.debug(debugmsg + " processed " + testRecordData); Log.debug(debugmsg + " params " + params); } }
/** * <br> * <em>Purpose:</em> componentClick */ protected void componentClick() throws SAFSException { if (compObject == null) { throw new SAFSException("Component SGuiObject is null."); } String locator = compObject.getLocator(); Log.debug("component's locator=" + locator); setFocusToWindow(); try { if (action.equalsIgnoreCase(CLICK) || action.equalsIgnoreCase(COMPONENTCLICK)) { selenium.click(locator); testRecordData.setStatusCode(StatusCodes.NO_SCRIPT_FAILURE); } else if (action.equalsIgnoreCase(CTRLCLICK)) { selenium.controlKeyDown(); selenium.click(locator); selenium.controlKeyUp(); testRecordData.setStatusCode(StatusCodes.NO_SCRIPT_FAILURE); } else if (action.equalsIgnoreCase(DOUBLECLICK)) { selenium.doubleClick(locator); testRecordData.setStatusCode(StatusCodes.NO_SCRIPT_FAILURE); } else if (action.equalsIgnoreCase(RIGHTCLICK)) { selenium.mouseDownRight(locator); selenium.mouseUpRight(locator); testRecordData.setStatusCode(StatusCodes.NO_SCRIPT_FAILURE); } else if (action.equalsIgnoreCase(CTRLRIGHTCLICK)) { selenium.controlKeyDown(); selenium.mouseDownRight(locator); selenium.mouseUpRight(locator); selenium.controlKeyUp(); testRecordData.setStatusCode(StatusCodes.NO_SCRIPT_FAILURE); } else if (action.equalsIgnoreCase(SHIFTCLICK)) { selenium.shiftKeyDown(); selenium.click(locator); selenium.shiftKeyUp(); testRecordData.setStatusCode(StatusCodes.NO_SCRIPT_FAILURE); } } catch (Exception e) { // Try SFAS robot to do the work. scrollToComponent(compObject); Rectangle compRect = getComponentBounds(compObject); if (compRect == null) { Log.error("component rectangle is null."); throw new SAFSException("component rectangle is null."); } // Log.info("Selenium mouseMove to: " // +(int)compRect.getCenterX()+":"+(int)compRect.getCenterY()); if (action.equalsIgnoreCase(CLICK) || action.equalsIgnoreCase(COMPONENTCLICK)) { robot.mouseMove((int) compRect.getCenterX(), (int) compRect.getCenterY()); robot.mousePress(KeyEvent.BUTTON1_MASK); robot.mouseRelease(KeyEvent.BUTTON1_MASK); testRecordData.setStatusCode(StatusCodes.NO_SCRIPT_FAILURE); } else if (action.equalsIgnoreCase(CTRLCLICK)) { robot.keyPress(KeyEvent.VK_CONTROL); robot.mouseMove((int) compRect.getCenterX(), (int) compRect.getCenterY()); robot.mousePress(KeyEvent.BUTTON1_MASK); robot.mouseRelease(KeyEvent.BUTTON1_MASK); robot.keyRelease(KeyEvent.VK_CONTROL); testRecordData.setStatusCode(StatusCodes.NO_SCRIPT_FAILURE); } else if (action.equalsIgnoreCase(DOUBLECLICK)) { robot.mouseMove((int) compRect.getCenterX(), (int) compRect.getCenterY()); robot.mousePress(KeyEvent.BUTTON1_MASK); robot.mouseRelease(KeyEvent.BUTTON1_MASK); robot.mousePress(KeyEvent.BUTTON1_MASK); robot.mouseRelease(KeyEvent.BUTTON1_MASK); testRecordData.setStatusCode(StatusCodes.NO_SCRIPT_FAILURE); } else if (action.equalsIgnoreCase(RIGHTCLICK)) { robot.mouseMove((int) compRect.getCenterX(), (int) compRect.getCenterY()); robot.mousePress(KeyEvent.BUTTON3_MASK); robot.mouseRelease(KeyEvent.BUTTON3_MASK); testRecordData.setStatusCode(StatusCodes.NO_SCRIPT_FAILURE); } else if (action.equalsIgnoreCase(CTRLRIGHTCLICK)) { robot.keyPress(KeyEvent.VK_CONTROL); robot.mouseMove((int) compRect.getCenterX(), (int) compRect.getCenterY()); robot.mousePress(KeyEvent.BUTTON3_MASK); robot.mouseRelease(KeyEvent.BUTTON3_MASK); robot.keyRelease(KeyEvent.VK_CONTROL); testRecordData.setStatusCode(StatusCodes.NO_SCRIPT_FAILURE); } else if (action.equalsIgnoreCase(SHIFTCLICK)) { robot.keyPress(KeyEvent.VK_SHIFT); robot.mousePress(KeyEvent.BUTTON1_MASK); robot.mouseRelease(KeyEvent.BUTTON1_MASK); robot.keyRelease(KeyEvent.VK_SHIFT); testRecordData.setStatusCode(StatusCodes.NO_SCRIPT_FAILURE); } } // log success message and status if (testRecordData.getStatusCode() == StatusCodes.NO_SCRIPT_FAILURE) { String msg = genericText.convert( "success3", windowName + ":" + compName + " " + action + " successful.", windowName, compName, action); log.logMessage(testRecordData.getFac(), msg, PASSED_MESSAGE); return; // just in case. (normally any failure should have issued an Exception) } else { log.logMessage( testRecordData.getFac(), action + "\n" + testRecordData.getFilename() + " at Line " + testRecordData.getLineNumber() + ", " + testRecordData.getFac(), FAILED_MESSAGE); testRecordData.setStatusCode(StatusCodes.GENERAL_SCRIPT_FAILURE); } }