protected boolean exist() throws SAFSException { String debugmsg = StringUtils.debugmsg(false); try { boolean isShowing = false; // wait for the window - secTimout of 0 means a single try to search for given comps // waitForObject checks only component validity and tells nothing about its visibility int status = sUtils.waitForObject(mapname, windowName, compName, 0); if (status == 0) { // component search succeeded isShowing = compIsVisible("//HTML[1]"); SGuiObject obj; obj = sHelper.getCompTestObject(); if (isShowing && (obj != null)) { isShowing = compIsVisible(obj.getLocator()); } } // else status!=0, which means that component search failed return isShowing; } catch (SAFSObjectNotFoundException sonfe) { Log.warn(debugmsg + " Met Exception " + StringUtils.debugmsg(sonfe)); } return false; }
protected Object getPropertyObject(String propertyName) throws SAFSException { String rval = null; if (compObject == null) { int status = waitForObject(mapname, windowName, compName, secsWaitForComponent); if (status == 0) compObject = ((STestRecordHelper) testRecordData).getCompTestObject(); } if (compObject != null) { Log.debug("assignPropVar for " + compObject.getLocator() + ":" + propertyName); rval = sUtils.getAttribute(selenium, compObject.getLocator(), propertyName); if (rval == null) { rval = selenium.getEval( "var xpath = \"" + compObject.getLocator() + "\";var prop = \"" + propertyName + "\";SAFSgetAttribute(xpath,prop);"); } } else { Log.warn("component object is null."); } return rval; }
@SuppressWarnings("unchecked") protected Map<String, Object> getProperties() throws SAFSException { if (compObject != null) { return sUtils.getAttributes(selenium, compObject.getLocator()); } else { Log.debug("compObject is null, can't get properties."); return null; } }
/** Maximize the current window */ protected void _maximize() throws SAFSException { String message = null; // The window can't be resotred if it is maximized by selenium API. // So use the SAFS Robot to maximize the windows firstly try { super._maximize(); return; } catch (SAFSException e) { message = "Can't maximize window by SAFS Robot. Try Selenium API to maximize. Exception=" + e.getMessage(); Log.warn(message); if (!sUtils.maximizeWindow(winObject.getWindowId(), selenium)) { throw new SAFSException("Fail to maximize by Selenium API."); } } }
/** * Scrolls to a component on the page * * @param o component to be scrolled to */ protected void scrollToComponent(SGuiObject o) { String xpath = sUtils.navigateFrames(o.getLocator(), selenium); long left = 0; long top = 0; try { left = selenium.getElementPositionLeft(xpath).longValue(); } catch (Exception x) { } try { top = selenium.getElementPositionTop(xpath).longValue(); } catch (Exception x) { } String eval = selenium.getEval("SAFSgetClientScrollInfo();"); String[] values = eval.split(";"); long width = 0; long height = 0; long scrollTop = 0; long scrollLeft = 0; try { width = Integer.parseInt(values[0]); } catch (Exception x) {; } try { height = Integer.parseInt(values[1]); } catch (Exception x) {; } try { scrollLeft = Integer.parseInt(values[2]); } catch (Exception x) {; } try { scrollTop = Integer.parseInt(values[3]); } catch (Exception x) {; } if ((left < scrollLeft || left > scrollLeft + width) || (top < scrollTop || top > scrollTop + height)) { eval = selenium.getEval("window.scrollTo(" + left + "," + top + ");"); } }
/** 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); } } }
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); } }
/** * Gets the size of the component * * @param s component * @return size of the component */ protected Rectangle getComponentBounds(String s) { return sUtils.getComponentBounds(s, selenium); }
/** * Gets the size of the component * * @param o component * @return size of the component */ private Rectangle getComponentBounds(SGuiObject o) { return sUtils.getComponentBounds(o, selenium); }
/** * <br> * <em>Purpose:</em> verifyProperty */ protected void verifyProperty() throws SAFSException { testRecordData.setStatusCode(StatusCodes.GENERAL_SCRIPT_FAILURE); if (params.size() < 2) { paramsFailedMsg(windowName, compName); return; } String prop = (String) iterator.next(); String val = (String) iterator.next(); String strcase = ""; boolean ignorecase = false; try { strcase = (String) iterator.next(); } catch (Exception x) {; } ignorecase = !StringUtils.isCaseSensitive(strcase); Log.info(".....CFComponent.process; ready to do the VP for prop : " + prop + " val: " + val); String rval = null; int status = sUtils.waitForObject(mapname, windowName, compName, 15); SGuiObject comp = null; String _type = null; if (status == 0) { comp = ((STestRecordHelper) testRecordData).getCompTestObject(); _type = ((STestRecordHelper) testRecordData).getCompType(); // TODO: Changed this! // rval = selenium.getEval("var xpath = \""+comp.getLocator()+"\";var prop = // \""+prop+"\";SAFSgetAttribute(xpath,prop);"); rval = sUtils.getAttribute(selenium, comp.getLocator(), prop); if (rval == null) { Log.info( "Selenium property '" + prop + "' for component '" + compName + "' of type '" + _type + "' not found. Trying alternatives..."); // assume attribute not found if (((_type.equalsIgnoreCase("CHECKBOX")) || (_type.equalsIgnoreCase("RADIOBUTTON"))) && (prop.equalsIgnoreCase("CHECKED")) && (val.equalsIgnoreCase("FALSE"))) { rval = "False"; } if (((_type.equalsIgnoreCase("LISTBOX")) || (_type.equalsIgnoreCase("COMBOBOX"))) && (prop.equalsIgnoreCase("SELECTED")) && (val.equalsIgnoreCase("FALSE"))) { rval = "False"; } } } Log.info( "Selenium property '" + prop + "' for component '" + compName + "' of type '" + _type + "' contains value '" + rval + "'"); // it is possible the property name is not valid for Selenium // it may be a property valid in a different engine // TODO: but do we want to assume we are running with other engines? if (rval == null || rval.equals("null")) { testRecordData.setStatusCode(StatusCodes.SCRIPT_NOT_EXECUTED); return; } if (((!ignorecase) && (val.equals(rval))) || (ignorecase && (val.equalsIgnoreCase(rval)))) { // set status to ok testRecordData.setStatusCode(StatusCodes.NO_SCRIPT_FAILURE); altText = genericText.convert( "bench_matches", compName + ":" + prop + " matches expected value \"" + val + "\"", compName + ":" + prop, val); log.logMessage(testRecordData.getFac(), altText, PASSED_MESSAGE); } else { // failed testRecordData.setStatusCode(StatusCodes.GENERAL_SCRIPT_FAILURE); altText = genericText.convert( "bench_not_match", compName + ":" + prop + " did not match expected result \"" + val + "\"", compName + ":" + prop, val); String detail = genericText.convert("actual_value", "ActualValue='" + rval + "'", rval); standardFailureMessage(altText, compName + ":" + prop + " " + detail); } }
private void setFocusToWindow() throws SAFSException { if (!sUtils.setWindowFocus(winObject.getWindowId(), selenium)) { Log.warn("Not able to focus window: " + testRecordData.getWindowGuiId()); } }