示例#1
0
  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;
  }
示例#2
0
  /**
   * @param filename String
   * @param parentDir String, the parent directory of the filename
   * @return String, absolute file name got from filename and it's parent
   * @throws SAFSException
   */
  protected String getAbsoluteFileName(String filename, String parentDir) throws SAFSException {
    String debugMsg = getClass().getName() + ".getAbsoluteFileName(): ";

    // Get the bench and test absolute fileName
    if (filename == null || filename.equals("") || filename.endsWith(File.separator)) {
      String detail =
          failedText.convert(
              FAILStrings.BAD_PARAM, "Invalid parameter value for FileName", "FileName");
      Log.debug(debugMsg + detail);
      throw new SAFSException(detail);
    }

    File fn = new CaseInsensitiveFile(filename).toFile();
    if (!fn.isAbsolute()) {
      String pdir = getVariable(parentDir);

      if (pdir == null) {
        String detail =
            failedText.convert(
                FAILStrings.STAF_ERROR,
                "SATF ERROR: Can not get variable " + parentDir,
                "Can not get variable " + parentDir);
        Log.debug(debugMsg + detail);
        throw new SAFSException(detail);
      }

      return new CaseInsensitiveFile(pdir, filename).toFile().getAbsolutePath();
    }

    return filename;
  }
示例#3
0
文件: WDSPC.java 项目: SAFSDEV/Core
 /**
  * @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());
 }
示例#4
0
文件: WDSPC.java 项目: SAFSDEV/Core
 /**
  * Retrieve the "title" of each available browser "window" controlled by a WebDriver we have
  * launched.
  *
  * @return
  */
 public String[] getWindows() {
   Log.info("WDSPC getWindows blocked by runningGetAllElements.");
   while (runningGetAllElements) ;
   Log.info("WDSPC getWindows now proceeding...");
   runningWindowChecker = true;
   String[] titles = new String[0];
   try {
     titles = WDLibrary.getAllWindowTitles();
   } catch (Exception x) {
     Log.debug("WDSPC getWindows Exception:", x);
   }
   runningWindowChecker = false;
   return titles;
 }
示例#5
0
  /**
   * theObj is expected to be a JMenu TestObject proxy (Usually a ToggleGUITestObject). Path
   * information (might not have length > 0).
   *
   * <p>We are then going to go UP the tree to make the full path from menubar down to the subitem.
   *
   * <p>
   *
   * @param theObj -- The JMenu proxy to be evaluated.
   * @param path -- The initial path provided prior to us filling in the full path up the hierarchy.
   *     This must be the child path of "theObj"
   * @return GuiSubitemTestObject, the test proxy object of "JMenuBar" or "JPopupMenu". The
   *     parameter path will contain the full path to the ancestor whose type is "JMenuBar" or
   *     "JPopupMenu"
   */
  protected GuiSubitemTestObject getSubMenuItemFullPath(TestObject theObj, StringBuffer path)
      throws SAFSException {
    String debugmsg = getClass().getName() + ".getSubMenuItemFullPath() ";
    String text = null;
    TestObject proxyObj = new TestObject(theObj.getObjectReference());
    GuiSubitemTestObject guiSbuitemObj = null;

    // Try to get the ancestor of this test object,
    // The ancestor must be the test proxy object of "MenuBar" or "PopupMenu"
    boolean isMenuBarOrPopupMenu = false;

    while ((!isMenuBarOrPopupMenu) && (proxyObj != null)) {
      if (!isMenuBarOrPopupMenu) {
        text = getPropertyText(proxyObj);
        if (path.length() > 0) path.insert(0, text + Tree.PATH_SEPARATOR);
        else path.insert(0, text);
      }
      proxyObj = proxyObj.getMappableParent();
      isMenuBarOrPopupMenu = isMenuBar(proxyObj);
    }
    if (isMenuBarOrPopupMenu) {
      guiSbuitemObj = new GuiSubitemTestObject(proxyObj.getObjectReference());
    } else {
      Log.debug(
          debugmsg
              + "Can not get ancestor of type 'Menu Bar' or 'Popup Menu' for "
              + theObj.getObjectClassName());
    }

    return guiSbuitemObj;
  }
示例#6
0
 /**
  * @param guiObj, TestObject may be JMenuBar or JPopupMenu
  * @param path, String is the full path of some MenuItem on which a click action will take place
  */
 protected void selectMenuItemWithoutVerification(GuiSubitemTestObject guiObj, String path) {
   com.rational.test.ft.script.List list = Script.localAtPath(path);
   // guiObj.setState(Action.select(), list); // RobotJ doesn't like this...
   try {
     guiObj.click(list);
     // set status to ok
     testRecordData.setStatusCode(StatusCodes.OK);
     String altText =
         "MenuItem \"" + path + "\" clicked, " + windowName + ":" + compName + " " + action;
     log.logMessage(
         testRecordData.getFac(),
         passedText.convert(PRE_TXT_SUCCESS_4, altText, path, windowName, compName, action),
         PASSED_MESSAGE);
   } catch (TargetGoneException tge) {
     Log.info(
         "CFMenuBar IGNORING TargetGoneException probably resulting from intended window closure...");
     // set status to ok
     testRecordData.setStatusCode(StatusCodes.OK);
     String altText =
         "MenuItem \"" + path + "\" clicked, " + windowName + ":" + compName + " " + action;
     log.logMessage(
         testRecordData.getFac(),
         passedText.convert(PRE_TXT_SUCCESS_4, altText, path, windowName, compName, action),
         PASSED_MESSAGE);
   } catch (NullPointerException npe) {
     testRecordData.setStatusCode(StatusCodes.GENERAL_SCRIPT_FAILURE);
     log.logMessage(testRecordData.getFac(), "item not found: " + path, FAILED_MESSAGE);
   }
 }
示例#7
0
  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;
  }
示例#8
0
  /**
   * <br>
   * <em>Purpose:</em> process: process the testRecordData <br>
   * This is our specific version. We subclass the generic CFComponent. The types of objects handled
   * here are '{@link GuiSubitemTestObject}' and '{@link ToggleGUITestObject}'. Path Example:
   * "Admin->Customers..." The actions handled here are: <br>
   *
   * <ul>
   *   <li>selectmenuitem
   *   <li>selectmenuitemcontains
   *   <li>verifymenuitem
   *   <li>verifymenuitemcontains
   * </ul>
   *
   * <br>
   * <br>
   * <em>Side Effects:</em> {@link #testRecordData} statusCode is set based on the result of the
   * processing <br>
   * <em>State Read:</em> {@link #testRecordData}, {@link #params} <br>
   * <em>Assumptions:</em> none
   */
  protected void localProcess() {
    try {
      // then we have to process for specific items not covered by our super
      log.logMessage(
          testRecordData.getFac(),
          getClass().getName() + ".process, searching specific tests...",
          DEBUG_MESSAGE);

      if (action != null) {
        Log.info(
            ".....CFMenuBar.process; ACTION: "
                + action
                + "; win: "
                + windowName
                + "; comp: "
                + compName);
        if ((action.equalsIgnoreCase(SELECTMENUITEM))
            || (action.equalsIgnoreCase(SELECTPOPUPMENUITEM))) {
          selectMenuItem();
        } else if ((action.equalsIgnoreCase(SELECTMENUITEMCONTAINS))) {
          selectMenuItemContains();
        } else if ((action.equalsIgnoreCase(SELECTUNVERIFIEDMENUITEM))) {
          selectUnverifiedMenuItem();
        } else if (action.equalsIgnoreCase(SELECTUNVERIFIEDPOPUPMENUITEM)) {
          selectUnverifiedPopupMenuItem();
        } else if ((action.equalsIgnoreCase(VERIFYMENUITEM))
            || (action.equalsIgnoreCase(VERIFYPOPUPMENUITEM))) {
          verifyMenuItem();
        } else if ((action.equalsIgnoreCase(VERIFYMENUITEMCONTAINS))
            || (action.equalsIgnoreCase(VERIFYPOPUPMENUCONTAINS))
            || (action.equalsIgnoreCase(VERIFYPOPUPMENUPARTIALMATCH))) {
          verifyMenuItemContains();
        } else if (action.equalsIgnoreCase(VERIFYPOPUPMENU)) {
          verifyPopupMenu();
        }
        // all for now
      }
    } catch (com.rational.test.ft.SubitemNotFoundException snfe) {
      testRecordData.setStatusCode(StatusCodes.GENERAL_SCRIPT_FAILURE);
      log.logMessage(
          testRecordData.getFac(),
          "SubitemNotFoundException: " + snfe.getMessage(),
          FAILED_MESSAGE);
    } catch (com.rational.test.ft.ObjectNotFoundException onfe) {
      testRecordData.setStatusCode(StatusCodes.GENERAL_SCRIPT_FAILURE);
      log.logMessage(
          testRecordData.getFac(), "ObjectNotFoundException: " + onfe.getMessage(), FAILED_MESSAGE);
    } catch (SAFSException ex) {
      testRecordData.setStatusCode(StatusCodes.GENERAL_SCRIPT_FAILURE);
      log.logMessage(testRecordData.getFac(), "SAFSException: " + ex.getMessage(), FAILED_MESSAGE);
    } catch (Exception unk) {
      unk.printStackTrace();
      testRecordData.setStatusCode(StatusCodes.GENERAL_SCRIPT_FAILURE);
      log.logMessage(
          testRecordData.getFac(),
          unk.getClass().getName() + ": " + unk.getMessage(),
          FAILED_MESSAGE);
    }
  }
示例#9
0
文件: WDSPC.java 项目: SAFSDEV/Core
  public boolean highlight(SPCTreeNode node) {
    String dbgmsg = "WDSPC.highlight ";
    String xpath = node.xpath;
    String scriptCommand = null;
    boolean highlighted = true;

    // CANAGL attempt at setFocus()?
    try {
      selenium.manage().window().setPosition(selenium.manage().window().getPosition());
    } catch (NullPointerException ignore) {
      if (selenium == null) {
        Log.warn(dbgmsg + "did not find a non-null selenium WebDriver to focus!");
      } else {
        Log.warn(
            dbgmsg
                + "did not find a non-null WebDriver window() to manage() for get/set Position!");
      }
    }

    try {
      String rs = node.getRecognitionString();
      if (rs == null || rs.length() == 0) {
        Log.debug(dbgmsg + "did not find stored recognition string. Switching to XPATH.");
        rs = "XPATH=" + xpath;
      }
      utils.setWDTimeoutLock();
      utils.setWDTimeout(0);

      WebElement item = SearchObject.getObject(rs);
      if (item == null) {
        Log.debug(dbgmsg + "did not find the WebElement using recognition string: " + rs);
        return false;
      }
      highlighted = SearchObject.highlight(item);

    } catch (Exception e) {
      Log.warn(dbgmsg + e + getClass().getSimpleName() + ": " + e.getMessage());
      highlighted = false;
    } finally {
      utils.resetWDTimeout();
      utils.resetWDTimeoutLock();
    }

    return highlighted;
  }
示例#10
0
 @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;
   }
 }
示例#11
0
 /**
  * Checks to see whether an element is visible in the browser
  *
  * @param locator xpath of the element to be check
  * @return whether the element is visible
  */
 private boolean compIsVisible(String locator) {
   boolean isShowing = false;
   try {
     isShowing = selenium.isVisible(locator);
   } catch (RuntimeException rx) {
     Log.debug("Selenium.compIsVisible RuntimeException ignored (false).");
   }
   return isShowing;
 }
示例#12
0
  /** 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);
      }
    }
  }
示例#13
0
 static {
   try {
     robot = new java.awt.Robot();
     Log.debug("Selenium CFComponent awt.Robot =" + robot);
   } catch (Exception x) {
     Log.debug("Selenium CFComponent awt.Robot instantiation exception:", x);
   }
   try {
     InputStream stream =
         ClassLoader.getSystemResourceAsStream(
             CreateUnicodeMap.DEFAULT_FILE + CreateUnicodeMap.DEFAULT_FILE_EXT);
     // InputStream stream = CFComponent.class.getResourceAsStream(CreateUnicodeMap.DEFAULT_FILE +
     // CreateUnicodeMap.DEFAULT_FILE_EXT);
     INIFileReader reader = new INIFileReader(stream, 0, false);
     Log.debug("Selenium CFComponent INIFileReader=" + reader);
     keysparser = new InputKeysParser(reader);
     Log.debug("Selenium CFComponent InputKeysParser=" + keysparser);
   } catch (Exception x) {
     Log.debug("Selenium CFComponent INI Reader or parser instantiation exception:", x);
   }
 }
示例#14
0
 /**
  * Scrolls to a component then left clicks on it.
  *
  * @param o component to be clicked
  */
 protected void scrollToAndClickComponent(SGuiObject o) {
   scrollToComponent(o);
   Rectangle compRect = getComponentBounds(o);
   try {
     robot.mouseMove((int) compRect.getCenterX(), (int) compRect.getCenterY());
     robot.mousePress(KeyEvent.BUTTON1_MASK);
     robot.mouseRelease(KeyEvent.BUTTON1_MASK);
     testRecordData.setStatusCode(StatusCodes.NO_SCRIPT_FAILURE);
   } catch (NullPointerException npe) {
     Log.debug("IGNORING Selenium NPE for scrollToAndClick '" + o.getWindowId() + "':", npe);
     testRecordData.setStatusCode(StatusCodes.NO_SCRIPT_FAILURE);
   }
 }
示例#15
0
  /**
   * <em>Purpose:</em> Remove the content from an input box.<br>
   *
   * @param _comp
   */
  private void clearText(SGuiObject _comp) {
    String debugmsg = getClass().getName() + ".clearText(): ";

    try {
      selenium.type(_comp.getLocator(), "");
    } catch (Exception e) {
      Log.debug(debugmsg + " Exception occur. " + e.getMessage());
      selenium.click(_comp.getLocator());
      RobotKeyEvent.doKeystrokes(keysparser.parseInput("^a{ExtDelete}"), robot, 0);
      // RobotKeyEvent.doKeystrokes(keysparser.parseInput("{ExtHome}+{ExtEnd}{ExtDelete}"), robot,
      // 0);
    }
  }
示例#16
0
 /**
  * @param guiObj, TestObject may be JMenuBar or JPopupMenu
  * @param path, String is the full path of some MenuItem on which a click action will take place
  * @param fuzzy, boolean, If true, we will do a non-exact verification of existance of path
  */
 protected void selectMenuItemWithVerification(
     GuiSubitemTestObject guiObj, String path, boolean fuzzy) {
   MenuTree atree = null;
   try {
     atree = (MenuTree) extractMenuItems(guiObj, 0);
     log.logMessage(testRecordData.getFac(), "atree: " + atree, DEBUG_MESSAGE);
     // Do the work of matching..., verify the path
     // If fuzzy is true, do the partial match; otherwise do the exact match
     String match = atree.matchPath(path, fuzzy, null);
     if (match != null) {
       log.logMessage(testRecordData.getFac(), "match: " + match, DEBUG_MESSAGE);
       com.rational.test.ft.script.List slist = Script.localAtPath(match);
       try {
         guiObj.click(slist);
         // set status to ok
         testRecordData.setStatusCode(StatusCodes.OK);
         String altText =
             "MenuItem \"" + match + "\" clicked, " + windowName + ":" + compName + " " + action;
         log.logMessage(
             testRecordData.getFac(),
             passedText.convert(PRE_TXT_SUCCESS_4, altText, match, windowName, compName, action),
             PASSED_MESSAGE);
       } catch (TargetGoneException tge) {
         Log.info(
             "CFMenuBar IGNORING TargetGoneException probably resulting from intended window closure...");
         // set status to ok
         testRecordData.setStatusCode(StatusCodes.OK);
         String altText =
             "MenuItem \"" + match + "\" clicked, " + windowName + ":" + compName + " " + action;
         log.logMessage(
             testRecordData.getFac(),
             passedText.convert(PRE_TXT_SUCCESS_4, altText, match, windowName, compName, action),
             PASSED_MESSAGE);
       } catch (NullPointerException npe) {
         testRecordData.setStatusCode(StatusCodes.GENERAL_SCRIPT_FAILURE);
         log.logMessage(testRecordData.getFac(), "item not found: " + path, FAILED_MESSAGE);
       }
     } else {
       testRecordData.setStatusCode(StatusCodes.GENERAL_SCRIPT_FAILURE);
       log.logMessage(
           testRecordData.getFac(),
           getClass().getName() + ": no match on: " + path,
           FAILED_MESSAGE);
     }
   } catch (SAFSException se) {
     testRecordData.setStatusCode(StatusCodes.GENERAL_SCRIPT_FAILURE);
     log.logMessage(
         testRecordData.getFac(), getClass().getName() + ": " + se.getMessage(), FAILED_MESSAGE);
   }
 }
示例#17
0
  /**
   * <br>
   * <em>Purpose:</em> Select a menuItem <br>
   * <br>
   * We use an equivalent of this to accomplish the select:
   * jmbMenuBar().click(atPath("Admin->Customers..."));
   *
   * @param menuObj -- GuiSubItemTestObject representing a JMenuBar or JPopupMenu or JMenuItem or
   *     JMenu or MainMenu, MenuItem, MenuStrip, and ToolStripMenuItem
   * @param menuItemPath -- String, path information to the final JMenu or JMenuItem or MenuItem or
   *     ToolStripMenuItem to be selected.
   * @param fuzzy -- If false, match the given path exactly with the Menu. This parameter will not
   *     be used if verify is false.
   * @param verify -- If true, verify existance of path before selecting.
   * @exception SAFSException
   */
  protected void selectMenuBar(
      TestObject menuObj, String menuItemPath, boolean fuzzy, boolean verify) throws SAFSException {

    String debugMsg = getClass().getName() + ".selectMenuBar(): ";

    // Create a new StringBuffer path to store the full path when calling getSubMenuItemFullPath()
    StringBuffer path = new StringBuffer(menuItemPath);

    GuiSubitemTestObject guiObj = null;
    // If the object is a sub-menu,
    // try to get the test proxy object of "MenuBar" or "PopupMenu" and get the full path.
    if (!isMenuBar(menuObj)) {
      Log.debug(
          debugMsg
              + "JSAFSBefore get full path: "
              + menuObj.getObjectClassName()
              + " $$ path="
              + path);
      guiObj = getSubMenuItemFullPath(menuObj, path);
      if (guiObj == null) {
        Log.debug(
            debugMsg + "Can not get the test object of 'MenuBar' or 'PopupMenu' for " + menuObj);
        throw new SAFSException("Can not get the test object of 'MenuBar' or 'PopupMenu'.");
      }
      Log.debug(
          debugMsg + "After get full path: " + guiObj.getObjectClassName() + " $$ path=" + path);
    } else {
      guiObj = new GuiSubitemTestObject(menuObj.getObjectReference());
    }
    // Check the existance of path
    if (verify) {
      selectMenuItemWithVerification(guiObj, path.toString(), fuzzy);
    } else {
      // If we don't verify the existance of path, no need the fuzzy parameter
      selectMenuItemWithoutVerification(guiObj, path.toString());
    }
  }
示例#18
0
  protected Collection<String> captureObjectData() throws SAFSException {
    Collection<String> contents = new ArrayList<String>();

    String prop = PROPERTY_innerText; // this isn't the property for all objects...
    String browser =
        TestRecordHelper.getConfig().getNamedValue(DriverConstant.SECTION_SAFS_SELENIUM, "BROWSER");
    if (!(browser.equals("*iexplore") || browser.equals("*piiexplore"))) {
      prop = PROPERTY_textContent;
    }

    String myClass = getClass().getSimpleName();
    if (myClass.equals("CFList") || myClass.equals("CFComboBox")) {
      prop = PROPERTY_DOT_itemText;
    }

    // Get text from object...
    Object rval = null;
    if (compObject != null) {
      StringBuffer jsScript = new StringBuffer();
      jsScript.append(JavaScriptFunctions.getSAFSgetElementFromXpathFunction());
      jsScript.append(JavaScriptFunctions.getSAFSgetAttributeFunction());
      jsScript.append(" var xpath = \"" + compObject.getLocator() + "\";");
      jsScript.append(" var prop = \"" + prop + "\";");
      jsScript.append(" SAFSgetAttribute(xpath,prop);");
      rval = selenium.getEval(jsScript.toString());
    }
    if (rval == null || rval.equals("null")) {
      throw new SAFSException(
          "read property(" + prop + ") value is null", SAFSException.CODE_CONTENT_ISNULL);
    }

    Log.info("..... real value is: " + rval + ", " + rval.getClass().getName());

    String value = null;
    if (rval instanceof Collection) {
      @SuppressWarnings("rawtypes")
      Iterator ii = ((Collection) rval).iterator();

      while (ii.hasNext()) {
        value = getStringValue(ii.next());
        contents.add(value);
      }
    } else {
      value = getStringValue(rval);
      contents.add(value);
    }

    return contents;
  }
示例#19
0
文件: WDSPC.java 项目: SAFSDEV/Core
 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;
 }
示例#20
0
  /**
   * <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());
        }
      }
    }
  }
示例#21
0
  /** 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.");
      }
    }
  }
示例#22
0
  /**
   * <em>Note:</em> Try to get The value of "text" property of a menuitem. Needed to be overrided
   * for other application than Swing. For example: For java, "text" is the text property. But for
   * .NET, "Text" is.
   *
   * @param menuObj A TestObject represents menu or menuItem.
   * @return The value of "text" property of a menuitem.
   */
  protected String getPropertyText(TestObject menuObject) {
    String debugmsg = getClass().getName() + ".getTextProperty() ";
    String text = "";

    try {
      text = (String) menuObject.getProperty(TEXT_PROPERTY);
    } catch (PropertyNotFoundException x) {
      Log.debug(
          debugmsg
              + x.getMessage()
              + ". Property "
              + TEXT_PROPERTY
              + " not found for"
              + menuObject.getObjectClassName());
    }

    return text;
  }
示例#23
0
  /**
   * @param pathToStatus, String contains "path=status". Example: "File->Open=Enabled"
   * @return Map, contains path as key and status as value
   */
  protected Map convertToMap(List pathToStatusList) {
    String debugmsg = getClass().getName() + ".convertToMap() ";
    Map map = new HashMap();
    String pathStatus = null;
    StringTokenizer tokens = null;

    for (int i = 0; i < pathToStatusList.size(); i++) {
      pathStatus = pathToStatusList.get(i).toString();
      if (pathStatus.contains(Tree.EQUAL_SEPARATOR)) {
        tokens = new StringTokenizer(pathStatus, Tree.EQUAL_SEPARATOR);
        map.put(tokens.nextToken(), tokens.nextToken());
      } else {
        Log.debug(debugmsg + " Missing status: " + pathStatus);
      }
    }

    return map;
  }
示例#24
0
文件: WDSPC.java 项目: SAFSDEV/Core
 public BufferedImage getCurrentPreview() {
   String imagepath = null;
   // let UI settle
   try {
     Thread.sleep(700);
   } catch (Exception x) {
   }
   try {
     imagepath = File.createTempFile("WDSPCBrowser", "png").getAbsolutePath();
     WDLibrary.captureScreen(imagepath);
     ii = ImageIO.read(new File(imagepath));
   } catch (Exception x) {
     Log.debug(
         "WDSPC.getAllElements getScreenshot "
             + x.getClass().getSimpleName()
             + ", "
             + x.getMessage());
   }
   return ii;
 }
示例#25
0
  /**
   * @param menuObject
   * @return True if the menuObject is a popupMenu; False otherwise.
   * @throws SAFSException
   */
  protected boolean isPopupMenu(TestObject menuObject) throws SAFSException {
    String debugmsg = getClass().getName() + ".isPopupMenu() ";
    boolean isMenuBar = false;

    String ui = null;
    try {
      ui = (String) menuObject.getProperty(UITYPE_PROPERTY);
    } catch (PropertyNotFoundException x) {
      Log.debug(
          debugmsg
              + x.getMessage()
              + ". Property "
              + UITYPE_PROPERTY
              + " not found for"
              + menuObject.getObjectClassName());
      throw new SAFSException(
          "Property " + UITYPE_PROPERTY + " not found for" + menuObject.getObjectClassName());
    }

    isMenuBar = UITYPE_POPUPMENU.equalsIgnoreCase(ui);

    return isMenuBar;
  }
示例#26
0
  /**
   * <em>Note:</em> Needed to be override in subclass. "uIClassID" is a property specific for java
   * swing object, we use this property to test what UI Component it is. This can only work for
   * swing.
   *
   * @param menuObject A TestObject represents a MenuBar or PopupMenu or Menu or MenuItem
   * @return True if the TestObject is MenuBar or PopupMenu. False otherwise.
   * @throws SAFSException
   */
  protected boolean isMenuBar(TestObject menuObject) throws SAFSException {
    String debugmsg = getClass().getName() + ".isMenuBar() ";
    boolean isMenuBar = false;

    String ui = null;
    try {
      // Other non-Swing components may not have similar properties
      ui = (String) menuObject.getProperty(UITYPE_PROPERTY);
    } catch (PropertyNotFoundException x) {
      Log.debug(
          debugmsg
              + x.getMessage()
              + ". Property "
              + UITYPE_PROPERTY
              + " not found for"
              + menuObject.getObjectClassName());
      throw new SAFSException(
          "Property " + UITYPE_PROPERTY + " not found for" + menuObject.getObjectClassName());
    }

    isMenuBar = UITYPE_MENUBAR.equalsIgnoreCase(ui) || UITYPE_POPUPMENU.equalsIgnoreCase(ui);

    return isMenuBar;
  }
示例#27
0
文件: WDSPC.java 项目: SAFSDEV/Core
  public void getAllChildElements(final WebElement parentElement, final String parentNode) {
    Log.info("WDSPC.getAllChildElements blocked by runningWindowChecker...");
    while (runningWindowChecker) ;
    Log.info("WDSPC.getAllChildElements proceeding...");
    stopthread = false;
    (new Thread() {
          public void run() {
            runningGetAllElements = true;
            Log.info("WDSPC.getAllChildElements set runningGetAllElements TRUE...");
            selenium = WDLibrary.getWebDriver();
            SGuiObject sgo = new SGuiObject("", "", WDLibrary.getIDForWebDriver(selenium), false);
            List<WebElement> data = null;
            try {
              Log.info("WDSPC.getAllChildElements calling WebDriver findElements()...");
              data = parentElement.findElements(By.xpath(".//*"));
            } catch (Exception e) {
              Log.debug("WDSPC findElements() Exception:", e);
              runningGetAllElements = false;
              return;
            }

            if (!data.isEmpty()) {
              Log.info(
                  "WDSPC.getAllChildElements found "
                      + data.size()
                      + " elements. Attempting XPaths...");
              // get the xpaths to each element
              try {
                utils.setWDTimeoutLock();
                utils.setWDTimeout(0);
                // List<String> paths = new ArrayList();
                // List<WebElement> retained = new ArrayList();
                WebElement e = null;
                String t = null;
                String rec = null;
                // SearchObject.resetXPathObjectCache();
                for (int i = 0; i < data.size() && !stopthread; i++) {
                  try {
                    e = data.get(i);
                    t = e.getTagName();
                    if (!SearchObject.isIgnoredNonUITag(t)) {
                      rec = SearchObject.generateFullGenericXPath(e);
                      spcGUI.insertComponentInTree(e, rec, parentNode);
                      // retained.add(e);
                      // paths.add(SearchObject.generateFullGenericXPath(e));
                    }
                  } catch (Exception x) {
                    Log.debug(
                        "WDSPC.getAllChildElements ignoring "
                            + x.getClass().getSimpleName()
                            + ": "
                            + x.getMessage());
                  }
                }
                // SearchObject.resetXPathObjectCache();
                // spcGUI.updateData(retained, paths);
                runningGetAllElements = false;
                Log.info("WDSPC getAllChildElements set runningGetAllElements FALSE...");
              } catch (Throwable t) {
                Log.info(
                    "WDSPC getAllChildElements "
                        + t.getClass().getSimpleName()
                        + ": "
                        + t.getMessage());
              } finally {
                utils.resetWDTimeout();
                utils.resetWDTimeoutLock();
              }
            } else {
              runningGetAllElements = false;
              Log.info("WDSPC getAllChildElements set runningGetAllElements FALSE...");
              Log.debug(
                  "WDSPC getAllChildElements was interrupted, or otherwise found 0 Elements.");
            }
            spcGUI.setGUIForReady();
          }
        })
        .start();
  }
示例#28
0
文件: WDSPC.java 项目: SAFSDEV/Core
  public void getAllElements(String title, final String frameRS) {
    Log.info("WDSPC getAllElements blocked by runningWindowChecker...");
    while (runningWindowChecker) ;
    Log.info("WDSPC getAllElements proceeding...");
    final String t2;
    if (title.equals("")) {
      t2 = selenium.getTitle(); // what if selenium is null? can it be?
    } else {
      t2 = title;
    }
    stopthread = false;
    (new Thread() {
          public void run() {
            runningGetAllElements = true;
            Log.info("WDSPC getAllElements set runningGetAllElements TRUE...");
            try {
              selenium = WDLibrary.getBrowserWithTitle(t2);
            } catch (SeleniumPlusException ignore) {
              Log.info(
                  "WDSPC getAllElements proceeding with existing WebDriver due to: "
                      + ignore.getMessage());
            }
            SGuiObject sgo = new SGuiObject("", "", WDLibrary.getIDForWebDriver(selenium), false);

            List<WebElement> data = null;
            try {
              TargetLocator locator = selenium.switchTo();
              locator.defaultContent();
              if (frameRS == null || frameRS.trim().isEmpty()) {
                // clear the 'last frame', so that the component will be searched on default html
                // document
                SearchObject.setLastFrame(null);
              } else {
                // String[] st = StringUtils.getTokenArray(frameRS, SearchObject.childSeparator,
                // SearchObject.escapeChar);
                SearchObject.switchFrame(selenium, frameRS);
              }

              Log.info("WDSPC calling WebDriver findElements()...");
              data = selenium.findElements(By.xpath("//*"));
            } catch (Exception e) {
              Log.debug("WDSPC findElements() Exception:", e);
              runningGetAllElements = false;
              return;
            }

            if (!data.isEmpty()) {
              Log.info(
                  "WDSPC getAllElements found " + data.size() + " elements. Attempting XPaths...");
              // get the xpaths to each element
              try {
                utils.setWDTimeoutLock();
                utils.setWDTimeout(0);
                List<String> paths = new ArrayList();
                List<WebElement> retained = new ArrayList();
                WebElement e = null;
                String t = null;
                String info = null;
                SearchObject.resetXPathObjectCache();
                for (int i = 0; i < data.size() && !stopthread; i++) {
                  try {
                    e = data.get(i);
                    t = e.getTagName();
                    if (!SearchObject.isIgnoredNonUITag(t)) {
                      if (spcGUI.useVisibleOnly() && !e.isDisplayed()) continue;
                      info = SearchObject.generateGenericXPath(e);
                      if (t.equalsIgnoreCase(SearchObject.TAG_FRAME)
                          || t.equalsIgnoreCase(SearchObject.TAG_IFRAME)) {
                        String frameRS = SearchObject.generateSAFSFrameRecognition(info);
                        if (spcGUI.addFrameRS(frameRS)) {
                          spcGUI.addFrameRSToCache(
                              e, info, (String) spcGUI.jcb_curwindows.getSelectedItem());
                        }
                      }
                      paths.add(SearchObject.generateFullGenericXPath(e));
                      spcGUI.setStatus(info, null);
                      retained.add(e);
                    }
                  } catch (Exception x) {
                    Log.debug(
                        "WDSPC getAllElements ignoring "
                            + x.getClass().getSimpleName()
                            + ": "
                            + x.getMessage(),
                        x);
                  }
                }
                SearchObject.resetXPathObjectCache();

                // TODO handle actual Frames
                spcGUI.updateData(null, retained, paths);

                runningGetAllElements = false;
                Log.info("WDSPC getAllElements set runningGetAllElements FALSE...");
              } catch (Throwable t) {
                Log.info(
                    "WDSPC getAllElements " + t.getClass().getSimpleName() + ": " + t.getMessage(),
                    t);
              } finally {
                utils.resetWDTimeout();
                utils.resetWDTimeoutLock();
              }
            } else {
              runningGetAllElements = false;
              Log.info("WDSPC getAllElements set runningGetAllElements FALSE...");
              Log.debug("WDSPC getAllElements was interrupted, or otherwise found 0 Elements.");
            }
          }
        })
        .start();
  }
示例#29
0
  /**
   * <b>Purpose:</b> Verify the complete status of the current popup menu with a benchmark file.
   *
   * @throws SAFSException
   */
  protected void verifyPopupMenu() throws SAFSException {
    String debugmsg = getClass().getName() + ".verifyPopupMenu() ";
    String benchFileName = null, headerString = null, testFileName = null, diffFileName = null;

    // Analyse the four parameters, three of them are optional
    // benchFileName (required),headerString (optional),testFileName (optional),diffFileName
    // (optional)
    if (params.size() < 1) {
      this.issueParameterCountFailure(
          FAILStrings.convert(
              FAILStrings.BAD_PARAM, "Invalid parameter value for BenchmarkFile", "BenchmarkFile"));
      Log.debug(debugmsg + " Missing parameter of 'benchFileName'!!!");
      return;
    }
    Iterator iter = params.iterator();
    String defaultFileName = iter.next().toString();
    Log.info(debugmsg + " default file name (for bench,test,diff): " + defaultFileName);
    benchFileName = getAbsoluteFileName(defaultFileName, STAFHelper.SAFS_VAR_BENCHDIRECTORY);
    if (iter.hasNext()) headerString = iter.next().toString();
    if (iter.hasNext()) {
      testFileName = iter.next().toString();
      if (testFileName != null && !testFileName.trim().equals("")) {
        testFileName = getAbsoluteFileName(testFileName, STAFHelper.SAFS_VAR_TESTDIRECTORY);
      } else {
        testFileName = getAbsoluteFileName(defaultFileName, STAFHelper.SAFS_VAR_TESTDIRECTORY);
      }
    } else {
      testFileName = getAbsoluteFileName(defaultFileName, STAFHelper.SAFS_VAR_TESTDIRECTORY);
    }
    if (iter.hasNext()) {
      diffFileName = iter.next().toString();
      if (diffFileName != null && !diffFileName.trim().equals("")) {
        diffFileName = getAbsoluteFileName(diffFileName, STAFHelper.SAFS_VAR_DIFDIRECTORY);
      } else {
        diffFileName = getAbsoluteFileName(defaultFileName, STAFHelper.SAFS_VAR_DIFDIRECTORY);
      }
    } else {
      diffFileName = getAbsoluteFileName(defaultFileName, STAFHelper.SAFS_VAR_DIFDIRECTORY);
    }

    // 1.Get the whole sub-tree of the JMenu provided (the third parameter)
    GuiSubitemTestObject guiObj = new GuiSubitemTestObject(obj1.getObjectReference());
    MenuTree tree = (MenuTree) extractMenuItems(guiObj, 0);
    // Get a list which contains all nodes' "path=status"
    List treePathAndStatus = tree.getTreePaths("", true);

    // 2.Stroe the header-file into the test-file
    //	Store the each node's path and it's status of the sub-tree into the "test-file"
    if (headerString != null && !headerString.trim().equals("")) {
      Log.debug(debugmsg + testFileName + " will contains headerString: " + headerString);
      treePathAndStatus.add(0, headerString);
    }
    if (testFileName != null && !testFileName.trim().equals("")) {
      Log.debug(debugmsg + "Menu status will be saved to " + testFileName);
      try {
        StringUtils.writefile(testFileName, treePathAndStatus);
      } catch (IOException e) {
        String detail =
            failedText.convert(
                FAILStrings.FILE_ERROR, "Can not write to " + testFileName, testFileName);
        Log.debug(debugmsg + detail);
        throw new SAFSException(detail);
      }
    }

    // 3.Compare with the bench-file;
    //		If mached, set the testRecord's status to OK.
    //		Otherwise, set the testRecord's status to FAILURE and store the difference to diff-file.
    List benchContents = new ArrayList();
    try {
      benchContents.addAll(StringUtils.readfile(benchFileName));
    } catch (IOException e) {
      String detail =
          failedText.convert(
              FAILStrings.FILE_ERROR, "Can not read " + benchFileName, benchFileName);
      Log.debug(debugmsg + detail);
      throw new SAFSException(detail);
    }
    Log.debug(debugmsg + "BenchFile Menu's status:" + benchContents);
    Log.debug(debugmsg + "Current Menu's status:" + treePathAndStatus);

    // The list differences will contains the difference between current status and bench status
    List differences = new ArrayList();
    if (headerString != null && !headerString.trim().equals("")) {
      Log.debug(debugmsg + "Compare the header line.");
      String benchHeader = benchContents.isEmpty() ? "" : benchContents.remove(0).toString();
      String currentHeader = treePathAndStatus.remove(0).toString();
      Log.debug("benchHeader: " + benchHeader);
      Log.debug("currentHeader: " + currentHeader);
      if (!currentHeader.equalsIgnoreCase(benchHeader)) {
        differences.add(
            "Header different: \n"
                + "benchHeader: "
                + benchHeader
                + "\n"
                + "currentHeader: "
                + currentHeader
                + "\n\n");
      }
    }
    // Convert List to Map which contains path as key and status as value
    Map benchStatusMap = convertToMap(benchContents);
    Map currentStatusMap = convertToMap(treePathAndStatus);
    // I.	If the two maps have the same path and the same status
    // II.	Else If the two maps have the same path but status are different, then write this
    // difference to the list differences.
    //		Finally remove the path from both maps
    Object[] currentPathArray = currentStatusMap.keySet().toArray();
    for (int i = 0; i < currentPathArray.length; i++) {
      String key = currentPathArray[i].toString();
      String benchStatus = null;
      if (benchStatusMap.containsKey(key)) {
        benchStatus = benchStatusMap.get(key).toString();
      } else {
        continue;
      }
      String currentStatus = currentStatusMap.get(key).toString();
      Log.debug("menu path: " + key);
      Log.debug("benchStatusValue: " + benchStatus);
      Log.debug("currentStatusValue: " + currentStatus);
      if (!benchStatus.equalsIgnoreCase(currentStatus)) {
        differences.add(
            "Menu path: "
                + key
                + " has difference: \n"
                + "benchStatus: "
                + benchStatus
                + "\n"
                + "currentStatus: "
                + currentStatus
                + "\n");
      }
      // Finally remove this path from both benchStatusMap and currentStatusMap
      benchStatusMap.remove(key);
      currentStatusMap.remove(key);
    }
    // III.	Else if MenuItem exist only in bench file, write this difference to list differences.
    if (benchStatusMap.size() != 0) {
      differences.add("MenuItem exist only in " + benchFileName);
      Object[] keys = benchStatusMap.keySet().toArray();
      for (int i = 0; i < keys.length; i++) {
        String key = keys[i].toString();
        differences.add("Menu path: " + key + " ##  Status: " + benchStatusMap.get(key));
      }
    }
    // IV.	Else if MenuItem exist only in current menu, write this difference to list differences.
    if (currentStatusMap.size() != 0) {
      differences.add("MenuItem exist only in current menu");
      Object[] keys = currentStatusMap.keySet().toArray();
      for (int i = 0; i < keys.length; i++) {
        String key = keys[i].toString();
        differences.add("Menu path: " + key + " ##  Status: " + currentStatusMap.get(key));
      }
    }

    // If the size of differences is bigger than 0, there are some differences between current
    // status and bench status
    if (differences.size() > 0) {
      testRecordData.setStatusCode(StatusCodes.GENERAL_SCRIPT_FAILURE);
      String detail =
          failedText.convert(
              GENStrings.CONTENT_NOT_MATCHES_KEY,
              "the content of 'Current menu status' does not match the content of '"
                  + benchFileName
                  + "'",
              "Current menu's status",
              benchFileName);
      if (diffFileName != null && !diffFileName.trim().equals("")) {
        try {
          StringUtils.writefile(diffFileName, differences);
          detail +=
              " "
                  + genericText.convert(
                      GENStrings.SEE_DIFFERENCE_FILE,
                      "\n\tPlease see difference in file '" + diffFileName + "'.",
                      diffFileName);
        } catch (IOException e1) {
          String message =
              failedText.convert(
                  FAILStrings.FILE_ERROR, "Can not write to " + diffFileName, diffFileName);
          Log.debug(debugmsg + message);
        }
      }
      componentExecutedFailureMessage(detail);
      return;
    }

    Log.debug(debugmsg + "All status of menu match that of benchfile.");
    String detail =
        genericText.convert(
            GENStrings.CONTENT_MATCHES_KEY,
            "the content of 'Current menu status' matches the content of '" + benchFileName + "'",
            "Current menu's status",
            benchFileName);
    componentSuccessMessage(detail);
    testRecordData.setStatusCode(StatusCodes.OK);
  }
示例#30
0
  /**
   * <br>
   * <em>Purpose:</em> Extract a menu hierarchy from a TestObject; The item is for JMenuBars,
   * JPopupMenus, JMenus, and JMenuItems (JMenu is subclass of JMenuItem). This routine is reentrant
   * until there are no more submenus to process. <br>
   * <em>Assumptions:</em> obj is a MenuBar, PopupMenu, Menu or MenuItem TestObject proxy. <br>
   * <em>Note:</em> For this method works for application other than java-swing, we need to override
   * getSubMenuItemCount(),getPropertyText(),getPropertyTextName(),getNewTreeNode() in the subclass
   * like CFDotNetMenuBar.
   *
   * <p>The following tree show the structure of JMenuBar JMenuBar
   * |____________________________________ | | | JMenu JMenu JMenu ___|___ | | | | JMenuItem JMenu
   * __|__ | | JMenuItem JMenuItem
   *
   * @param obj, Object (TestObject)
   * @param level, what level in the tree are we processing
   * @return org.safs.Tree, the real instance is org.safs.rational.MenuTree
   * @exception SAFSException
   */
  protected Tree extractMenuItems(Object obj, int level) throws SAFSException {

    String debugmsg = getClass().getName() + ".extractMenuItems() ";
    Tree tree = null;
    TestObject[] subitems = null;

    try {
      TestObject tobj = (TestObject) obj;
      Integer itemCount = null;

      if (isPopupMenu(tobj)) {
        subitems = tobj.getMappableChildren();
        itemCount = new Integer(subitems.length);
      } else {
        itemCount = getSubMenuItemCount(tobj);

        // having some problems in V2003
        if (itemCount.intValue() > 0) subitems = tobj.getMappableChildren();
        try {
          itemCount = new Integer(subitems.length);
        } catch (Exception x) {
          itemCount = new Integer(0);
        }
      }

      Tree lastjTree = null;

      for (int j = 0; j < itemCount.intValue(); j++) {
        TestObject gto2 = null;
        try {
          gto2 = subitems[j];
        } catch (ArrayIndexOutOfBoundsException aie) {
          Log.debug(
              "ArrayIndexOutOfBoundsException for level: "
                  + level
                  + ", menuitem: "
                  + j
                  + ", probably your menu has a separator or some other unknown object, continuing...");
          continue;
        }

        String text2 = getPropertyText(gto2);

        // do NOT increment level for what appears to be a SubMenu placeholder
        int inc = (text2 == null) ? 0 : 1;

        Integer itemCount2 = getSubMenuItemCount(gto2);
        if (itemCount2.intValue() == 0) {
          TestObject[] subkids = gto2.getMappableChildren();
          if (subkids != null) itemCount2 = new Integer(subkids.length);
        }

        Log.debug(
            "level "
                + level
                + ": item "
                + j
                + ": "
                + getPropertyTextName()
                + " \""
                + text2
                + "\" "
                + " children: "
                + itemCount2);

        // Use test object to form a tree node
        Tree jtree = new MenuTree();
        MenuTreeNode treeNode = getNewTreeNode(gto2, itemCount.intValue(), itemCount2.intValue());
        jtree.setUserObject(treeNode);

        if (j == 0) tree = jtree;
        else {
          lastjTree.setNextSibling(jtree);
        }

        jtree.setLevel(new Integer(level));
        jtree.setSiblingCount(itemCount);
        jtree.setChildCount(itemCount2);
        if (itemCount2.intValue() > 0) {
          // inc only when a valid new level exists
          Tree subtree = extractMenuItems(gto2, level + inc);
          jtree.setFirstChild(subtree);
        }
        lastjTree = jtree;
      }
    } catch (Exception ee) {
      ee.printStackTrace();
      throw new SAFSException(debugmsg + ": " + ee.getMessage());
    }
    return tree;
  }