When We Should Use KeyPress Instead of setText in Open Script??

Spread the love

Last week (KeyPress) I was testing an application which was based on servlet and client validation was on some javascript most likely ajax.

Scenario::
A customer needed to fill up a form for signup.As usual it was having First name,Last name,Address,City,Country, Mobile No.

What I did ??
I tried to record the scenario. While recording OATS recorded all the text filed with setText() method. Script looked cool.

But??
While playing back,It did fill up the form but application was throwing error. It was saying that all fields were mandatory and user needed to fill it.

Findings:
I noticed there was a ajax call which was sensing the key press event and trying to read the record on focus change.So manually when I tried to reproduce the case,application was behaving correctly. I changed the setText() method to keyPress() method and instead of clicking on the next field. I pressed TAB key. It worked!!!!.

 

 

  • I general form fill up, When we click on submit button,all text filed data go to server. In this case we can use setText()
  • In a case where application directly does not read the user input via a submit button. Rather it reads on keyPress or keyUp[Nothing but a javascript (ajax call).]And process data accordingly. We must use keyPress()
  • There should not be any space in data inside keyPress() method. Like keyPress(“Test1234”) is valid but keyPress(“Test 1234”) is Invalid
  • setText does a copy paste operation. So in such places where copy paste is prohibited we must use keyPress.


Spread the love
READ  Oracle Open Script –Supported features

12 thoughts on “When We Should Use KeyPress Instead of setText in Open Script??”

  1. How to use inputs with space or some special charecters like @,_,. Ex: I have email id field where inputs contains (@) and (.) chars. I am able to handle @ by using "" in keypress method but unable to handle underscore and dot charecters.Please help

  2. myDigital Voice

    public void upload_parseChars(String letter, Robot robot) throws AbstractScriptException {
    for (int i = 0; i < letter.length(); i++) {
    //info("inside uf_Vik_parseChars method ");
    char chary = letter.charAt(i);
    //info("Current character = "+letter.charAt(i));
    upld_typeCharacter(Character.toString(chary), robot);
    }
    }

  3. myDigital Voice

    public void upld_typeCharacter(String letter, Robot robot) throws AbstractScriptException {
    // info("Pressed event ");
    if (Character.isLetterOrDigit(letter.charAt(0))) {
    try {
    boolean upperCase = Character.isUpperCase(letter.charAt(0));
    String variableName = "VK_" + letter.toUpperCase();
    KeyEvent ke = new KeyEvent(new JTextField(), 0, 0, 0, 0, ' ');
    @SuppressWarnings("rawtypes")
    Class clazz = ke.getClass();
    Field field = clazz.getField(variableName);
    int keyCode = field.getInt(ke);
    robot.delay(80);
    if (upperCase)
    robot.keyPress(KeyEvent.VK_SHIFT);
    robot.keyPress(keyCode);
    robot.keyRelease(keyCode);

  4. myDigital Voice

    if (upperCase)
    robot.keyRelease(KeyEvent.VK_SHIFT);
    } catch (Exception e) {
    System.out.println(e);
    }
    } else {
    if (letter.equals("!")) {
    robot.keyPress(KeyEvent.VK_SHIFT);
    robot.keyPress(KeyEvent.VK_1);
    robot.keyRelease(KeyEvent.VK_1);
    robot.keyRelease(KeyEvent.VK_SHIFT);
    } else if (letter.equals("@")) {
    robot.keyPress(KeyEvent.VK_SHIFT);
    robot.keyPress(KeyEvent.VK_2);
    robot.keyRelease(KeyEvent.VK_2);
    robot.keyRelease(KeyEvent.VK_SHIFT);
    } else if (letter.equals("#")) {
    robot.keyPress(KeyEvent.VK_SHIFT);
    robot.keyPress(KeyEvent.VK_3);
    robot.keyRelease(KeyEvent.VK_3);
    robot.keyRelease(KeyEvent.VK_SHIFT);
    } else if (letter.equals("#")) {
    robot.keyPress(KeyEvent.VK_SHIFT);
    robot.keyPress(KeyEvent.VK_3);
    robot.keyRelease(KeyEvent.VK_3);
    robot.keyRelease(KeyEvent.VK_SHIFT);
    } else if (letter.equals("$")) {
    robot.keyPress(KeyEvent.VK_SHIFT);
    robot.keyPress(KeyEvent.VK_4);
    robot.keyRelease(KeyEvent.VK_4);
    robot.keyRelease(KeyEvent.VK_SHIFT);
    } else if (letter.equals("%")) {
    robot.keyPress(KeyEvent.VK_SHIFT);
    robot.keyPress(KeyEvent.VK_5);
    robot.keyRelease(KeyEvent.VK_5);
    robot.keyRelease(KeyEvent.VK_SHIFT);
    } else if (letter.equals("^")) {
    robot.keyPress(KeyEvent.VK_SHIFT);
    robot.keyPress(KeyEvent.VK_6);
    robot.keyRelease(KeyEvent.VK_6);
    robot.keyRelease(KeyEvent.VK_SHIFT);
    } else if (letter.equals("&")) {
    robot.keyPress(KeyEvent.VK_SHIFT);
    robot.keyPress(KeyEvent.VK_7);
    robot.keyRelease(KeyEvent.VK_7);
    robot.keyRelease(KeyEvent.VK_SHIFT);

  5. myDigital Voice

    } else if (letter.equals("*")) {
    robot.keyPress(KeyEvent.VK_SHIFT);
    robot.keyPress(KeyEvent.VK_8);
    robot.keyRelease(KeyEvent.VK_8);
    robot.keyRelease(KeyEvent.VK_SHIFT);
    } else if (letter.equals("=")) {
    robot.keyPress(KeyEvent.VK_EQUALS);
    robot.keyRelease(KeyEvent.VK_EQUALS);
    } else if (letter.equals(" ")) {
    robot.keyPress(KeyEvent.VK_SPACE);
    robot.keyRelease(KeyEvent.VK_SPACE);
    } else if (letter.equals("/")) {
    robot.keyPress(KeyEvent.VK_BACK_SLASH);
    robot.keyRelease(KeyEvent.VK_BACK_SLASH);
    } else if (letter.equals("\")) {
    robot.keyPress(KeyEvent.VK_BACK_SLASH);
    robot.keyRelease(KeyEvent.VK_BACK_SLASH);
    } else if (letter.equals("_")) {
    robot.keyPress(KeyEvent.VK_SHIFT);
    robot.keyPress(KeyEvent.VK_MINUS);
    robot.keyRelease(KeyEvent.VK_MINUS);
    robot.keyRelease(KeyEvent.VK_SHIFT);
    } else if (letter.equals(":")) {
    robot.keyPress(KeyEvent.VK_SHIFT);
    robot.keyPress(KeyEvent.VK_SEMICOLON);
    robot.keyRelease(KeyEvent.VK_SEMICOLON);
    robot.keyRelease(KeyEvent.VK_SHIFT);
    } else if (letter.equals(";")) {
    robot.keyPress(KeyEvent.VK_SEMICOLON);
    robot.keyRelease(KeyEvent.VK_SEMICOLON);
    } else if (letter.equals(",")) {
    robot.keyPress(KeyEvent.VK_COMMA);
    robot.keyRelease(KeyEvent.VK_COMMA);
    } else if (letter.equals("-")) {
    robot.keyPress(KeyEvent.VK_SHIFT);
    robot.keyPress(KeyEvent.VK_SUBTRACT);
    robot.keyRelease(KeyEvent.VK_SUBTRACT);
    robot.keyRelease(KeyEvent.VK_SHIFT);
    } else if (letter.equals("?")) {
    robot.keyPress(KeyEvent.VK_SHIFT);
    robot.keyPress(KeyEvent.VK_SLASH);
    robot.keyRelease(KeyEvent.VK_SLASH);
    robot.keyRelease(KeyEvent.VK_SHIFT);
    } else if (letter.equals(" ")) {
    robot.keyPress(KeyEvent.VK_SPACE);
    robot.keyRelease(KeyEvent.VK_SPACE);
    } else if (letter.equals(".")) {
    robot.keyPress(KeyEvent.VK_PERIOD);
    robot.keyRelease(KeyEvent.VK_PERIOD);
    }

    }
    }

  6. Heya i’m for the first time here. I came across this board
    and I find It truly useful & it helped me out much.
    I hope to give something back and help others like you aided me.

  7. It’s a shame you don’t have a donate button! I’d most certainly
    donate to this superb blog! I guess for now i’ll settle
    for bookmarking and adding your RSS feed to my Google account.
    I look forward to brand new updates and will talk about this site with my Facebook
    group. Chat soon!

  8. dortheamackintosh

    Everything published was actually very logical.
    However, think on this, suppose you were to create a awesome post title?
    I ain’t saying your information isn’t solid., but suppose you added a headline that makes
    people desire more? I mean When We Should Use KeyPress Instead of setText in Open Script??

    – Tech Travel Hub is kinda vanilla. You could peek at Yahoo’s front page and watch how
    they create article headlines to grab viewers to open the links.

    You might add a video or a related picture or two to get people interested about what you’ve got to say.

    In my opinion, it would bring your posts a little bit more
    interesting.

  9. After looking over a number of the blog posts on your web page, I honestly like your technique of blogging.
    I book marked it to my bookmark webpage list and will be checking back soon. Please check out my website too and let me know what you think.

  10. Hello! I just would like to offer you a huge thumbs up for your excellent info you
    have got here on this post. I will be coming back to your website for
    more soon.

Leave a Comment

Your email address will not be published. Required fields are marked *