Skip to content

Commit

Permalink
Adding special keys support to sendKeys in all official formatters fo…
Browse files Browse the repository at this point in the history
…r Selenium IDE + enhancement of plugin api for formatters with an additional type parameter. Fixes issue SeleniumHQ#6053
  • Loading branch information
samitbadle committed Aug 9, 2013
1 parent b104cdf commit f392466
Show file tree
Hide file tree
Showing 12 changed files with 520 additions and 32 deletions.
19 changes: 15 additions & 4 deletions ide/main/src/content/format.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ FormatCollection.saveUserFormats = function(formats) {
}

// this is called on se-ide startup for the current formatter, or when you change formatters
FormatCollection.loadFormatter = function(url) {
FormatCollection.loadFormatter = function(url, type) {
const subScriptLoader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
.getService(Components.interfaces.mozIJSSubScriptLoader);

Expand All @@ -107,6 +107,16 @@ FormatCollection.loadFormatter = function(url) {
for (var prop in StringUtils) {
// copy functions from StringUtils
format[prop] = StringUtils[prop];
}
if (type && (type == "webdriver" || type == "remotecontrol")) {
this.log.debug('loading format type ' + type);
format.formatterType = type;
subScriptLoader.loadSubScript('chrome://selenium-ide/content/formats/formatCommandOnlyAdapter.js', format);
if (type == "webdriver") {
subScriptLoader.loadSubScript('chrome://selenium-ide/content/formats/webdriver.js', format);
} else {
subScriptLoader.loadSubScript('chrome://selenium-ide/content/formats/remoteControl.js', format);
}
}
this.log.debug('loading format from ' + url);
subScriptLoader.loadSubScript(url, format);
Expand Down Expand Up @@ -207,7 +217,7 @@ FormatCollection.loadPluginFormats = function(options, pluginManager) {
for (var i = 0; i < plugin.code.length; i++) {
try {
var split_ppf = plugin.code[i].split(";");
formats.push(new PluginFormat(options, split_ppf[0], split_ppf[1], split_ppf[2]));
formats.push(new PluginFormat(options, split_ppf[0], split_ppf[1], split_ppf[2], split_ppf[3]));
//TODO catch plugin formatter errors, need to modify the guts of the formatters :(
} catch (error) {
pluginManager.setPluginError(plugin.id, plugin.code[i], error);
Expand Down Expand Up @@ -516,17 +526,18 @@ UserFormat.prototype.isReversible = function(){
/**
* Format for plugin provided formats
*/
function PluginFormat(options, id, name, url) {
function PluginFormat(options, id, name, url, type) {
this.options = options;
this.id = id;
this.name = name;
this.url = url;
this.type = type;
}

PluginFormat.prototype = new Format;

PluginFormat.prototype.loadFormatter = function() {
return FormatCollection.loadFormatter(this.url);
return FormatCollection.loadFormatter(this.url, this.type);
}

PluginFormat.prototype.getSource = function() {
Expand Down
2 changes: 1 addition & 1 deletion ide/main/src/content/formats/html.js
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ this.configForm =
'<description>Template for command entries in the test html file</description>' +
'<textbox id="options_commandTemplate" multiline="true" flex="1" rows="3"/>' +
'<separator class="groove"/>' +
'<checkbox id="options_escapeDollar" label="Escape \'${\' as \'\\${\' (useful for JSP 2.0)"/>';
'<checkbox id="options_escapeDollar" label="Escape \'$' + '{\' as \'\\$' + '{\' (useful for JSP 2.0)"/>';
//'<separator class="thin"/>' +
//'<description>Template for comment entries in the test html file</description>' +
//'<textbox id="options_commentTemplate" multiline="true" flex="1"/>' +
Expand Down
44 changes: 35 additions & 9 deletions ide/main/src/content/formats/webdriver.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@
* Common classes / functions for Selenium RC format.
*/

var subScriptLoader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"].getService(Components.interfaces.mozIJSSubScriptLoader);
subScriptLoader.loadSubScript('chrome://selenium-ide/content/formats/formatCommandOnlyAdapter.js', this);
if (!this.formatterType) { // this.formatterType is defined for the new Formatter system
// This method (the if block) of loading the formatter type is deprecated.
// For new formatters, simply specify the type in the addPluginProvidedFormatter() and omit this
// if block in your formatter.
var subScriptLoader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"].getService(Components.interfaces.mozIJSSubScriptLoader);
subScriptLoader.loadSubScript('chrome://selenium-ide/content/formats/formatCommandOnlyAdapter.js', this);
}

/* @override
* This function filters the command list and strips away the commands we no longer need
Expand Down Expand Up @@ -95,10 +100,9 @@ function formatHeader(testCase) {
}
className = testClassName(className);
var formatLocal = testCase.formatLocal(this.name);
methodName = testMethodName(className.replace(/Test$/i, "").replace(/^Test/i, "").
replace(/^[A-Z]/, function(str) {
return str.toLowerCase();
}));
methodName = testMethodName(className.replace(/Test$/i, "").replace(/^Test/i, "").replace(/^[A-Z]/, function(str) {
return str.toLowerCase();
}));
var header = (options.getHeader ? options.getHeader() : options.header).
replace(/\$\{className\}/g, className).
replace(/\$\{methodName\}/g, methodName).
Expand Down Expand Up @@ -243,6 +247,27 @@ function concatString(array) {
return array.join(" + ");
}

function toArgumentList(array) {
return array.join(", ");
}

function keyVariable(key) {
return variableName(key);
}

this.sendKeysMaping = {};

function xlateKeyVariable(variable) {
var r;
if ((r = /^KEY_(.+)$/.exec(variable))) {
var key = this.sendKeysMaping[r[1]];
if (key) {
return keyVariable(key);
}
}
return null;
}

function xlateArgument(value, type) {
value = value.replace(/^\s+/, '');
value = value.replace(/\s+$/, '');
Expand All @@ -264,11 +289,12 @@ function xlateArgument(value, type) {
var regexp = /\$\{(.*?)\}/g;
var lastIndex = 0;
while (r2 = regexp.exec(value)) {
if (this.declaredVars && this.declaredVars[r2[1]]) {
var key = xlateKeyVariable(r2[1]);
if (key || (this.declaredVars && this.declaredVars[r2[1]])) {
if (r2.index - lastIndex > 0) {
parts.push(string(value.substring(lastIndex, r2.index)));
}
parts.push(variableName(r2[1]));
parts.push(key ? key : variableName(r2[1]));
lastIndex = regexp.lastIndex;
} else if (r2[1] == "nbsp") {
if (r2.index - lastIndex > 0) {
Expand All @@ -281,7 +307,7 @@ function xlateArgument(value, type) {
if (lastIndex < value.length) {
parts.push(string(value.substring(lastIndex, value.length)));
}
return concatString(parts);
return (type && type.toLowerCase() == 'args') ? toArgumentList(parts) : concatString(parts);
} else if (type && type.toLowerCase() == 'number') {
return value;
} else {
Expand Down
94 changes: 92 additions & 2 deletions ide/plugins/csharp-format/src/content/formats/cs-wd.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@
* Formatter for Selenium 2 / WebDriver .NET (C#) client.
*/

var subScriptLoader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"].getService(Components.interfaces.mozIJSSubScriptLoader);
subScriptLoader.loadSubScript('chrome://selenium-ide/content/formats/webdriver.js', this);
if (!this.formatterType) { // this.formatterType is defined for the new Formatter system
// This method (the if block) of loading the formatter type is deprecated.
// For new formatters, simply specify the type in the addPluginProvidedFormatter() and omit this
// if block in your formatter.
var subScriptLoader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"].getService(Components.interfaces.mozIJSSubScriptLoader);
subScriptLoader.loadSubScript('chrome://selenium-ide/content/formats/webdriver.js', this);
}

function testClassName(testName) {
return testName.split(/[^0-9A-Za-z]+/).map(
Expand Down Expand Up @@ -155,6 +160,91 @@ function formatComment(comment) {
});
}

function keyVariable(key) {
return "Keys." + key;
}

this.sendKeysMaping = {
BACK_SPACE: "Backspace",
BACKSPACE: "Backspace",
TAB: "Tab",
ENTER: "Enter",
SHIFT: "Shift",
LEFT_SHIFT: "LeftShift",
CONTROL: "Control",
LEFT_CONTROL: "LeftControl",
ALT: "Alt",
LEFT_ALT: "LeftAlt",
PAUSE: "Pause",
ESCAPE: "Escape",
ESC: "Escape",
SPACE: "Space",
PAGE_UP: "PageUp",
PAGE_DOWN: "PageDown",
END: "End",
HOME: "Home",
LEFT: "Left",
ARROW_LEFT: "ArrowLeft",
UP: "Up",
ARROW_UP: "ArrowUp",
RIGHT: "Right",
ARROW_RIGHT: "ArrowRight",
DOWN: "Down",
ARROW_DOWN: "ArrowDown",
INSERT: "Insert",
DELETE: "Delete",
SEMICOLON: "Semicolon",
EQUALS: "Equal",

NUMPAD0: "NumberPad0",
NUM_ZERO: "NumberPad0",
NUMPAD1: "NumberPad1",
NUM_ONE: "NumberPad1",
NUMPAD2: "NumberPad2",
NUM_TWO: "NumberPad2",
NUMPAD3: "NumberPad3",
NUM_THREE: "NumberPad3",
NUMPAD4: "NumberPad4",
NUM_FOUR: "NumberPad4",
NUMPAD5: "NumberPad5",
NUM_FIVE: "NumberPad5",
NUMPAD6: "NumberPad6",
NUM_SIX: "NumberPad6",
NUMPAD7: "NumberPad7",
NUM_SEVEN: "NumberPad7",
NUMPAD8: "NumberPad8",
NUM_EIGHT: "NumberPad8",
NUMPAD9: "NumberPad9",
NUM_NINE: "NumberPad9",
MULTIPLY: "Multiply",
NUM_MULTIPLY: "Multiply",
ADD: "Add",
NUM_PLUS: "Add",
SEPARATOR: "Separator",
SUBTRACT: "Subtract",
NUM_MINUS: "Subtract",
DECIMAL: "Decimal",
NUM_PERIOD: "Decimal",
DIVIDE: "Divide",
NUM_DIVISION: "Divide",

F1: "F1",
F2: "F2",
F3: "F3",
F4: "F4",
F5: "F5",
F6: "F6",
F7: "F7",
F8: "F8",
F9: "F9",
F10: "F10",
F11: "F11",
F12: "F12",

META: "Meta",
COMMAND: "Command"
};

/**
* Returns a string representing the suite for this formatter language.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<html:script type="application/javascript">
var ide_api = new API();
ide_api.addPlugin("[email protected]");
ide_api.addPluginProvidedFormatter("csharpwdformatter", "C# / NUnit / WebDriver", "chrome://csharp-formatters/content/formats/cs-wd.js");
ide_api.addPluginProvidedFormatter("csharpwdformatter", "C# / NUnit / WebDriver", "chrome://csharp-formatters/content/formats/cs-wd.js", "webdriver");
ide_api.addPluginProvidedFormatter("csharpformatter", "C# / NUnit / Remote Control", "chrome://csharp-formatters/content/formats/cs-rc.js");
</html:script>
</overlay>
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<html:script type="application/javascript">
var ide_api = new API();
ide_api.addPlugin("[email protected]");
ide_api.addPluginProvidedFormatter("webdriverjunit4formatter", "Java / JUnit 4 / WebDriver", "chrome://java-formatters/content/formats/webdriver-junit4.js");
ide_api.addPluginProvidedFormatter("webdriverjunit4formatter", "Java / JUnit 4 / WebDriver", "chrome://java-formatters/content/formats/webdriver-junit4.js", "webdriver");
ide_api.addPluginProvidedFormatter("backedjunit4formatter", "Java / JUnit 4 / WebDriver Backed", "chrome://java-formatters/content/formats/java-backed-junit4.js");
ide_api.addPluginProvidedFormatter("junit4formatter", "Java / JUnit 4 / Remote Control", "chrome://java-formatters/content/formats/java-rc-junit4.js");
ide_api.addPluginProvidedFormatter("junit3formatter", "Java / JUnit 3 / Remote Control", "chrome://java-formatters/content/formats/java-rc.js");
Expand Down
94 changes: 92 additions & 2 deletions ide/plugins/java-format/src/content/formats/webdriver-junit4.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@
* Formatter for Selenium 2 / WebDriver Java client.
*/

var subScriptLoader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"].getService(Components.interfaces.mozIJSSubScriptLoader);
subScriptLoader.loadSubScript('chrome://selenium-ide/content/formats/webdriver.js', this);
if (!this.formatterType) { // this.formatterType is defined for the new Formatter system
// This method (the if block) of loading the formatter type is deprecated.
// For new formatters, simply specify the type in the addPluginProvidedFormatter() and omit this
// if block in your formatter.
var subScriptLoader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"].getService(Components.interfaces.mozIJSSubScriptLoader);
subScriptLoader.loadSubScript('chrome://selenium-ide/content/formats/webdriver.js', this);
}

function useSeparateEqualsForArray() {
return true;
Expand Down Expand Up @@ -145,6 +150,91 @@ function formatComment(comment) {
});
}

function keyVariable(key) {
return "Keys." + key;
}

this.sendKeysMaping = {
"BACK_SPACE": "BACK_SPACE",
"BACKSPACE": "BACK_SPACE",
"TAB": "TAB",
"ENTER": "ENTER",
"SHIFT": "SHIFT",
"LEFT_SHIFT": "LEFT_SHIFT",
"CONTROL": "CONTROL",
"LEFT_CONTROL": "LEFT_CONTROL",
"ALT": "ALT",
"LEFT_ALT": "LEFT_ALT",
"PAUSE": "PAUSE",
"ESCAPE": "ESCAPE",
"ESC": "ESCAPE",
"SPACE": "SPACE",
"PAGE_UP": "PAGE_UP",
"PAGE_DOWN": "PAGE_DOWN",
"END": "END",
"HOME": "HOME",
"LEFT": "LEFT",
"ARROW_LEFT": "ARROW_LEFT",
"UP": "UP",
"ARROW_UP": "ARROW_UP",
"RIGHT": "RIGHT",
"ARROW_RIGHT": "ARROW_RIGHT",
"DOWN": "DOWN",
"ARROW_DOWN": "ARROW_DOWN",
"INSERT": "INSERT",
"DELETE": "DELETE",
"SEMICOLON": "SEMICOLON",
"EQUALS": "EQUALS",

"NUMPAD0": "NUMPAD0",
"NUM_ZERO": "NUMPAD0",
"NUMPAD1": "NUMPAD1",
"NUM_ONE": "NUMPAD1",
"NUMPAD2": "NUMPAD2",
"NUM_TWO": "NUMPAD2",
"NUMPAD3": "NUMPAD3",
"NUM_THREE": "NUMPAD3",
"NUMPAD4": "NUMPAD4",
"NUM_FOUR": "NUMPAD4",
"NUMPAD5": "NUMPAD5",
"NUM_FIVE": "NUMPAD5",
"NUMPAD6": "NUMPAD6",
"NUM_SIX": "NUMPAD6",
"NUMPAD7": "NUMPAD7",
"NUM_SEVEN": "NUMPAD7",
"NUMPAD8": "NUMPAD8",
"NUM_EIGHT": "NUMPAD8",
"NUMPAD9": "NUMPAD9",
"NUM_NINE": "NUMPAD9",
"MULTIPLY": "MULTIPLY",
"NUM_MULTIPLY": "MULTIPLY",
"ADD": "ADD",
"NUM_PLUS": "ADD",
"SEPARATOR": "SEPARATOR",
"SUBTRACT": "SUBTRACT",
"NUM_MINUS": "SUBTRACT",
"DECIMAL": "DECIMAL",
"NUM_PERIOD": "DECIMAL",
"DIVIDE": "DIVIDE",
"NUM_DIVISION": "DIVIDE",

"F1": "F1",
"F2": "F2",
"F3": "F3",
"F4": "F4",
"F5": "F5",
"F6": "F6",
"F7": "F7",
"F8": "F8",
"F9": "F9",
"F10": "F10",
"F11": "F11",
"F12": "F12",

"META": "META",
"COMMAND": "COMMAND"
};

/**
* Returns a string representing the suite for this formatter language.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<html:script type="application/javascript">
var ide_api = new API();
ide_api.addPlugin("[email protected]");
ide_api.addPluginProvidedFormatter("pythonwdformatter", "Python 2 / unittest / WebDriver", "chrome://python-formatters/content/formats/python2-wd.js");
ide_api.addPluginProvidedFormatter("pythonwdformatter", "Python 2 / unittest / WebDriver", "chrome://python-formatters/content/formats/python2-wd.js", "webdriver");
ide_api.addPluginProvidedFormatter("pythonformatters", "Python 2 / unittest / Remote Control", "chrome://python-formatters/content/formats/python2-rc.js");
</html:script>
</overlay>
Loading

0 comments on commit f392466

Please sign in to comment.