Search This Blog

Thursday, January 31, 2013

#MonkeyRunner : Delete Text on EditText

Now my job is about writing script for doing auto-testing using Monkey runner.
I found the way to delete text that has been entered inside Edittext. Here is the code ...

    # Max text length
    fieldLength = 100
    

    # Select all the chars on the right
    dev.press('KEYCODE_SHIFT_RIGHT', MonkeyDevice.DOWN)
    for i in range(fieldLength):
             dev.press('KEYCODE_DPAD_RIGHT', MonkeyDevice.DOWN_AND_UP)
         #MonkeyRunner.sleep(1)
      dev.press('KEYCODE_SHIFT_RIGHT', MonkeyDevice.UP)
    # Delete them
    dev.press('KEYCODE_DEL', MonkeyDevice.DOWN_AND_UP)
   
    # Select all the chars on the left
    dev.press('KEYCODE_SHIFT_LEFT', MonkeyDevice.DOWN)
    for i in range(fieldLength):
             dev.press('KEYCODE_DPAD_LEFT', MonkeyDevice.DOWN_AND_UP)
         #MonkeyRunner.sleep(1)
      dev.press('KEYCODE_SHIFT_LEFT', MonkeyDevice.UP)
    # Delete them
    dev.press('KEYCODE_DEL', MonkeyDevice.DOWN_AND_UP)


By running above script, it will select text and drag to the right then delete it. Afterthat it will select text and drag to the left and delete to make sure all text is clear.

Hope it helps...

No comments:

Post a Comment