[prev in list] [next in list] [prev in thread] [next in thread] 

List:       selenium-commits
Subject:    [Selenium-commits] [JIRA] Commented: (SEL-143) Key and Mouse events
From:       "Anonymous (JIRA)" <jira () public ! thoughtworks ! org>
Date:       2005-08-19 15:39:38
Message-ID: 8596647.1124465978368.JavaMail.jira () atlassian ! public ! thoughtworks ! org
[Download RAW message or body]

    [ http://jira.public.thoughtworks.org/browse/SEL-143?page=comments#action_12022 ] \


$remoteUser.fullName commented on SEL-143:
----------------------

Here you go, the test file is also the tested file, place it on your docroot at \
/selenium/tests/TestSelenium.html (or change the file/path according your new \
position/filename) and put it in some testsuite.


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!--
Copyright 2004 ThoughtWorks, Inc

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
-->
<html>
<head>
  <meta content="text/html; charset=ISO-8859-1"
 http-equiv="content-type">
  <title>Test Selenium</title>
</head>
<body>
<table cellpadding="1" cellspacing="1" border="1">
  <tbody>
    <tr>
      <td rowspan="1" colspan="3">Test Selenium<br>
      </td>
    </tr>
    <tr>
      <td>open</td>
      <td>/selenium/tests/TestSelenium.html</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>verifyLocation</td>
      <td>/selenium/tests/TestSelenium.html</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>mouseover</td>
      <td>li1</td>
      <td>&nbsp;</td>
    </tr>   
    <tr>
      <td>mouseover</td>
      <td>li2</td>
      <td>&nbsp;</td>
    </tr>   
    <tr>
      <td>mousedown</td>
      <td>li1</td>
      <td>&nbsp;</td>
    </tr>   
    <tr>
      <td>mousedown</td>
      <td>li2</td>
      <td>&nbsp;</td>
    </tr>   
    <tr>
      <td>keypress</td>
      <td>li3</td>
      <td>119</td>
    </tr>   
    <tr>
      <td>keypress</td>
      <td>li3</td>
      <td>115</td>
    </tr>   
  </tbody>
</table>
<ul >
<li id=li1><input size=20 id=i1> Test mousedown bound</input></li>
<li id=li2><input size=20 id=i2> Test mouseover bound</input></li>
<li id=li3><input size=20 id=i3> Test key event bound</input></li>
</ul>
<script>
/* bind a keypress receiver to some object */ 
li1.onmousedown = function mousedowned(e) {
 i1.value = ' li1 got mousedown';
 return false;
}
li2.onmouseover = function mouseover(e) {
 i2.value = ' li2 got mouseover';
 return false;
}
li3.onkeypress = function keypressed(e) {
 if (!e) var e = window.event;
 var code=e.keyCode ? e.keyCode:e.which;
 if (code==9) i3.value = ' li3 tab pressed';
 else if (code==119) i3.value = ' li3 F8 pressed';
 else i3.value = ' li3 key pressed';
 return false;
}

</script>
</body>
</html>


> Key and Mouse events
> --------------------
> 
> Key: SEL-143
> URL: http://jira.public.thoughtworks.org/browse/SEL-143
> Project: Selenium
> Type: New Feature
> Components: BrowserBot
> Reporter: fjh fekkes
> Priority: Minor

> 
> 
> Hello,
> in a try out of selenium I needed the keyevents and mouseevents to be accessible \
> also. Therefor I extended the browserbot by the triggerKeyEvent (triggerMouseEvent \
> was already there) and the subsequent functions to make the commands available \
> (Keypress, Keydown, Mouseover and Mousedown).  I only defined the commands and \
> browsers (IE and MOZ) I need at the moment, the other events are a straigthforward \
> exercise  Regards,
> Fekke
> << htmlutils.js >>
> /* FJH Fire a key event in a browser-compatible manner */
> function triggerKeyEvent(element, eventType, keycode, canBubble) {
> canBubble = (typeof(canBubble) == undefined) ? true : canBubble;
> if (element.fireEvent) {
> 	keyEvent = parent.frames['myiframe'].document.createEventObject();
> 	keyEvent.keyCode=keycode;
> 	element.fireEvent('on' + eventType, keyEvent);
> }
> else {
> var evt = document.createEvent('KeyEvents');
> evt.initKeyEvent(eventType, true, true, window, false, false, false, false, \
> keycode, keycode); element.dispatchEvent(evt);
> }
> }
> /* END FJH */
> << selenium-api.js >>
> /*
> * FJH Key, Mouse event on the located element
> */
> Selenium.prototype.doKeypress = function(locator, keycode) {
> var element = this.page().findElement(locator);
> this.page().keypressElement(element, keycode);
> };
> Selenium.prototype.doKeydown = function(locator, keycode) {
> var element = this.page().findElement(locator);
> this.page().keydownElement(element, keycode);
> };
> Selenium.prototype.doMouseover = function(locator) {
> var element = this.page().findElement(locator);
> this.page().mouseoverElement(element);
> };
> Selenium.prototype.doMousedown = function(locator) {
> var element = this.page().findElement(locator);
> this.page().mousedownElement(element);
> };
> /* END FJH */
> << selenium-browserbot.js >>
> /* FJH Key, Mouse events */
> MozillaPageBot.prototype.keypressElement = function(element, keycode) {
> triggerEvent(element, 'focus', false);
> // Trigger the key event.
> triggerKeyEvent(element, 'keypress', keycode, true);
> if (this.windowClosed()) {
> return;
> }
> triggerEvent(element, 'blur', false);
> };
> MozillaPageBot.prototype.keydownElement = function(element, keycode) {
> triggerEvent(element, 'focus', false);
> // Trigger the key event.
> triggerKeyEvent(element, 'keydown', keycode, true);
> if (this.windowClosed()) {
> return;
> }
> triggerEvent(element, 'blur', false);
> };
> IEPageBot.prototype.keypressElement = function(element, keycode) {
> triggerEvent(element, 'focus', false);
> // Trigger the key event.
> triggerKeyEvent(element, 'keypress', keycode, true);
> if (this.windowClosed()) {
> return;
> }
> triggerEvent(element, 'blur', false);
> };
> IEPageBot.prototype.keydownElement = function(element, keycode) {
> triggerEvent(element, 'focus', false);
> // Trigger the key event.
> triggerKeyEvent(element, 'keydown', keycode, true);
> if (this.windowClosed()) {
> return;
> }
> triggerEvent(element, 'blur', false);
> };
> MozillaPageBot.prototype.mouseoverElement = function(element) {
> triggerEvent(element, 'focus', false);
> // Trigger the mouse event.
> triggerMouseEvent(element, 'mouseover', true);
> if (this.windowClosed()) {
> return;
> }
> triggerEvent(element, 'blur', false);
> };
> MozillaPageBot.prototype.mousedownElement = function(element) {
> triggerEvent(element, 'focus', false);
> // Trigger the mouse event.
> triggerMouseEvent(element, 'mousedown', true);
> if (this.windowClosed()) {
> return;
> }
> triggerEvent(element, 'blur', false);
> };
> IEPageBot.prototype.mouseoverElement = function(element) {
> triggerEvent(element, 'focus', false);
> // Trigger the mouse event.
> triggerMouseEvent(element, 'mouseover', true);
> if (this.windowClosed()) {
> return;
> }
> triggerEvent(element, 'blur', false);
> };
> IEPageBot.prototype.mousedownElement = function(element) {
> triggerEvent(element, 'focus', false);
> // Trigger the mouse event.
> triggerMouseEvent(element, 'mousedown', true);
> if (this.windowClosed()) {
> return;
> }
> triggerEvent(element, 'blur', false);
> };
> /* END FJH */

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://jira.public.thoughtworks.org/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira

_______________________________________________
Selenium-commits mailing list
Selenium-commits@lists.public.thoughtworks.org
http://lists.public.thoughtworks.org/mailman/listinfo/selenium-commits


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic