aspose file tools*
The moose likes Testing and the fly likes JWebUnit: How do I simulate clicking enter in a text field? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Testing
Bookmark "JWebUnit: How do I simulate clicking enter in a text field?" Watch "JWebUnit: How do I simulate clicking enter in a text field?" New topic
Author

JWebUnit: How do I simulate clicking enter in a text field?

Dave Alvarado
Ranch Hand

Joined: Jul 02, 2008
Posts: 436
Hi,

I'm using the latest version of JWebUnit-HtmlUnit plugin (2.2) along with Maven 2.2 to run some test cases. My question is, how do I simulate a user clicking the "Enter" key when inside a text field? I'm trying to write a test case for clicking enter to see if it acts like clicking the Submit button on my page.

Thanks, - Dave
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41859
    
  63
No, I don't think JWebUnit can do that; it'd be browser-specific anyway.

Hitting enter in a text field causes a form submit - not a click on the submit button. So the only difference would be if the click on the submit button does something beside simply submitting the form.


Ping & DNS - my free Android networking tools app
Dave Alvarado
Ranch Hand

Joined: Jul 02, 2008
Posts: 436
In my web page, I have tied an "onkeypress" event handler to the text field, and if I detect an enter key, I call a Javascript function that simulates clicking the submit button. So any way JWebUnit can invoke that event handler?

Thanks, - Dave
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41859
    
  63
Why the JavaScript? Unless you do something special to prevent it, most forms submit automatically if you hit the enter key in a text field.
Dave Alvarado
Ranch Hand

Joined: Jul 02, 2008
Posts: 436
I need the JS because there are two type=submit buttons on the page, and the first one is a "Cancel" button, so clicking "Enter" executes the Cancel action, which I do not want.

Getting back to the original question, do you know how I can get JWebUnit to execute Javascript, or at least, the event handlers associated with buttons?

Thanks, - Dave
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JWebUnit: How do I simulate clicking enter in a text field?