Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
T
todomvc
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Sven Franck
todomvc
Commits
e36fff78
Commit
e36fff78
authored
Jan 29, 2014
by
ColinEberhardt
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #801 from passy/browser-tests-style
Update browser-tests JS style
parents
bacfede5
4a4016ff
Changes
7
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
841 additions
and
819 deletions
+841
-819
browser-tests/Gruntfile.js
browser-tests/Gruntfile.js
+14
-15
browser-tests/allTests.js
browser-tests/allTests.js
+46
-27
browser-tests/knownIssues.js
browser-tests/knownIssues.js
+87
-87
browser-tests/page.js
browser-tests/page.js
+146
-146
browser-tests/pageLaxMode.js
browser-tests/pageLaxMode.js
+19
-19
browser-tests/test.js
browser-tests/test.js
+371
-370
browser-tests/testOperations.js
browser-tests/testOperations.js
+158
-155
No files found.
browser-tests/Gruntfile.js
View file @
e36fff78
module
.
exports
=
function
(
grunt
)
{
'
use strict
'
;
grunt
.
loadNpmTasks
(
'
grunt-simple-mocha
'
);
var
gruntConfig
=
{
grunt
.
initConfig
(
{
simplemocha
:
{
options
:
{
reporter
:
'
mocha-known-issues-reporter
'
...
...
@@ -11,8 +11,7 @@ module.exports = function (grunt) {
src
:
'
allTests.js
'
}
}
};
grunt
.
initConfig
(
gruntConfig
);
});
// build tasks
grunt
.
registerTask
(
'
test
'
,
[
'
simplemocha
'
]);
...
...
browser-tests/allTests.js
View file @
e36fff78
var
testSuite
=
require
(
'
./test.js
'
),
fs
=
require
(
'
fs
'
),
argv
=
require
(
'
optimist
'
).
default
(
'
laxMode
'
,
false
).
argv
,
rootUrl
=
"
http://localhost:8000/
"
,
frameworkNamePattern
=
/^
[
a-z-_
]
+$/
;
'
use strict
'
;
// collect together the framework names from each of the subfolders
var
list
=
fs
.
readdirSync
(
"
../architecture-examples/
"
)
.
map
(
function
(
folderName
)
{
return
{
name
:
folderName
,
path
:
"
architecture-examples/
"
+
folderName
}
});
list
=
list
.
concat
(
fs
.
readdirSync
(
"
../labs/architecture-examples/
"
)
.
map
(
function
(
folderName
)
{
return
{
name
:
folderName
,
path
:
"
labs/architecture-examples/
"
+
folderName
}
}));
list
=
list
.
concat
(
fs
.
readdirSync
(
"
../labs/dependency-examples/
"
)
.
map
(
function
(
folderName
)
{
return
{
name
:
folderName
,
path
:
"
labs/dependency-examples/
"
+
folderName
}
}));
var
testSuite
=
require
(
'
./test.js
'
);
var
fs
=
require
(
'
fs
'
);
var
argv
=
require
(
'
optimist
'
).
default
(
'
laxMode
'
,
false
).
argv
;
var
rootUrl
=
'
http://localhost:8000/
'
;
var
frameworkNamePattern
=
/^
[
a-z-_
]
+$/
;
list
=
list
.
concat
(
fs
.
readdirSync
(
"
../dependency-examples/
"
)
.
map
(
function
(
folderName
)
{
return
{
name
:
folderName
,
path
:
"
dependency-examples/
"
+
folderName
}
}));
// collect together the framework names from each of the subfolders
var
list
=
fs
.
readdirSync
(
'
../architecture-examples/
'
)
.
map
(
function
(
folderName
)
{
return
{
name
:
folderName
,
path
:
'
architecture-examples/
'
+
folderName
};
})
.
concat
(
fs
.
readdirSync
(
'
../labs/architecture-examples/
'
)
.
map
(
function
(
folderName
)
{
return
{
name
:
folderName
,
path
:
'
labs/architecture-examples/
'
+
folderName
};
})
)
.
concat
(
fs
.
readdirSync
(
'
../labs/dependency-examples/
'
)
.
map
(
function
(
folderName
)
{
return
{
name
:
folderName
,
path
:
'
labs/dependency-examples/
'
+
folderName
};
})
)
.
concat
(
fs
.
readdirSync
(
'
../dependency-examples/
'
)
.
map
(
function
(
folderName
)
{
return
{
name
:
folderName
,
path
:
'
dependency-examples/
'
+
folderName
};
})
);
// apps that are not hosted at the root of their folder need to be handled explicitly
var
exceptions
=
[
{
name
:
"
chaplin-brunch
"
,
path
:
"
labs/dependency-examples/chaplin-brunch/public
"
}
{
name
:
'
chaplin-brunch
'
,
path
:
'
labs/dependency-examples/chaplin-brunch/public
'
}
];
list
=
list
.
map
(
function
(
framework
)
{
var
exception
=
exceptions
.
filter
(
function
(
exFramework
)
{
return
exFramework
.
name
===
framework
.
name
});
list
=
list
.
map
(
function
(
framework
)
{
var
exception
=
exceptions
.
filter
(
function
(
exFramework
)
{
return
exFramework
.
name
===
framework
.
name
;
});
return
exception
.
length
>
0
?
exception
[
0
]
:
framework
;
});
// filter out any folders that are not frameworks (.e.g hidden files)
list
=
list
.
filter
(
function
(
framework
)
{
return
frameworkNamePattern
.
test
(
framework
.
name
);
});
list
=
list
.
filter
(
function
(
framework
)
{
return
frameworkNamePattern
.
test
(
framework
.
name
);
});
// if a specific framework has been named, just run this one
if
(
argv
.
framework
)
{
list
=
list
.
filter
(
function
(
framework
)
{
return
framework
.
name
===
argv
.
framework
});
list
=
list
.
filter
(
function
(
framework
)
{
return
framework
.
name
===
argv
.
framework
;
});
}
// run the tests for each framework
var
testIndex
=
1
;
list
.
forEach
(
function
(
framework
)
{
testSuite
.
todoMVCTest
(
framework
.
name
,
rootUrl
+
framework
.
path
+
"
/index.html
"
,
argv
.
speedMode
,
argv
.
laxMode
);
list
.
forEach
(
function
(
framework
)
{
testSuite
.
todoMVCTest
(
framework
.
name
,
rootUrl
+
framework
.
path
+
'
/index.html
'
,
argv
.
speedMode
,
argv
.
laxMode
);
});
browser-tests/knownIssues.js
View file @
e36fff78
This diff is collapsed.
Click to expand it.
browser-tests/page.js
View file @
e36fff78
'
use strict
'
;
var
webdriver
=
require
(
'
selenium-webdriver
'
);
function
Page
(
browser
,
laxMode
)
{
module
.
exports
=
function
Page
(
browser
)
{
// ----------------- utility methods
this
.
xPathForItemAtIndex
=
function
(
index
)
{
this
.
xPathForItemAtIndex
=
function
(
index
)
{
// why is XPath the only language silly enough to be 1-indexed?
return
"
//ul[@id='todo-list']/li[
"
+
(
index
+
1
)
+
"
]
"
;
}
return
'
//ul[@id="todo-list"]/li[
'
+
(
index
+
1
)
+
'
]
'
;
};
// ----------------- try / get methods
...
...
@@ -16,99 +18,99 @@ function Page(browser, laxMode) {
// and test that the length is zero. These methods are used to obtain
// elements which *might* be present in the DOM, hence the try/get name.
this
.
tryGetMainSectionElement
=
function
()
{
return
browser
.
findElements
(
webdriver
.
By
.
xpath
(
"
//section[@id='main']
"
));
}
this
.
tryGetMainSectionElement
=
function
()
{
return
browser
.
findElements
(
webdriver
.
By
.
xpath
(
'
//section[@id="main"]
'
));
};
this
.
tryGetFooterElement
=
function
()
{
return
browser
.
findElements
(
webdriver
.
By
.
xpath
(
"
//footer[@id='footer']
"
));
}
this
.
tryGetFooterElement
=
function
()
{
return
browser
.
findElements
(
webdriver
.
By
.
xpath
(
'
//footer[@id="footer"]
'
));
};
this
.
tryGetClearCompleteButton
=
function
()
{
return
browser
.
findElements
(
webdriver
.
By
.
xpath
(
"
//button[@id='clear-completed']
"
));
}
this
.
tryGetClearCompleteButton
=
function
()
{
return
browser
.
findElements
(
webdriver
.
By
.
xpath
(
'
//button[@id="clear-completed"]
'
));
};
this
.
tryGetToggleForItemAtIndex
=
function
(
index
)
{
var
xpath
=
this
.
xPathForItemAtIndex
(
index
)
+
"
//input[contains(@class,'toggle')]
"
;
this
.
tryGetToggleForItemAtIndex
=
function
(
index
)
{
var
xpath
=
this
.
xPathForItemAtIndex
(
index
)
+
'
//input[contains(@class,"toggle")]
'
;
return
browser
.
findElements
(
webdriver
.
By
.
xpath
(
xpath
));
}
};
this
.
tryGetItemLabelAtIndex
=
function
(
index
)
{
return
browser
.
findElements
(
webdriver
.
By
.
xpath
(
this
.
xPathForItemAtIndex
(
index
)
+
"
//label
"
));
}
this
.
tryGetItemLabelAtIndex
=
function
(
index
)
{
return
browser
.
findElements
(
webdriver
.
By
.
xpath
(
this
.
xPathForItemAtIndex
(
index
)
+
'
//label
'
));
};
// ----------------- DOM element access methods
this
.
getEditInputForItemAtIndex
=
function
(
index
)
{
var
xpath
=
this
.
xPathForItemAtIndex
(
index
)
+
"
//input[contains(@class,'edit')]
"
;
this
.
getEditInputForItemAtIndex
=
function
(
index
)
{
var
xpath
=
this
.
xPathForItemAtIndex
(
index
)
+
'
//input[contains(@class,"edit")]
'
;
return
browser
.
findElement
(
webdriver
.
By
.
xpath
(
xpath
));
}
};
this
.
getItemInputField
=
function
()
{
return
browser
.
findElement
(
webdriver
.
By
.
xpath
(
"
//input[@id='new-todo']
"
));
}
this
.
getItemInputField
=
function
()
{
return
browser
.
findElement
(
webdriver
.
By
.
xpath
(
'
//input[@id="new-todo"]
'
));
};
this
.
getMarkAllCompletedCheckBox
=
function
()
{
return
browser
.
findElement
(
webdriver
.
By
.
xpath
(
"
//input[@id='toggle-all']
"
));
}
this
.
getMarkAllCompletedCheckBox
=
function
()
{
return
browser
.
findElement
(
webdriver
.
By
.
xpath
(
'
//input[@id="toggle-all"]
'
));
};
this
.
getItemElements
=
function
()
{
return
browser
.
findElements
(
webdriver
.
By
.
xpath
(
"
//ul[@id='todo-list']/li
"
));
}
this
.
getItemElements
=
function
()
{
return
browser
.
findElements
(
webdriver
.
By
.
xpath
(
'
//ul[@id="todo-list"]/li
'
));
};
this
.
getNonCompletedItemElements
=
function
()
{
return
browser
.
findElements
(
webdriver
.
By
.
xpath
(
"
//ul[@id='todo-list']/li[not(contains(@class,'completed'))]
"
));
}
this
.
getNonCompletedItemElements
=
function
()
{
return
browser
.
findElements
(
webdriver
.
By
.
xpath
(
'
//ul[@id="todo-list"]/li[not(contains(@class,"completed"))]
'
));
};
this
.
getItemsCountElement
=
function
()
{
return
browser
.
findElement
(
webdriver
.
By
.
id
(
"
todo-count
"
));
}
this
.
getItemsCountElement
=
function
()
{
return
browser
.
findElement
(
webdriver
.
By
.
id
(
'
todo-count
'
));
};
this
.
getItemLabelAtIndex
=
function
(
index
)
{
return
browser
.
findElement
(
webdriver
.
By
.
xpath
(
this
.
xPathForItemAtIndex
(
index
)
+
"
//label
"
));
}
this
.
getItemLabelAtIndex
=
function
(
index
)
{
return
browser
.
findElement
(
webdriver
.
By
.
xpath
(
this
.
xPathForItemAtIndex
(
index
)
+
'
//label
'
));
};
this
.
getFilterElements
=
function
()
{
return
browser
.
findElements
(
webdriver
.
By
.
xpath
(
"
//ul[@id='filters']//a
"
));
}
this
.
getFilterElements
=
function
()
{
return
browser
.
findElements
(
webdriver
.
By
.
xpath
(
'
//ul[@id="filters"]//a
'
));
};
// ----------------- page actions
this
.
clickMarkAllCompletedCheckBox
=
function
()
{
return
this
.
getMarkAllCompletedCheckBox
().
then
(
function
(
checkbox
)
{
this
.
clickMarkAllCompletedCheckBox
=
function
()
{
return
this
.
getMarkAllCompletedCheckBox
().
then
(
function
(
checkbox
)
{
checkbox
.
click
();
});
}
};
this
.
clickClearCompleteButton
=
function
()
{
return
this
.
tryGetClearCompleteButton
().
then
(
function
(
elements
)
{
this
.
clickClearCompleteButton
=
function
()
{
return
this
.
tryGetClearCompleteButton
().
then
(
function
(
elements
)
{
var
button
=
elements
[
0
];
button
.
click
();
});
}
};
this
.
enterItem
=
function
(
itemText
)
{
this
.
enterItem
=
function
(
itemText
)
{
var
textField
=
this
.
getItemInputField
();
textField
.
sendKeys
(
itemText
);
textField
.
sendKeys
(
webdriver
.
Key
.
ENTER
);
};
this
.
toggleItemAtIndex
=
function
(
index
)
{
return
this
.
tryGetToggleForItemAtIndex
(
index
).
then
(
function
(
elements
)
{
this
.
toggleItemAtIndex
=
function
(
index
)
{
return
this
.
tryGetToggleForItemAtIndex
(
index
).
then
(
function
(
elements
)
{
var
toggleElement
=
elements
[
0
];
toggleElement
.
click
();
});
}
};
this
.
editItemAtIndex
=
function
(
index
,
itemText
)
{
this
.
editItemAtIndex
=
function
(
index
,
itemText
)
{
return
this
.
getEditInputForItemAtIndex
(
index
)
.
then
(
function
(
itemEditField
)
{
.
then
(
function
(
itemEditField
)
{
// send 50 delete keypresses, just to be sure the item text is deleted
var
deleteKeyPresses
=
""
;
for
(
var
i
=
0
;
i
<
50
;
i
++
)
{
deleteKeyPresses
+=
webdriver
.
Key
.
BACK_SPACE
var
deleteKeyPresses
=
''
;
for
(
var
i
=
0
;
i
<
50
;
i
++
)
{
deleteKeyPresses
+=
webdriver
.
Key
.
BACK_SPACE
;
}
itemEditField
.
sendKeys
(
deleteKeyPresses
);
// update the item with the new text.
...
...
@@ -116,34 +118,32 @@ function Page(browser, laxMode) {
});
};
this
.
doubleClickItemAtIndex
=
function
(
index
)
{
return
this
.
getItemLabelAtIndex
(
index
).
then
(
function
(
itemLabel
)
{
// double click is not 'natively' supported, so we need to send the event direct to the element
// see: http://stackoverflow.com/questions/3982442/selenium-2-webdriver-how-to-double-click-a-table-row-which-opens-a-new-window
browser
.
executeScript
(
"
var evt = document.createEvent('MouseEvents');
"
+
"
evt.initMouseEvent('dblclick',true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0,null);
"
+
"
arguments[0].dispatchEvent(evt);
"
,
itemLabel
);
this
.
doubleClickItemAtIndex
=
function
(
index
)
{
return
this
.
getItemLabelAtIndex
(
index
).
then
(
function
(
itemLabel
)
{
// double click is not 'natively' supported, so we need to send the
// event direct to the element see:
// http://stackoverflow.com/questions/3982442/selenium-2-webdriver-how-to-double-click-a-table-row-which-opens-a-new-window
browser
.
executeScript
(
'
var evt = document.createEvent("MouseEvents");
'
+
'
evt.initMouseEvent("dblclick",true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0,null);
'
+
'
arguments[0].dispatchEvent(evt);
'
,
itemLabel
);
});
}
};
this
.
filterByActiveItems
=
function
(
index
)
{
return
this
.
getFilterElements
().
then
(
function
(
filters
)
{
this
.
filterByActiveItems
=
function
(
)
{
return
this
.
getFilterElements
().
then
(
function
(
filters
)
{
filters
[
1
].
click
();
});
}
};
this
.
filterByCompletedItems
=
function
(
index
)
{
return
this
.
getFilterElements
().
then
(
function
(
filters
)
{
this
.
filterByCompletedItems
=
function
(
)
{
return
this
.
getFilterElements
().
then
(
function
(
filters
)
{
filters
[
2
].
click
();
});
}
};
this
.
filterByAllItems
=
function
(
index
)
{
return
this
.
getFilterElements
().
then
(
function
(
filters
)
{
this
.
filterByAllItems
=
function
(
)
{
return
this
.
getFilterElements
().
then
(
function
(
filters
)
{
filters
[
0
].
click
();
});
}
}
module
.
exports
=
Page
;
\ No newline at end of file
};
};
browser-tests/pageLaxMode.js
View file @
e36fff78
var
webdriver
=
require
(
'
selenium-webdriver
'
),
Page
=
require
(
"
./page
"
);
'
use strict
'
;
function
PageLaxMode
(
browser
)
{
var
webdriver
=
require
(
'
selenium-webdriver
'
);
var
Page
=
require
(
'
./page
'
);
module
.
exports
=
function
PageLaxMode
(
browser
)
{
Page
.
apply
(
this
,
[
browser
]);
this
.
tryGetToggleForItemAtIndex
=
function
(
index
)
{
this
.
tryGetToggleForItemAtIndex
=
function
(
index
)
{
// the specification dictates that the checkbox should have the 'toggle' CSS class. Some implementations deviate from
// this, hence in lax mode we simply look for any checkboxes within the specified 'li'.
var
xpath
=
this
.
xPathForItemAtIndex
(
index
)
+
"
//input[@type='checkbox']
"
;
var
xpath
=
this
.
xPathForItemAtIndex
(
index
)
+
'
//input[@type="checkbox"]
'
;
return
browser
.
findElements
(
webdriver
.
By
.
xpath
(
xpath
));
}
};
this
.
getEditInputForItemAtIndex
=
function
(
index
)
{
this
.
getEditInputForItemAtIndex
=
function
(
index
)
{
// the specification dictates that the input element that allows the user to edit a todo item should have a CSS
// class of 'edit'. In lax mode, we also look for an input of type 'text'.
var
xpath
=
"
(
"
+
this
.
xPathForItemAtIndex
(
index
)
+
"
//input[@type='text']
"
+
"
|
"
+
this
.
xPathForItemAtIndex
(
index
)
+
"
//input[contains(@class,'edit')]
"
+
"
)
"
;
var
xpath
=
'
(
'
+
this
.
xPathForItemAtIndex
(
index
)
+
'
//input[@type="text"]
'
+
'
|
'
+
this
.
xPathForItemAtIndex
(
index
)
+
'
//input[contains(@class,"edit")]
'
+
'
)
'
;
return
browser
.
findElement
(
webdriver
.
By
.
xpath
(
xpath
));
}
}
module
.
exports
=
PageLaxMode
;
\ No newline at end of file
};
};
browser-tests/test.js
View file @
e36fff78
var
webdriver
=
require
(
'
selenium-webdriver
'
),
test
=
require
(
'
selenium-webdriver/testing
'
),
assert
=
require
(
"
assert
"
),
Page
=
require
(
"
./page
"
),
PageLaxMode
=
require
(
"
./pageLaxMode
"
),
TestOperations
=
require
(
"
./testOperations
"
);
exports
.
todoMVCTest
=
function
(
frameworkName
,
baseUrl
,
speedMode
,
laxMode
)
{
'
use strict
'
;
var
webdriver
=
require
(
'
selenium-webdriver
'
);
var
test
=
require
(
'
selenium-webdriver/testing
'
);
var
Page
=
require
(
'
./page
'
);
var
PageLaxMode
=
require
(
'
./pageLaxMode
'
);
var
TestOperations
=
require
(
'
./testOperations
'
);
module
.
exports
.
todoMVCTest
=
function
(
frameworkName
,
baseUrl
,
speedMode
,
laxMode
)
{
test
.
describe
(
'
TodoMVC -
'
+
frameworkName
,
function
()
{
var
otherUrl
=
"
http://localhost:8000/
"
;
var
TODO_ITEM_ONE
=
"
buy some cheese
"
;
var
TODO_ITEM_TWO
=
"
feed the cat
"
;
var
TODO_ITEM_THREE
=
"
book a doctors appointment
"
;
var
otherUrl
=
'
http://localhost:8000/
'
;
var
TODO_ITEM_ONE
=
'
buy some cheese
'
;
var
TODO_ITEM_TWO
=
'
feed the cat
'
;
var
TODO_ITEM_THREE
=
'
book a doctors appointment
'
;
var
browser
,
testOps
,
page
;
...
...
@@ -23,7 +24,7 @@ exports.todoMVCTest = function(frameworkName, baseUrl, speedMode, laxMode) {
function
launchBrowser
()
{
browser
=
new
webdriver
.
Builder
()
.
withCapabilities
({
browserName
:
"
chrome
"
})
.
withCapabilities
({
browserName
:
'
chrome
'
})
.
build
();
browser
.
get
(
baseUrl
);
...
...
@@ -51,7 +52,7 @@ exports.todoMVCTest = function(frameworkName, baseUrl, speedMode, laxMode) {
page
.
getItemElements
().
then
(
function
(
items
)
{
if
(
items
.
length
>
0
)
{
// find any items that are not complete
page
.
getNonCompletedItemElements
().
then
(
function
(
nonCompleteItems
)
{
page
.
getNonCompletedItemElements
().
then
(
function
(
nonCompleteItems
)
{
if
(
nonCompleteItems
.
length
>
0
)
{
page
.
clickMarkAllCompletedCheckBox
();
}
...
...
@@ -91,11 +92,11 @@ exports.todoMVCTest = function(frameworkName, baseUrl, speedMode, laxMode) {
test
.
it
(
'
should clear text input field when an item is added
'
,
function
()
{
page
.
enterItem
(
TODO_ITEM_ONE
);
testOps
.
assertItemInputFieldText
(
""
);
testOps
.
assertItemInputFieldText
(
''
);
});
test
.
it
(
'
should trim text input
'
,
function
()
{
page
.
enterItem
(
"
"
+
TODO_ITEM_ONE
+
"
"
);
page
.
enterItem
(
'
'
+
TODO_ITEM_ONE
+
'
'
);
testOps
.
assertItemText
(
0
,
TODO_ITEM_ONE
);
});
...
...
@@ -173,10 +174,10 @@ exports.todoMVCTest = function(frameworkName, baseUrl, speedMode, laxMode) {
createStandardItems
();
page
.
doubleClickItemAtIndex
(
1
);
page
.
editItemAtIndex
(
1
,
"
buy some sausages
"
+
webdriver
.
Key
.
ENTER
);
page
.
editItemAtIndex
(
1
,
'
buy some sausages
'
+
webdriver
.
Key
.
ENTER
);
testOps
.
assertItemText
(
0
,
TODO_ITEM_ONE
);
testOps
.
assertItemText
(
1
,
"
buy some sausages
"
);
testOps
.
assertItemText
(
1
,
'
buy some sausages
'
);
testOps
.
assertItemText
(
2
,
TODO_ITEM_THREE
);
});
...
...
@@ -198,10 +199,10 @@ exports.todoMVCTest = function(frameworkName, baseUrl, speedMode, laxMode) {
createStandardItems
();
page
.
doubleClickItemAtIndex
(
1
);
page
.
editItemAtIndex
(
1
,
"
buy some sausages
"
+
webdriver
.
Key
.
ENTER
);
page
.
editItemAtIndex
(
1
,
'
buy some sausages
'
+
webdriver
.
Key
.
ENTER
);
testOps
.
assertItemText
(
0
,
TODO_ITEM_ONE
);
testOps
.
assertItemText
(
1
,
"
buy some sausages
"
);
testOps
.
assertItemText
(
1
,
'
buy some sausages
'
);
testOps
.
assertItemText
(
2
,
TODO_ITEM_THREE
);
});
...
...
@@ -209,13 +210,13 @@ exports.todoMVCTest = function(frameworkName, baseUrl, speedMode, laxMode) {
createStandardItems
();
page
.
doubleClickItemAtIndex
(
1
);
page
.
editItemAtIndex
(
1
,
"
buy some sausages
"
);
page
.
editItemAtIndex
(
1
,
'
buy some sausages
'
);
// click a toggle button so that the blur() event is fired
page
.
toggleItemAtIndex
(
0
);
testOps
.
assertItemText
(
0
,
TODO_ITEM_ONE
);
testOps
.
assertItemText
(
1
,
"
buy some sausages
"
);
testOps
.
assertItemText
(
1
,
'
buy some sausages
'
);
testOps
.
assertItemText
(
2
,
TODO_ITEM_THREE
);
});
...
...
@@ -223,10 +224,10 @@ exports.todoMVCTest = function(frameworkName, baseUrl, speedMode, laxMode) {
createStandardItems
();
page
.
doubleClickItemAtIndex
(
1
);
page
.
editItemAtIndex
(
1
,
"
buy some sausages
"
+
webdriver
.
Key
.
ENTER
);
page
.
editItemAtIndex
(
1
,
'
buy some sausages
'
+
webdriver
.
Key
.
ENTER
);
testOps
.
assertItemText
(
0
,
TODO_ITEM_ONE
);
testOps
.
assertItemText
(
1
,
"
buy some sausages
"
);
testOps
.
assertItemText
(
1
,
'
buy some sausages
'
);
testOps
.
assertItemText
(
2
,
TODO_ITEM_THREE
);
});
...
...
@@ -245,7 +246,7 @@ exports.todoMVCTest = function(frameworkName, baseUrl, speedMode, laxMode) {
createStandardItems
();
page
.
doubleClickItemAtIndex
(
1
);
page
.
editItemAtIndex
(
1
,
"
foo
"
+
webdriver
.
Key
.
ESCAPE
);
page
.
editItemAtIndex
(
1
,
'
foo
'
+
webdriver
.
Key
.
ESCAPE
);
testOps
.
assertItemCount
(
3
);
testOps
.
assertItemText
(
0
,
TODO_ITEM_ONE
);
...
...
@@ -257,9 +258,9 @@ exports.todoMVCTest = function(frameworkName, baseUrl, speedMode, laxMode) {
test
.
describe
(
'
Counter
'
,
function
()
{
test
.
it
(
'
should display the current number of todo items
'
,
function
()
{
page
.
enterItem
(
TODO_ITEM_ONE
);
testOps
.
assertItemCountText
(
"
1 item left
"
);
testOps
.
assertItemCountText
(
'
1 item left
'
);
page
.
enterItem
(
TODO_ITEM_TWO
);
testOps
.
assertItemCountText
(
"
2 items left
"
);
testOps
.
assertItemCountText
(
'
2 items left
'
);
});
});
...
...
@@ -268,9 +269,9 @@ exports.todoMVCTest = function(frameworkName, baseUrl, speedMode, laxMode) {
test
.
it
(
'
should display the number of completed items
'
,
function
()
{
createStandardItems
();
page
.
toggleItemAtIndex
(
1
);
testOps
.
assertClearCompleteButtonText
(
"
Clear completed (1)
"
);
testOps
.
assertClearCompleteButtonText
(
'
Clear completed (1)
'
);
page
.
toggleItemAtIndex
(
2
);
testOps
.
assertClearCompleteButtonText
(
"
Clear completed (2)
"
);
testOps
.
assertClearCompleteButtonText
(
'
Clear completed (2)
'
);
});
test
.
it
(
'
should remove completed items when clicked
'
,
function
()
{
...
...
@@ -353,7 +354,7 @@ exports.todoMVCTest = function(frameworkName, baseUrl, speedMode, laxMode) {
testOps
.
assertItemText
(
2
,
TODO_ITEM_THREE
);
});
test
.
it
(
'
should highlight the currently applied filter
'
,
function
()
{
test
.
it
(
'
should highlight the currently applied filter
'
,
function
()
{
createStandardItems
();
// initially 'all' should be selected
...
...
@@ -367,4 +368,4 @@ exports.todoMVCTest = function(frameworkName, baseUrl, speedMode, laxMode) {
});
});
});
}
}
;
browser-tests/testOperations.js
View file @
e36fff78
var
assert
=
require
(
"
assert
"
);
'
use strict
'
;
var
assert
=
require
(
'
assert
'
);
function
TestOperations
(
page
)
{
...
...
@@ -8,153 +10,154 @@ function TestOperations(page) {
// it is either not in the DOM, or is in the DOM but not visible.
function
testIsHidden
(
elements
)
{
if
(
elements
.
length
===
1
)
{
elements
[
0
].
isDisplayed
().
then
(
function
(
isDisplayed
)
{
elements
[
0
].
isDisplayed
().
then
(
function
(
isDisplayed
)
{
assert
(
!
isDisplayed
);
})
});
}
}
function
testIsVisible
(
elements
)
{
assert
.
equal
(
1
,
elements
.
length
);
elements
[
0
].
isDisplayed
().
then
(
function
(
isDisplayed
)
{
elements
[
0
].
isDisplayed
().
then
(
function
(
isDisplayed
)
{
assert
(
isDisplayed
);
});
}
this
.
assertClearCompleteButtonIsHidden
=
function
()
{
page
.
tryGetClearCompleteButton
().
then
(
function
(
element
)
{
this
.
assertClearCompleteButtonIsHidden
=
function
()
{
page
.
tryGetClearCompleteButton
().
then
(
function
(
element
)
{
testIsHidden
(
element
);
});
}
};
this
.
assertClearCompleteButtonIsVisible
=
function
()
{
page
.
tryGetClearCompleteButton
().
then
(
function
(
element
)
{
this
.
assertClearCompleteButtonIsVisible
=
function
()
{
page
.
tryGetClearCompleteButton
().
then
(
function
(
element
)
{
testIsVisible
(
element
);
});
}
};
this
.
assertItemCount
=
function
(
itemCount
)
{
page
.
getItemElements
().
then
(
function
(
toDoItems
)
{
this
.
assertItemCount
=
function
(
itemCount
)
{
page
.
getItemElements
().
then
(
function
(
toDoItems
)
{
assert
.
equal
(
itemCount
,
toDoItems
.
length
);
});
}
};
this
.
assertClearCompleteButtonText
=
function
(
buttonText
)
{
page
.
tryGetClearCompleteButton
().
then
(
function
(
elements
)
{
this
.
assertClearCompleteButtonText
=
function
(
buttonText
)
{
page
.
tryGetClearCompleteButton
().
then
(
function
(
elements
)
{
var
button
=
elements
[
0
];
button
.
getText
().
then
(
function
(
text
)
{
button
.
getText
().
then
(
function
(
text
)
{
assert
.
equal
(
buttonText
,
text
);
});
});
}
};
this
.
assertMainSectionIsHidden
=
function
()
{
page
.
tryGetMainSectionElement
().
then
(
function
(
mainSection
)
{
this
.
assertMainSectionIsHidden
=
function
()
{
page
.
tryGetMainSectionElement
().
then
(
function
(
mainSection
)
{
testIsHidden
(
mainSection
);
});
}
};
this
.
assertFooterIsHidden
=
function
()
{
page
.
tryGetFooterElement
().
then
(
function
(
footer
)
{
this
.
assertFooterIsHidden
=
function
()
{
page
.
tryGetFooterElement
().
then
(
function
(
footer
)
{
testIsHidden
(
footer
);
});
}
};
this
.
assertMainSectionIsVisible
=
function
()
{
page
.
tryGetMainSectionElement
().
then
(
function
(
mainSection
)
{
this
.
assertMainSectionIsVisible
=
function
()
{
page
.
tryGetMainSectionElement
().
then
(
function
(
mainSection
)
{
testIsVisible
(
mainSection
);
});
}
};
this
.
assertItemToggleIsHidden
=
function
()
{
page
.
tryGetToggleForItemAtIndex
().
then
(
function
(
toggleItem
)
{
this
.
assertItemToggleIsHidden
=
function
()
{
page
.
tryGetToggleForItemAtIndex
().
then
(
function
(
toggleItem
)
{
testIsHidden
(
toggleItem
);
});
}
};
this
.
assertItemLabelIsHidden
=
function
()
{
page
.
tryGetItemLabelAtIndex
().
then
(
function
(
toggleItem
)
{
this
.
assertItemLabelIsHidden
=
function
()
{
page
.
tryGetItemLabelAtIndex
().
then
(
function
(
toggleItem
)
{
testIsHidden
(
toggleItem
);
});
}
};
this
.
assertFooterIsVisible
=
function
()
{
page
.
tryGetFooterElement
().
then
(
function
(
footer
)
{
this
.
assertFooterIsVisible
=
function
()
{
page
.
tryGetFooterElement
().
then
(
function
(
footer
)
{
testIsVisible
(
footer
);
});
}
};
this
.
assertItemInputFieldText
=
function
(
text
)
{
page
.
getItemInputField
().
getText
().
then
(
function
(
inputFieldText
)
{
this
.
assertItemInputFieldText
=
function
(
text
)
{
page
.
getItemInputField
().
getText
().
then
(
function
(
inputFieldText
)
{
assert
.
equal
(
text
,
inputFieldText
);
});
}
};
this
.
assertItemText
=
function
(
itemIndex
,
textToAssert
)
{
page
.
getItemLabelAtIndex
(
itemIndex
).
getText
().
then
(
function
(
text
)
{
this
.
assertItemText
=
function
(
itemIndex
,
textToAssert
)
{
page
.
getItemLabelAtIndex
(
itemIndex
).
getText
().
then
(
function
(
text
)
{
assert
.
equal
(
textToAssert
,
text
.
trim
());
});
}
};
this
.
assertItemCountText
=
function
(
textToAssert
)
{
page
.
getItemsCountElement
().
getText
().
then
(
function
(
text
)
{
this
.
assertItemCountText
=
function
(
textToAssert
)
{
page
.
getItemsCountElement
().
getText
().
then
(
function
(
text
)
{
assert
.
equal
(
textToAssert
,
text
.
trim
());
});
}
};
// tests for the presence of the 'completed' CSS class for the item at the given index
this
.
assertItemAtIndexIsCompleted
=
function
(
index
)
{
page
.
getItemElements
().
then
(
function
(
toDoItems
)
{
toDoItems
[
index
].
getAttribute
(
"
class
"
).
then
(
function
(
cssClass
)
{
assert
(
cssClass
.
indexOf
(
"
completed
"
)
!==
-
1
);
this
.
assertItemAtIndexIsCompleted
=
function
(
index
)
{
page
.
getItemElements
().
then
(
function
(
toDoItems
)
{
toDoItems
[
index
].
getAttribute
(
'
class
'
).
then
(
function
(
cssClass
)
{
assert
(
cssClass
.
indexOf
(
'
completed
'
)
!==
-
1
);
});
});
}
};
this
.
assertItemAtIndexIsNotCompleted
=
function
(
index
)
{
page
.
getItemElements
().
then
(
function
(
toDoItems
)
{
toDoItems
[
index
].
getAttribute
(
"
class
"
).
then
(
function
(
cssClass
)
{
this
.
assertItemAtIndexIsNotCompleted
=
function
(
index
)
{
page
.
getItemElements
().
then
(
function
(
toDoItems
)
{
toDoItems
[
index
].
getAttribute
(
'
class
'
).
then
(
function
(
cssClass
)
{
// the maria implementation uses an 'incompleted' CSS class which is redundant
// TODO: this should really be moved into the pageLaxMode
assert
(
cssClass
.
indexOf
(
"
completed
"
)
===
-
1
||
cssClass
.
indexOf
(
"
incompleted
"
)
!==
-
1
);
assert
(
cssClass
.
indexOf
(
'
completed
'
)
===
-
1
||
cssClass
.
indexOf
(
'
incompleted
'
)
!==
-
1
);
});
});
}
};
function
isSelected
(
cssClass
)
{
return
cssClass
.
indexOf
(
"
selected
"
)
!==
-
1
;
return
cssClass
.
indexOf
(
'
selected
'
)
!==
-
1
;
}
this
.
assertFilterAtIndexIsSelected
=
function
(
index
)
{
page
.
getFilterElements
().
then
(
function
(
filterElements
)
{
filterElements
[
0
].
getAttribute
(
"
class
"
).
then
(
function
(
cssClass
)
{
assert
(
index
==
0
?
isSelected
(
cssClass
)
:
!
isSelected
(
cssClass
));
this
.
assertFilterAtIndexIsSelected
=
function
(
index
)
{
page
.
getFilterElements
().
then
(
function
(
filterElements
)
{
filterElements
[
0
].
getAttribute
(
'
class
'
).
then
(
function
(
cssClass
)
{
assert
(
index
=
==
0
?
isSelected
(
cssClass
)
:
!
isSelected
(
cssClass
));
});
filterElements
[
1
].
getAttribute
(
"
class
"
).
then
(
function
(
cssClass
)
{
assert
(
index
==
1
?
isSelected
(
cssClass
)
:
!
isSelected
(
cssClass
));
filterElements
[
1
].
getAttribute
(
'
class
'
).
then
(
function
(
cssClass
)
{
assert
(
index
=
==
1
?
isSelected
(
cssClass
)
:
!
isSelected
(
cssClass
));
});
filterElements
[
2
].
getAttribute
(
"
class
"
).
then
(
function
(
cssClass
)
{
assert
(
index
==
2
?
isSelected
(
cssClass
)
:
!
isSelected
(
cssClass
));
filterElements
[
2
].
getAttribute
(
'
class
'
).
then
(
function
(
cssClass
)
{
assert
(
index
=
==
2
?
isSelected
(
cssClass
)
:
!
isSelected
(
cssClass
));
});
});
}
};
this
.
assertCompleteAllIsClear
=
function
()
{
page
.
getMarkAllCompletedCheckBox
().
then
(
function
(
markAllCompleted
)
{
markAllCompleted
.
isSelected
().
then
(
function
(
isSelected
)
{
this
.
assertCompleteAllIsClear
=
function
()
{
page
.
getMarkAllCompletedCheckBox
().
then
(
function
(
markAllCompleted
)
{
markAllCompleted
.
isSelected
().
then
(
function
(
isSelected
)
{
assert
(
!
isSelected
);
})
});
}
});
};
this
.
assertCompleteAllIsChecked
=
function
()
{
page
.
getMarkAllCompletedCheckBox
().
then
(
function
(
markAllCompleted
)
{
markAllCompleted
.
isSelected
().
then
(
function
(
isSelected
)
{
this
.
assertCompleteAllIsChecked
=
function
()
{
page
.
getMarkAllCompletedCheckBox
().
then
(
function
(
markAllCompleted
)
{
markAllCompleted
.
isSelected
().
then
(
function
(
isSelected
)
{
assert
(
isSelected
);
})
});
}
});
};
}
module
.
exports
=
TestOperations
;
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment