Exemple #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;
  }
Exemple #2
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;
  }
Exemple #3
0
  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;
  }
Exemple #4
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());
        }
      }
    }
  }
Exemple #5
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.");
      }
    }
  }
Exemple #6
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);
      }
    }
  }
Exemple #7
0
  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);
    }
  }
Exemple #8
0
 private void setFocusToWindow() throws SAFSException {
   if (!sUtils.setWindowFocus(winObject.getWindowId(), selenium)) {
     Log.warn("Not able to focus window: " + testRecordData.getWindowGuiId());
   }
 }