コード例 #1
0
ファイル: CFMenuBar.java プロジェクト: SAFSDEV/Core
  /**
   * @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;
  }
コード例 #2
0
ファイル: CFComponent.java プロジェクト: SAFSDEV/Core
  /**
   * <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());
        }
      }
    }
  }
コード例 #3
0
ファイル: CFComponent.java プロジェクト: SAFSDEV/Core
  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;
  }
コード例 #4
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());
 }
コード例 #5
0
ファイル: CFMenuBar.java プロジェクト: SAFSDEV/Core
  /**
   * 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
ファイル: 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;
  }
コード例 #7
0
ファイル: CFComponent.java プロジェクト: SAFSDEV/Core
 @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;
   }
 }
コード例 #8
0
ファイル: CFComponent.java プロジェクト: SAFSDEV/Core
 /**
  * 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;
 }
コード例 #9
0
ファイル: CFComponent.java プロジェクト: SAFSDEV/Core
 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);
   }
 }
コード例 #10
0
ファイル: CFComponent.java プロジェクト: SAFSDEV/Core
  /**
   * <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);
    }
  }
コード例 #11
0
ファイル: CFComponent.java プロジェクト: SAFSDEV/Core
 /**
  * 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);
   }
 }
コード例 #12
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;
 }
コード例 #13
0
ファイル: CFMenuBar.java プロジェクト: SAFSDEV/Core
  /**
   * <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());
    }
  }
コード例 #14
0
ファイル: CFMenuBar.java プロジェクト: SAFSDEV/Core
  /**
   * @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;
  }
コード例 #15
0
ファイル: CFMenuBar.java プロジェクト: SAFSDEV/Core
  /**
   * <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;
  }
コード例 #16
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;
 }
コード例 #17
0
ファイル: CFMenuBar.java プロジェクト: SAFSDEV/Core
  /**
   * @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;
  }
コード例 #18
0
ファイル: CFMenuBar.java プロジェクト: SAFSDEV/Core
  /**
   * <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;
  }
コード例 #19
0
ファイル: CFMenuBar.java プロジェクト: SAFSDEV/Core
  /**
   * <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);
  }
コード例 #20
0
ファイル: CFMenuBar.java プロジェクト: SAFSDEV/Core
  /**
   * <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;
  }
コード例 #21
0
ファイル: CFComponent.java プロジェクト: SAFSDEV/Core
  /**
   * <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);
    }
  }
コード例 #22
0
ファイル: CFComponent.java プロジェクト: SAFSDEV/Core
  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);
    }
  }