• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Dave Alvarado
Ranch Hand
Posts: 436
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Dave Alvarado
Ranch Hand
Posts: 436
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 436
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic