Commit b66b6b90 b66b6b90e7a49b7ae6696c2a956cac91d09f7c67 by Clochix

Add some tests to CasperUtils.keyboardEvent

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