|
|
|
[
Permlink
| « Hide
]
Dan Fabulich - 22/Nov/06 01:03 PM
This would also be nice for clicking on browser security pop-ups and bringing up the browser's context menu.
How about this for an implementation?
1) Use the Robot library built into Java (java.awt.Robot) to send OS-level keystrokes and mouse events Note: If the locator argument is an empty string (""), then it is assumed it will just "blindly" type the keyboard events. The keys will be sent (though only incidentally) to the window that has the focus. In the future, if Selenium ever gains native OS widget recognition, perhaps we could properly do something like this: Hmmm... "KeyboardAndMouse" are a bit wordy...
How about: and for typeKeys, how about: The "window" locator is already a valid dom expression, so that's nice... Also, I'd like to reuse Microsoft's "SendKeys" API for the syntax of sending keys. Read here for more info: http://msdn2.microsoft.com/en-us/library/8c6yea83.aspx I checked in a basically working version of this in revision 2061. I didn't follow Jason's suggestion re: the formatting of the commands because that would require coordinating state between the JS browser and the server, making the implementation much more complicated.
Instead, I implemented separate keyDownNative, keyUpNative and keyPressNative commands that do not accept element locators, and require you to pass in integer java.awt.event.KeyEvent keycodes. http://java.sun.com/javase/6/docs/api/java/awt/event/KeyEvent.html These commands do not support the regular shiftKeyDown, altKeyDown, metaKeyDown and controlKeyDown commands; instead you have to separately send a keyDownNative(KeyEvent.VK_SHIFT) to hold down shift in a "native" way. You also have to manually focus on the element first using the "focus" command. Finally, I did not implement typeKeysNative; I filed that separately as SRC-377, because it's a lot harder than it looks to convert a given string into native key events. I think the focus function makes the test case TestMouseEvents fail:
Expected: '{mouseover(theTextbox)} {mouseover(theButton)} {mousedown(theTextbox ctrlKeyDown)} {mousedown(theButton)} {focus(theButton)} {contextmenu(theButton)} {mousedown(theButton)}' Actual: '{mouseover(theTextbox)} {mouseover(theButton)} {mousedown(theTextbox ctrlKeyDown)} {mousedown(theButton)} {focus(theButton)} {contextmenu(theButton)} {focus(theButton)} {mousedown(theButton)}' <-- the command before the last will now be recorded as event. Is this the correct behavior and only the test case has to be adapted? |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||