r2 - 19 Jul 2007 - 06:24:02 - MimiYinYou are here: OSAF >  Journal Web  >  QualityAssuranceTeam > AdamChristianNotes > AdamChristianSeleniumPostMerge

Selenium Post Merge

selenium-api.js: I am trying to get these changes added to the Selenium core for the next version.

//Double click functionality
 Selenium.prototype.doDblclick = function(locator) {
 var element = this.page().findElement(locator);
 this.page().dblclickElement(element);
};
//Author: Adam Christian, Open Source Applications Foundation
//Email: adam@osafoundation.org
//
//Description: The following function allows one to write a test that drags and drops a specified
//div to another specified destination div. However this doesn't take into account x and y 
//offsets for divs that are positioned inside other divs. I plan on adding the ability to pass
//those offsets in the test table in the future.
//
//Example html Selenium test table:
//<tr>
// <td>store</td>
// <td>javascript{this.browserbot.getCurrentWindow().Cal.eventRegistry.getFirst().id}</td>
// <td>did</td>
//</tr>
//<tr>
// <td>dragdropDiv</td>
// <td>id=eventDivContent__${did}</td>
// <td>id=hourDiv4-1200</td>
//</tr>
Selenium.prototype.doDragdropDiv = function(locator, destlocator) {
    
    var element = this.page().findElement(locator)
    var eStartXY = getClientXY(element)
    var eStartX = eStartXY[0];
    var eStartY = eStartXY[1];
    
    
    var destelement = this.page().findElement(destlocator)
    var dStartXY = getClientXY(destelement)
    var dStartX = dStartXY[0];
    var dStartY = dStartXY[1];
    
    var xVal = Math.abs(dStartX - eStartX);
    var yVal = Math.abs(dStartY - eStartY);
    
    var Xdir = "-";
    var Ydir = "-";
    var movementXincrement = -1;
    var movementYincrement = -1;
    
    if (dStartX > eStartX) {
        Xdir = "+";
        movementXincrement = 1;
    }
    
    if (dStartY > eStartY) {
        Xdir = "+";
        movementYincrement = 1;
    }
    
    triggerMouseEvent(element, 'mousedown', true, eStartX, eStartY);
    var clientX = eStartX;
    var clientY = eStartY;
    var clientFinishX = dStartX;
    var clientFinishY = dStartY;
       
       while ((clientX != clientFinishX) || (clientY != clientFinishY)) {
        if (clientX != clientFinishX) {
         clientX += movementXincrement;
            }
        if (clientY != clientFinishY) {
         clientY += movementYincrement;
            }
            triggerMouseEvent(element, 'mousemove', true, clientX, clientY);
        }
        triggerMouseEvent(element, 'mouseup',   true, clientFinishX, clientFinishY);
    //newmovementString = Xdir + xVal + "," + Ydir + yVal;
    //throw(newmovementString);
    //return this.doDragdrop(locator,newmovementString);
    
}
selenium-browserbot.js

//Double click for Mozilla
 MozillaPageBot.prototype.dblclickElement = function(element) {

 triggerEvent(element, 'focus', false);

 // Trigger the mouse event.
 triggerMouseEvent(element, 'dblclick', true);

 if (this._windowClosed()) {
     return;
 }

 triggerEvent(element, 'blur', false);
};
//Double Click functionality for Safari
 SafariPageBot.prototype.dblclickElement = function(element) {

 triggerEvent(element, 'focus', false);

 // Trigger the mouse event.
 triggerMouseEvent(element, 'dblclick', true);

 if (this._windowClosed()) {
     return;
 }

 triggerEvent(element, 'blur', false);
};
//Double click functionality for IE
 IEPageBot.prototype.dblclickElement = function(element) {
triggerEvent(element, 'focus', false);

// Trigger the mouse event.
triggerMouseEvent(element, 'dblclick', true);

if (this._windowClosed()) {
    return;
}

    triggerEvent(element, 'blur', false);

};

user-extensions.js

/Author: Adam Christian, Open Source Applications Foundation
//Email: adam@osafoundation.org
//
//Description: The following function allows a selenium test to accurately move an event DIV
//to a destination time/day using the Cosmo UI objects to calculate and compensate for
//The relative DIV offsets
//
//Example html Selenium test table:
//<tr>
// <td>store</td>
// <td>javascript{this.browserbot.getCurrentWindow().Cal.eventRegistry.getFirst().id}</td>
// <td>did</td>
//</tr>
//<tr>
// <td>dragdropDivCosmo</td>
// <td>id=eventDivContent__${did}</td>
// <td>id=hourDiv4-1200</td>
//</tr>
Selenium.prototype.doDragdropDivCosmo = function(origlocator, destlocator) {
    
    //Get originating coordinates for the event
    var element = this.page().findElement(origlocator)
    var eStartXY = getClientXY(element)
    var eStartX = eStartXY[0];
    var eStartY = eStartXY[1];
    
    //Click on it, so the Draggable object is insantiated and becomes accessable via Cal.dragElem
    triggerMouseEvent(element, 'mousedown', true, eStartX, eStartY);

    //Calculate the start drag using the x and y calendar offsets
    var eStartX = (eStartX + this.browserbot.getCurrentWindow().Cal.dragElem.clickOffsetX);
    var eStartY = (eStartY + this.browserbot.getCurrentWindow().Cal.dragElem.clickOffsetY);
    
    //Get destination div x,y coordinates
    var destelement = this.page().findElement(destlocator)
    var dStartXY = getClientXY(destelement)
    
    //Adjust for offsets, the offsets were both still off by increments of 150 and 50, so I correct this here.
    //(There is probably a better way to do this, but this was the best hack I could make work reliably.)
    //This breaks when the X value when the browser canvas is significantly shrunk because the dest div size shrinks
    //This will be fixed after the merge code is given to QA
    var dStartX = (dStartXY[0] + this.browserbot.getCurrentWindow().Cal.dragElem.clickOffsetX - 150);
    var dStartY = (dStartXY[1] + this.browserbot.getCurrentWindow().Cal.dragElem.clickOffsetY - 50);
    
    //Calculate the actual distance the x and y needs to move
    var xVal = Math.abs(dStartX - eStartX);
    var yVal = Math.abs(dStartY - eStartY);
    
    //Default both to moving negatively
    var Xdir = "-";
    var Ydir = "-";
    
    //Default the increment direction
    var movementXincrement = -1;
    var movementYincrement = -1;
    
    //Set coordinate pos/neg for X
    if (dStartX > eStartX) {
        Xdir = "+";
        movementXincrement = 1;
    }
    
    //Set coordinate pos/neg for Y
    if (dStartY > eStartY) {
        Xdir = "+";
        movementYincrement = 1;
    }
    
    //Prepare to move the cursor (starting place)
    var clientX = eStartX;
    var clientY = eStartY;
    
    //Prepare to move to destination
    var clientFinishX = dStartX;
    var clientFinishY = dStartY;
       
       //While loop to actually move the mouse cursor
       while ((clientX != clientFinishX) || (clientY != clientFinishY)) {
        if (clientX != clientFinishX) {
             //Set incremented X coord
             clientX += movementXincrement;
            }
        if (clientY != clientFinishY) {
                //Set incremented Y coord
             clientY += movementYincrement;
            }
            //Move the mouse to the new coordinates
            triggerMouseEvent(element, 'mousemove', true, clientX, clientY);
        }
        
    //Mouseup in the final resting place for the event
    triggerMouseEvent(element, 'mouseup',   true, clientFinishX, clientFinishY);
    
}

//Author: Adam Christian, Open Source Applications Foundation
//Email: adam@osafoundation.org
//
//Description: The following is the equivalent of a wrapper, this allows me to use:
//<tr>
// <td>storeId</td>
// <td>first</td>
// <td>did</td>
//</tr>
//
//When the java script objects in Cosmo are changed, as they were in the merge editing ths code
//will fix all of the tests. 
Selenium.prototype.doStoreId = function(expression, variableName) {
    /** This command is a synonym for storeExpression.
     * @param expression the identifier for the ID we want from Cosmo
     * @param variableName the name of a <a href="#storedVars">variable</a> in which the result is to be stored.
     */
    //If they want the next
    if (expression == "next"){
        storedVars[variableName] = this.browserbot.getCurrentWindow().cosmo.view.cal.canvas.eventRegistry.getNext().id;
    }
    //Default to the first, more cases could be added
    else{
        storedVars[variableName] =  this.browserbot.getCurrentWindow().cosmo.view.cal.canvas.eventRegistry.getFirst().id;
    }
}

Actual Tests

<tr>
 <td>open</td>
 <td>/cosmo/pim/pim.page</td>
 <td></td>
</tr>
<tr>
      <td>dblclick</td>
      <td>id=hourDiv0-900</td>
      <td></td>
</tr>
<tr>
      <td>pause</td>
      <td>2000</td>
      <td></td>
</tr>
<tr>
 <td>storeId</td>
 <td>first</td>
 <td>did</td>
</tr>
<tr>
 <td>dragdropDivCosmo</td>
 <td>id=eventDivContent__${did}</td>
 <td>id=hourDiv4-1200</td>
</tr>
<tr>
 <td>click</td>
 <td>id=viewNavRight</td>
 <td></td>
</tr>
Edit | WYSIWYG | Attach | Printable | Raw View | Backlinks: Web, All Webs | History: r2 < r1 | More topic actions
 
Open Source Applications Foundation
Except where otherwise noted, this site and its content are licensed by OSAF under an Creative Commons License, Attribution Only 3.0.
See list of page contributors for attributions.