Commit b66b6b90 b66b6b90e7a49b7ae6696c2a956cac91d09f7c67 by Clochix

Add some tests to CasperUtils.keyboardEvent

1 parent 3121f0d6
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>CasperJS test keyboard events</title>
6 </head>
7 <body>
8 <form>
9 <textarea id="test1"></textarea>
10 <select id="test2">
11 <option value="1">1</option>
12 <option value="2">2</option>
13 <option value="3">3</option>
14 <option value="4">4</option>
15 <option value="5">5</option>
16 <option value="6">6</option>
17 </select>
18 </form>
19 </body>
20 </html>
21
1 per.start('tests/site/keyboard-events.html');
2
3 casper.then(function() {
4 this.test.comment('CasperUtils.keyboardEvent()');
5
6 this.test.assert(this.keyboardEvent('keypress', '#test1', '0'), 'CasperUtils.keyboardEvent() can dispatch a keypress event');
7 this.test.assert(this.keyboardEvent('keydown', '#test1', '1'), 'CasperUtils.keyboardEvent() can dispatch a keydown event');
8 this.test.assert(this.keyboardEvent('keyup', '#test1', '2'), 'CasperUtils.keyboardEvent() can dispatch a keyup event');
9 this.test.assert(this.keyboardEvent('keydown', '#test2', 'Down'), 'CasperUtils.keyboardEvent() can dispatch an arrow key');
10 this.keyboardEvent('keydown', '#test2', 'Down');
11 this.keyboardEvent('keydown', '#test2', 'Down');
12
13 var results = this.getGlobal('results');
14 this.test.assertEvalEquals(function() {return document.querySelector('#test1').value;}, "012", 'CasperUtils.keyboardEvent() can set the value of a textarea');
15 this.test.assertEvalEquals(function() {return document.querySelector('#test2').selectedIndex;}, 3, 'CasperUtils.keyboardEvent() can update the value of a select');
16 });
17
18 casper.run(function() {
19 this.test.done();
20 });
21