Description
This extension adds the command 'storeGetVar' which stores a get-var retrieved from the url into a variable.
Works with IDE too.
Code to add to the user-extensions:
user-storeGetVar.js
/*
* Finds a get-variable in the url.
*
* Vincent Hindriksen
*/
function getQueryVariable(doc, location, variable) {
var query = location.search.substring(1).replace(/amp;/, "");
var vars = query.split("&");
for (var i=0;i<vars.length;i++) {
//alert('Query Variable :' + vars[i]);
var pair = vars[i].split("=");
if (pair[0] == variable) {
return pair[1];
}
}
// comment next line, when "undefined" is needed as result.
return "";
}
/**
* Gets a get-var from the url
* target - variable to find
* value - the variable to store the result in
*/
Selenium.prototype.doStoreGetvar = function(target, value) {
var location = this.page().getCurrentWindow().location;
var result = getQueryVariable(this.page(), location, target);
storedVars[value] = result;
};
user-showVars.js
Selenium.prototype.doShowVar = function(target, value) {
/**
* shows a simple popup with the variable
* target - variable to show
*/
alert(target+' : ' + storedVars[target]);
}
Example:
http://www.domain.com/index.html?a=first&z=last
| storeGetvar | a | var1 |
| storeGetvar | b | var2 |
| showVar | var1 | |
| showVar | var2 |
The command showVar is very useful for debugging.
