From 6cc085b380c1452438df05ad27c8cf4031908c28 Mon Sep 17 00:00:00 2001 From: "Kenneth G. Franqueiro" Date: Wed, 6 Aug 2014 19:48:21 -0400 Subject: [PATCH] Initial updates to make tests run with Intern 2 Note that intern is now expected to be installed within the dgrid directory. --- .gitignore | 1 + package.json | 2 +- test/intern/functional.js | 2 +- test/intern/functional/Editor.js | 192 +++++++++++++------------- test/intern/functional/Keyboard.js | 18 +-- test/intern/functional/KeyboardTab.js | 29 ++-- test/intern/functional/Selector.js | 52 +++---- test/intern/functional/Tree.js | 7 +- test/intern/functional/util.js | 104 ++++++++------ test/intern/intern.js | 118 ++++++++-------- test/intern/runTests.html | 2 +- 11 files changed, 277 insertions(+), 250 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..3c3629e64 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +node_modules diff --git a/package.json b/package.json index 502b0083f..1b5554039 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "dgrid", "author": "Kris Zyp", - "version": "0.4-dev", + "version": "0.4.0-dev", "description": "A lightweight, mobile-ready, data-driven, modular widget designed for lists and grids", "licenses": [ { diff --git a/test/intern/functional.js b/test/intern/functional.js index 4216e75b3..74aa4b174 100644 --- a/test/intern/functional.js +++ b/test/intern/functional.js @@ -4,4 +4,4 @@ define([ './functional/Selector', './functional/Editor', './functional/Tree' -], function(){}); \ No newline at end of file +], function () {}); \ No newline at end of file diff --git a/test/intern/functional/Editor.js b/test/intern/functional/Editor.js index 5651de38e..ce6444652 100644 --- a/test/intern/functional/Editor.js +++ b/test/intern/functional/Editor.js @@ -2,75 +2,76 @@ define([ "intern!tdd", "intern/chai!assert", "./util", - "dojo/node!wd/lib/special-keys", + "intern/dojo/node!leadfoot/keys", "require" -], function (test, assert, util, specialKeys, require) { +], function (test, assert, util, keys, require) { // Number of visible rows in the grid. // Check the data loaded in test file (editor.html) and rows visible // when the page is loaded to ensure this is correct. var GRID_ROW_COUNT = 3; var rowSelectorPrefix = "#grid-row-"; - test.suite("dgrid/editor functional tests", function () { - var gotoEnd; // Function defined when `before` logic runs - - // Functions to dismiss field and register edited value, passed to createDatachangeTest - - function dismissViaEnter(remote) { - return remote.type(specialKeys.Enter) - .end(); + var EditorCommand = util.createCommandConstructor({ + dismissViaEnter: function () { + // Presses the enter key and ends the current element context. + return new this.constructor(this, function () { + return this.parent.type(keys.ENTER); + }); + }, + dismissViaBlur: function () { + // Exits to the parent context and focuses an unrelated element. + return new this.constructor(this, function () { + return this.parent.end() + .elementByTagName("h2") + .click(); + }); } + }); - function dismissViaBlur(remote) { - return remote.end() - .elementByTagName("h2") - .click() - .end(); - } + test.suite("dgrid/editor functional tests", function () { + var gotoEnd; // Function defined when `before` logic runs // Functions performing operations to test the editor columns in the grid, // passed to createDatachangeTest - function testAlwaysOnEditor(remote, rowIndex, dismissFunc) { + function testAlwaysOnEditor(command, rowIndex, dismissFunc) { var startValue, appendValue = "abc"; // Click the cell's editor element to focus it - remote.elementByCssSelector(rowSelectorPrefix + rowIndex + " .field-name input") + command = command.elementByCssSelector(rowSelectorPrefix + rowIndex + " .field-name input") .clickElement() - // Store the current cell value .getValue() .then(function (cellValue) { startValue = cellValue; }); - - // Type extra chars to change value - gotoEnd(remote) - .type(appendValue); - dismissFunc(remote); // calls end - - // Click another cell to blur the edited cell (and trigger saving and dgrid-datachange event) - remote.elementByCssSelector(rowSelectorPrefix + rowIndex + " .field-description") - .clickElement() - // The test page has a dgrid-datachange event listener that will push the new value - // into a global array: datachangeStack - .execute("return datachangeStack.shift();") - .then(function (datachangeValue) { - assert.strictEqual(startValue + appendValue, datachangeValue, - "Value in dgrid-datachange event (" + datachangeValue + - ") should equal edited value (" + startValue + appendValue + ")"); - }) - .end(); + // Type extra characters to change value + return gotoEnd(command) + .type(appendValue) + [dismissFunc]() + .end() + // Click another cell to blur the edited cell (and trigger saving and dgrid-datachange event) + .elementByCssSelector(rowSelectorPrefix + rowIndex + " .field-description") + .clickElement() + // The test page has a dgrid-datachange event listener that will push the new value + // into a global array: datachangeStack + .execute("return datachangeStack.shift();") + .then(function (datachangeValue) { + assert.strictEqual(startValue + appendValue, datachangeValue, + "Value in dgrid-datachange event (" + datachangeValue + + ") should equal edited value (" + startValue + appendValue + ")"); + }) + .end(); } - function testEditOnEditor(remote, rowIndex, dismissFunc) { + function testEditOnEditor(command, rowIndex, dismissFunc) { var cellSelector = rowSelectorPrefix + rowIndex + " .field-description", startValue, appendValue = "abc"; // Click the cell to activate the editor - remote.elementByCssSelector(cellSelector) + command = command.elementByCssSelector(cellSelector) .clickElement() .end() // Set context to the cell's editor @@ -80,15 +81,14 @@ define([ .then(function (cellValue) { startValue = cellValue; }); - - // Type extra chars to change value - gotoEnd(remote) - .type(appendValue); - dismissFunc(remote); // calls end - - // The test page has a dgrid-datachange event listener that will push the new value - // into a global array: datachangeStack - remote.execute("return datachangeStack.shift();") + // Type extra characters to change value + return gotoEnd(command) + .type(appendValue) + [dismissFunc]() + .end() + // The test page has a dgrid-datachange event listener that will push the new value + // into a global array: datachangeStack + .execute("return datachangeStack.shift();") .then(function (datachangeValue) { assert.strictEqual(startValue + appendValue, datachangeValue, "Value in dgrid-datachange event (" + datachangeValue + @@ -100,32 +100,32 @@ define([ // Generates test functions for enter/blur value registration tests return function () { this.async(60000); - var remote = this.get("remote"); + var command = new EditorCommand(this.get("remote")); - remote.get(require.toUrl("./Editor.html")); - remote.waitForCondition("ready", 15000); + command = command.get(require.toUrl("./Editor.html")) + .waitForCondition("ready", 15000); if (initFunction) { - remote.execute(initFunction); + command = command.execute(initFunction); } for (var rowIndex = 0; rowIndex < GRID_ROW_COUNT; rowIndex++) { - testFunc(remote, rowIndex, dismissFunc); + command = testFunc(command, rowIndex, dismissFunc); } - - return remote.end(); + + return command; }; } function createFocusTest(selector, initFunction) { // Generates test functions for focus preservation tests return function () { - var remote = this.get("remote"), + var command = new EditorCommand(this.get("remote")), rowIndex; function each(rowIndex) { // Click the cell to activate and focus the editor - remote.elementByCssSelector(rowSelectorPrefix + rowIndex + " " + selector) + return command.elementByCssSelector(rowSelectorPrefix + rowIndex + " " + selector) .clickElement() .end() .executeAsync(function (id, rowIdPrefix, done) { @@ -154,24 +154,24 @@ define([ .end(); } - remote.get(require.toUrl("./Editor-OnDemand.html")) + command = command.get(require.toUrl("./Editor-OnDemand.html")) .waitForCondition("ready", 15000); if (initFunction) { - remote.execute(initFunction); + command = command.execute(initFunction); } for (rowIndex = 0; rowIndex < GRID_ROW_COUNT; rowIndex++) { - each(rowIndex); + command = each(rowIndex); } - return remote.end(); + return command; }; } function createEscapeRevertTest(initFunction) { return function () { - var remote = this.get("remote"), + var command = new EditorCommand(this.get("remote")), rowIndex; function each(rowIndex) { @@ -180,7 +180,7 @@ define([ appendValue = "abc"; // Click the cell to focus the editor - remote.elementByCssSelector(cellSelector) + var newCommand = command.elementByCssSelector(cellSelector) .clickElement() .end() // Get the initial value from the editor field @@ -190,8 +190,8 @@ define([ startValue = cellValue; }); - // Append extra chars and verify the editor's value has updated - gotoEnd(remote) + // Append extra chars and verify the editor's value has updated + return gotoEnd(newCommand) .type(appendValue) .getValue() .then(function (cellValue) { @@ -199,7 +199,7 @@ define([ "Row " + rowIndex + " editor value should differ from the original"); }) // Send Escape and verify the value has reverted in the grid's data - .type(specialKeys.Escape) + .type(keys.ESCAPE) .execute("return grid.row(" + rowIndex + ").data.description;") .then(function (cellValue) { assert.strictEqual(startValue, cellValue, @@ -208,24 +208,24 @@ define([ .end(); } - remote.get(require.toUrl("./Editor.html")) + command = command.get(require.toUrl("./Editor.html")) .waitForCondition("ready", 15000); if (initFunction) { - remote.execute(initFunction); + command = command.execute(initFunction); } for (rowIndex = 0; rowIndex < GRID_ROW_COUNT; rowIndex++) { - each(rowIndex); + command = each(rowIndex); } - return remote.end(); + return command; }; } function createAutosaveTest(initFunction) { return function () { - var remote = this.get("remote"), + var command = new EditorCommand(this.get("remote")), appendValue = "abc", rowIndex; @@ -233,20 +233,20 @@ define([ var editedValue; // Click the cell editor and update the value - remote.elementByCssSelector(rowSelectorPrefix + rowIndex + " .field-name input") + var newCommand = command.elementByCssSelector(rowSelectorPrefix + rowIndex + " .field-name input") .clickElement(); - gotoEnd(remote) + return gotoEnd(newCommand) .type(appendValue) .getValue() .then(function (cellValue) { editedValue = cellValue; - }); - dismissViaBlur(remote); // calls end - - // Click elsewhere to trigger saving of edited cell - remote.elementByTagName("h2") + }) + .dismissViaBlur() + .end() + // Click elsewhere to trigger saving of edited cell + .elementByTagName("h2") .clickElement() - .end() + .end() // Wait for the save to complete before moving on to next iteration .waitForCondition("saveComplete", 5000) // Get the saved value from the test page and verify it @@ -258,39 +258,39 @@ define([ }); } - remote.get(require.toUrl("./Editor-OnDemand.html")) + command = command.get(require.toUrl("./Editor-OnDemand.html")) .waitForCondition("ready", 15000); if (initFunction) { - remote.execute(initFunction); + command = command.execute(initFunction); } for (rowIndex = 0; rowIndex < GRID_ROW_COUNT; rowIndex++) { - each(rowIndex); + command = each(rowIndex); } - return remote.end(); + return command; }; } // Function passed to above functions to change grid column structure // to test other types of editors - + function setTextBox() { /* global setEditorToTextBox */ setEditorToTextBox(); } - + test.before(function () { // In order to function properly on all platforms, we need to know // what the proper character sequence is to go to the end of a text field. // End key works generally everywhere except Mac OS X. return util.isInputHomeEndSupported(this.get("remote")).then(function (isSupported) { - gotoEnd = isSupported ? function (remote) { - return remote.type(specialKeys.End); - } : function (remote) { - return remote.keys(specialKeys.Meta + specialKeys["Right arrow"] + - specialKeys.NULL); + gotoEnd = isSupported ? function (command) { + return command.type(keys.END); + } : function (command) { + return command.keys(keys.META + keys.ARROW_RIGHT + + keys.NULL); }; }); }); @@ -300,22 +300,22 @@ define([ // This combination works, though it's debatable whether it even should test.test("enter registers edited value for always-on editor", - createDatachangeTest(testAlwaysOnEditor, dismissViaEnter)); + createDatachangeTest(testAlwaysOnEditor, 'dismissViaEnter')); test.test("enter registers edited value for editOn editor", - createDatachangeTest(testEditOnEditor, dismissViaEnter)); + createDatachangeTest(testEditOnEditor, 'dismissViaEnter')); test.test("blur registers edited value for always-on editor", - createDatachangeTest(testAlwaysOnEditor, dismissViaBlur)); + createDatachangeTest(testAlwaysOnEditor, 'dismissViaBlur')); test.test("blur registers edited value for always-on editor - TextBox", - createDatachangeTest(testAlwaysOnEditor, dismissViaBlur, setTextBox)); + createDatachangeTest(testAlwaysOnEditor, 'dismissViaBlur', setTextBox)); test.test("blur registers edited value for editOn editor", - createDatachangeTest(testEditOnEditor, dismissViaBlur)); + createDatachangeTest(testEditOnEditor, 'dismissViaBlur')); test.test("blur registers edited value for editOn editor - TextBox", - createDatachangeTest(testEditOnEditor, dismissViaBlur, setTextBox)); + createDatachangeTest(testEditOnEditor, 'dismissViaBlur', setTextBox)); test.test("maintain focus on update for always-on editor", createFocusTest(".field-name input")); diff --git a/test/intern/functional/Keyboard.js b/test/intern/functional/Keyboard.js index cb699e639..f4dedef48 100644 --- a/test/intern/functional/Keyboard.js +++ b/test/intern/functional/Keyboard.js @@ -1,16 +1,16 @@ define([ "intern!tdd", "intern/chai!assert", - "dojo/node!wd/lib/special-keys", + "intern/dojo/node!leadfoot/keys", "require" -], function(test, assert, specialKeys, require){ +], function(test, assert, keys, require){ function testUpDownKeys(gridId, cellNavigation){ var rootQuery = "#" + gridId + " #" + gridId + "-row-"; return function(){ return this.get("remote") .elementByCssSelector(rootQuery + "0" + (cellNavigation ? " .dgrid-column-col1" : "")) .clickElement() - .type([specialKeys["Down arrow"]]) + .type([keys.ARROW_DOWN]) .end() .elementByCssSelector(rootQuery + "1" + (cellNavigation ? " .dgrid-column-col1" : "")) .getAttribute("class") @@ -19,7 +19,7 @@ define([ containsClass = (arr.indexOf("dgrid-focus") !== -1); assert.ok(containsClass, "the down arrow key should move focus one element down"); }) - .type([specialKeys["Up arrow"]]) + .type([keys.ARROW_UP]) .end() .elementByCssSelector(rootQuery + "0" + (cellNavigation ? " .dgrid-column-col1" : "")) .getAttribute("class") @@ -38,7 +38,7 @@ define([ return this.get("remote") .elementByCssSelector(rootQuery + " .dgrid-column-col1") .clickElement() - .type([specialKeys["Right arrow"]]) + .type([keys.ARROW_RIGHT]) .end() .elementByCssSelector(rootQuery + " .dgrid-column-col2") .getAttribute("class") @@ -47,7 +47,7 @@ define([ containsClass = (arr.indexOf("dgrid-focus") !== -1); assert.ok(containsClass, "the right arrow key should move focus one element right"); }) - .type([specialKeys["Left arrow"]]) + .type([keys.ARROW_LEFT]) .end() .elementByCssSelector(rootQuery + " .dgrid-column-col1") .getAttribute("class") @@ -66,7 +66,7 @@ define([ return this.get("remote") .elementByCssSelector(rootQuery + "0" + (cellNavigation ? " .dgrid-column-col1" : "")) .clickElement() - .type([specialKeys.End]) + .type([keys.END]) .end() .setImplicitWaitTimeout(1000) // Note that this assumes the list is always 100 items, 0-99 @@ -77,7 +77,7 @@ define([ containsClass = arr.indexOf("dgrid-focus") !== -1; assert.ok(containsClass, "the end key should move focus to the last element in the list"); }) - .type([specialKeys.Home]) + .type([keys.HOME]) .end() .elementByCssSelector(rootQuery + "0" + (cellNavigation ? " .dgrid-column-col1" : "")) .getAttribute("class") @@ -100,7 +100,7 @@ define([ .get(require.toUrl("./Keyboard.html")) .waitForCondition("ready", 5000); }); - + test.test("grid (cellNavigation: true) -> up + down arrow keys", testUpDownKeys("grid", true)); diff --git a/test/intern/functional/KeyboardTab.js b/test/intern/functional/KeyboardTab.js index ea172af04..dfee08fcb 100644 --- a/test/intern/functional/KeyboardTab.js +++ b/test/intern/functional/KeyboardTab.js @@ -1,10 +1,10 @@ define([ "intern!tdd", "intern/chai!assert", - "dojo/node!wd/lib/special-keys", + "intern/dojo/node!leadfoot/keys", "require" -], function(test, assert, specialKeys, require){ - var tabKey = specialKeys.Tab; +], function(test, assert, keys, require){ + var tabKey = keys.TAB; test.suite("Keyboard tab key functional tests", function(){ test.before(function(){ // Get our html page. This page should load all necessary scripts @@ -23,12 +23,14 @@ define([ .then(function(id){ assert.strictEqual(id, "showHeaderButton", "Focus is on the button: " + id); }) - .type(tabKey) + .type(tabKey) + .end() .active() .getAttribute("role").then(function(role){ assert.strictEqual(role, "columnheader", "Focus is on a column header: " + role); }) - .type(tabKey) + .type(tabKey) + .end() .active() .getAttribute("role").then(function(role){ assert.strictEqual(role, "gridcell", "Focus is on a grid cell: " + role); @@ -36,7 +38,8 @@ define([ .text().then(function(text){ assert.strictEqual(text, "0", "The cell with focus contains 0: " + text); }) - .type(tabKey) + .type(tabKey) + .end() .active() .getAttribute("role").then(function(role){ assert.strictEqual(role, "gridcell", "Focus is on a grid cell: " + role); @@ -45,19 +48,23 @@ define([ assert.strictEqual(text, "10", "The cell with focus contains 10: " + text); }) .reset() + .end() .elementById("showHeaderButton") .click() + .end() .active() .getAttribute("id") .then(function(id){ assert.strictEqual(id, "showHeaderButton", "Focus is on the button: " + id); }) - .type(tabKey) + .type(tabKey) + .end() .active() .getAttribute("role").then(function(role){ assert.strictEqual(role, "columnheader", "Focus is on a column header: " + role); }) - .type(tabKey) + .type(tabKey) + .end() .active() .getAttribute("role").then(function(role){ assert.strictEqual(role, "gridcell", "Focus is on a grid cell: " + role); @@ -65,12 +72,14 @@ define([ .text().then(function(text){ assert.strictEqual(text, "0", "The cell with focus contains 0: " + text); }) - .type(tabKey) + .type(tabKey) + .end() .active() .getAttribute("role").then(function(role){ assert.strictEqual(role, "columnheader", "Focus is on a column header: " + role); }) - .type(tabKey) + .type(tabKey) + .end() .active() .getAttribute("role").then(function(role){ assert.strictEqual(role, "gridcell", "Focus is on a grid cell: " + role); diff --git a/test/intern/functional/Selector.js b/test/intern/functional/Selector.js index a36f5966d..cd479aaf1 100644 --- a/test/intern/functional/Selector.js +++ b/test/intern/functional/Selector.js @@ -2,9 +2,9 @@ define([ "intern!tdd", "intern/chai!assert", "./util", - "dojo/node!wd/lib/special-keys", + "intern/dojo/node!leadfoot/keys", "require" -], function (test, assert, util, specialKeys, require) { +], function (test, assert, util, keys, require) { // The number of visible rows in each grid (clickable without scrolling) // Look at the test page to determine this value var NUM_VISIBLE_ROWS = 6; @@ -24,7 +24,7 @@ define([ test.suite("dgrid/selector functional tests", function () { var isShiftClickSupported; - + // Click the checkbox/radio in the first NUM_VISIBLE_ROWS of a grid. // After each click the row will be tested for the "dgrid-selected" class. function clickAndTestEachRow(remote, gridId) { @@ -33,7 +33,7 @@ define([ function each(rowIndex) { // Click the dgrid/selector checkbox/radio - remote.elementByCssSelector(rowSelector + rowIndex + " .field-select input") + return remote.elementByCssSelector(rowSelector + rowIndex + " .field-select input") .clickElement() .end() // Check the row for the "dgrid-selected" class @@ -60,21 +60,23 @@ define([ for (rowIndex = 0; rowIndex < NUM_VISIBLE_ROWS; rowIndex++) { // The code in this loop is async and might run after the loop has updated // rowIndex, so run the code in a function with its own value - each(rowIndex); + remote = each(rowIndex); } + + return remote; } // Click the checkbox/radio in the first row, then shift+click in the 5th. function shiftClickAndTestRows(remote, gridId) { var rowSelector = "#" + gridId + "-row-"; - remote.elementByCssSelector(rowSelector + "0" + " .field-select input") + return remote.elementByCssSelector(rowSelector + "0" + " .field-select input") .clickElement() .end() - .keys(specialKeys.Shift) + .keys(keys.SHIFT) .elementByCssSelector(rowSelector + "4" + " .field-select input") .clickElement() - .keys(specialKeys.NULL) + .keys(keys.NULL) .end(); } @@ -82,7 +84,7 @@ define([ function selectAll(remote, gridId) { var selector = "#" + gridId + " .dgrid-header .field-select input"; - remote.elementByCssSelector(selector) + return remote.elementByCssSelector(selector) .clickElement() .end(); } @@ -98,7 +100,7 @@ define([ rowIndex; function each(rowIndex) { - remote.elementByCssSelector(selector + rowIndex) + return remote.elementByCssSelector(selector + rowIndex) .getAttribute("class").then(function (classString) { var classNames, isSelected; @@ -117,33 +119,33 @@ define([ .end(); } - selectTestFunction(remote, gridId); + remote = selectTestFunction(remote, gridId); // Loop through all rows to verify selection state for (rowIndex = 0; rowIndex < NUM_VISIBLE_ROWS; rowIndex++) { // The code in this loop is async and might run after the loop has updated // rowIndex, so run the code in a function with its own value - each(rowIndex); + remote = each(rowIndex); } - return remote.end(); + return remote; }; } - + test.before(function () { var remote = this.get("remote"); - remote.get(require.toUrl("./Selector.html")); - return remote.waitForCondition("ready", 15000).then(function () { - return util.isShiftClickSupported(remote).then(function (isSupported) { - isShiftClickSupported = isSupported; - if (!isSupported) { - console.warn("shift+click tests will be no-ops because " + - "this browser/WebDriver combination does not support shift+click."); - } + return remote.get(require.toUrl("./Selector.html")) + .waitForCondition("ready", 15000).then(function () { + return util.isShiftClickSupported(remote).then(function (isSupported) { + isShiftClickSupported = isSupported; + if (!isSupported) { + console.warn("shift+click tests will be no-ops because " + + "this browser/WebDriver combination does not support shift+click."); + } + }); }); - }); }); - + test.beforeEach(function () { // Clear selections from previous tests return this.get("remote").execute(function () { @@ -155,7 +157,7 @@ define([ gridNone.clearSelection(); }); }); - + test.test("selectionMode: extended", createRowSelectionTest("gridExtended", true, clickAndTestEachRow)); test.test("selectionMode: multiple", diff --git a/test/intern/functional/Tree.js b/test/intern/functional/Tree.js index 307a04340..f06cd80f0 100644 --- a/test/intern/functional/Tree.js +++ b/test/intern/functional/Tree.js @@ -27,7 +27,7 @@ define([ xOffset = 30; } - remote.elementByCssSelector("#treeGrid-row-AF " + clickTarget) + return remote.elementByCssSelector("#treeGrid-row-AF " + clickTarget) .moveTo(xOffset, 8) [clickMethod]() .sleep(TRANSITION_DELAY) @@ -47,9 +47,8 @@ define([ .isDisplayed() .then(function(isDisplayed){ assert.ok(!isDisplayed, "Collapsed rows should not be visible"); - }); - - return remote.end(); + }) + .end(); }; } diff --git a/test/intern/functional/util.js b/test/intern/functional/util.js index e8d9b54bb..1aa6bec6c 100644 --- a/test/intern/functional/util.js +++ b/test/intern/functional/util.js @@ -1,6 +1,8 @@ define([ - "dojo/node!wd/lib/special-keys" -], function (specialKeys) { + "intern/dojo/node!leadfoot/keys", + "intern/dojo/node!leadfoot/Command", + "intern/dojo/node!leadfoot/compat" +], function (keys, Command, compat) { return { isShiftClickSupported: function (remote) { // summary: @@ -12,31 +14,29 @@ define([ // returns: // A promise that resolves to a boolean - remote.execute(function () { - window.shiftClickTestButtonClicked = false; - window.isShiftClickSupported = false; - var button = document.createElement("button"); - button.id = "shiftClickTestButton"; - button.onclick = function (event) { - window.shiftClickTestButtonClicked = true; - window.isShiftClickSupported = event.shiftKey; - }; - document.body.appendChild(button); - }); - - remote.keys(specialKeys.Shift) - .elementById("shiftClickTestButton") - .clickElement() - .keys(specialKeys.NULL) - .end() - .waitForCondition("shiftClickTestButtonClicked", 5000); - return remote.execute(function () { - document.body.removeChild(document.getElementById('shiftClickTestButton')); - return window.isShiftClickSupported; - }); + window.shiftClickTestButtonClicked = false; + window.isShiftClickSupported = false; + var button = document.createElement("button"); + button.id = "shiftClickTestButton"; + button.onclick = function (event) { + window.shiftClickTestButtonClicked = true; + window.isShiftClickSupported = event.shiftKey; + }; + document.body.appendChild(button); + }) + .keys(keys.SHIFT) + .elementById("shiftClickTestButton") + .clickElement() + .keys(keys.NULL) + .end() + .waitForCondition("shiftClickTestButtonClicked", 5000) + .execute(function () { + document.body.removeChild(document.getElementById('shiftClickTestButton')); + return window.isShiftClickSupported; + }); }, - + isInputHomeEndSupported: function (remote) { // summary: // Detects whether the given browser/OS combination supports @@ -45,25 +45,45 @@ define([ // A webdriver instance with a remote page already loaded // returns: // A promise that resolves to a boolean - - remote.execute(function () { - var input = document.createElement("input"); - input.id = "homeEndTestInput"; - input.value = "2"; - document.body.appendChild(input); - }); - - remote.elementById("homeEndTestInput") - .clickElement() - .type(specialKeys.End + "3" + specialKeys.Home + "1") - .end(); - + return remote.execute(function () { - var input = document.getElementById("homeEndTestInput"), - value = input.value; - document.body.removeChild(input); - return value === "123"; + var input = document.createElement("input"); + input.id = "homeEndTestInput"; + input.value = "2"; + document.body.appendChild(input); + }) + .elementById("homeEndTestInput") + .clickElement() + .type(keys.END + "3" + keys.HOME + "1") + .end() + .execute(function () { + var input = document.getElementById("homeEndTestInput"), + value = input.value; + document.body.removeChild(input); + return value === "123"; + }); + }, + + createCommandConstructor: function (members) { + // summary: + // Creates a custom Command constructor extended with the + // provided members. Based on Leadfoot's Command documentation: + // http://theintern.github.io/leadfoot/Command.html + + function CustomCommand() { + Command.apply(this, arguments); + } + CustomCommand.prototype = Object.create(Command.prototype); + CustomCommand.prototype.constructor = CustomCommand; + + Object.keys(members).forEach(function (name) { + CustomCommand.prototype[name] = members[name]; }); + + // Add Intern 1.x shim (TODO: stop doing this once all tests are fully converted) + compat.applyTo(CustomCommand.prototype); + + return CustomCommand; } }; }); diff --git a/test/intern/intern.js b/test/intern/intern.js index 6cdc5fd80..e7f8fdafc 100644 --- a/test/intern/intern.js +++ b/test/intern/intern.js @@ -1,71 +1,67 @@ -define({ - // The port on which the instrumenting proxy will listen - proxyPort: 9000, +define([ + 'intern/dojo/has' +], function (has) { + return { + // The port on which the instrumenting proxy will listen + proxyPort: 9000, - // A fully qualified URL to the Intern proxy - proxyUrl: 'http://localhost:9000/', + // A fully qualified URL to the Intern proxy + proxyUrl: 'http://localhost:9000/', - // Default desired capabilities for all environments. Individual capabilities can be overridden by any of the - // specified browser environments in the `environments` array below as well. See - // https://code.google.com/p/selenium/wiki/DesiredCapabilities for standard Selenium capabilities and - // https://saucelabs.com/docs/additional-config#desired-capabilities for Sauce Labs capabilities. - // Note that the `build` capability will be filled in with the current commit ID from the Travis CI environment - // automatically - capabilities: { - // Limit duration of each job to avoid waste of resources during hangs - 'max-duration': 600, - // Increase timeout if Sauce Labs receives no new commands - // (no commands are sent during non-functional unit tests) - 'idle-timeout': 180, - // Specify Selenium version (the default is several versions old) - 'selenium-version': '2.39.0' - }, + // Default desired capabilities for all environments. Individual capabilities can be overridden by any of the + // specified browser environments in the `environments` array below as well. See + // https://code.google.com/p/selenium/wiki/DesiredCapabilities for standard Selenium capabilities and + // https://saucelabs.com/docs/additional-config#desired-capabilities for Sauce Labs capabilities. + // Note that the `build` capability will be filled in with the current commit ID from the Travis CI environment + // automatically + capabilities: { + // Limit duration of each job to avoid waste of resources during hangs + 'max-duration': 600, + // Increase timeout if Sauce Labs receives no new commands + // (no commands are sent during non-functional unit tests) + 'idle-timeout': 180 + }, - // Browsers to run integration testing against. Note that version numbers must be strings if used with Sauce - // OnDemand. Options that will be permutated are browserName, version, platform, and platformVersion; any other - // capabilities options specified for an environment will be copied as-is - environments: [ - { browserName: 'internet explorer', version: '11', platform: 'Windows 8.1' }, - { browserName: 'internet explorer', version: '10', platform: 'Windows 8' }, - { browserName: 'internet explorer', version: '9', platform: 'Windows 7' }, - { browserName: 'firefox', platform: [ 'Linux', 'OS X 10.6', 'Windows 7' ] }, - { browserName: 'chrome', platform: [ 'Linux', 'OS X 10.8', 'Windows 7' ] }, - { browserName: 'safari', version: '6', platform: 'OS X 10.8' } - ], + // Browsers to run integration testing against. Note that version numbers must be strings if used with Sauce + // OnDemand. Options that will be permutated are browserName, version, platform, and platformVersion; any other + // capabilities options specified for an environment will be copied as-is + environments: [ + { browserName: 'internet explorer', version: '11', platform: 'Windows 8.1' }, + { browserName: 'internet explorer', version: '10', platform: 'Windows 8' }, + { browserName: 'internet explorer', version: '9', platform: 'Windows 7' }, + { browserName: 'firefox', platform: [ 'Linux', 'OS X 10.6', 'Windows 7' ] }, + { browserName: 'chrome', platform: [ 'Linux', 'OS X 10.8', 'Windows 7' ] }, + { browserName: 'safari', version: '6', platform: 'OS X 10.8' } + ], - // Maximum number of simultaneous integration tests that should be executed on the remote WebDriver service - maxConcurrency: 3, + // Maximum number of simultaneous integration tests that should be executed on the remote WebDriver service + maxConcurrency: 3, - // Whether or not to start Sauce Connect before running tests - useSauceConnect: true, + // If using Sauce Labs, keep your username and password in the SAUCE_USERNAME and SAUCE_ACCESS_KEY + // environment variables. + tunnel: 'SauceLabsTunnel', - // Connection information for the remote WebDriver service. If using Sauce Labs, keep your username and password - // in the SAUCE_USERNAME and SAUCE_ACCESS_KEY environment variables unless you are sure you will NEVER be - // publishing this configuration file somewhere - webdriver: { - host: 'localhost', - port: 4444 - }, + // Configuration options for the module loader; any AMD configuration options supported by the Dojo loader can be + // used here + loader: { + baseUrl: has('host-browser') ? '../../..' : '..', + // Packages that should be registered with the loader in each testing environment + packages: [ + { name: 'dojo', location: 'dojo' }, + { name: 'dijit', location: 'dijit' }, + { name: 'dgrid', location: 'dgrid' }, + { name: 'put-selector', location: 'put-selector' }, + { name: 'xstyle', location: 'xstyle' } + ] + }, - // Configuration options for the module loader; any AMD configuration options supported by the Dojo loader can be - // used here - loader: { - // Packages that should be registered with the loader in each testing environment - packages: [ - { name: 'dojo', location: 'dojo' }, - { name: 'dijit', location: 'dijit' }, - { name: 'dgrid', location: 'dgrid' }, - { name: 'put-selector', location: 'put-selector' }, - { name: 'xstyle', location: 'xstyle' } - ] - }, + // A regular expression matching URLs to files that should not be included in code coverage analysis + excludeInstrumentation: /^dojox?|^dijit|^dstore|^xstyle|^put-selector|\/test\/|\/nls\//, - // A regular expression matching URLs to files that should not be included in code coverage analysis - excludeInstrumentation: /^dojox?|^dijit|^xstyle|^put-selector|\/test\/|\/nls\//, + // Non-functional test suite(s) to run in each browser + suites: [ 'dgrid/test/intern/all' ], - // Non-functional test suite(s) to run in each browser - suites: [ 'dgrid/test/intern/all' ], - - // Functional test suite(s) to run in each browser once non-functional tests are completed - functionalSuites: [ 'dgrid/test/intern/functional' ] + // Functional test suite(s) to run in each browser once non-functional tests are completed + functionalSuites: [ 'dgrid/test/intern/functional' ] + } }); diff --git a/test/intern/runTests.html b/test/intern/runTests.html index 69e830394..15ccc8e21 100644 --- a/test/intern/runTests.html +++ b/test/intern/runTests.html @@ -3,7 +3,7 @@ dgrid Intern suite - + Redirecting to Intern runner.