Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
John McEleney
/
casperjs
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
Commit
7db58eff
...
7db58effa1887f1c40f19b3431e31536ad904d6e
authored
2012-06-27 19:15:04 +0200
by
Nicolas Perriault
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Revert #160 related commits
-
eb584737
. -
b66b6b90
. -
3121f0d6
.
1 parent
eb584737
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
0 additions
and
103 deletions
modules/casper.js
modules/clientutils.js
tests/site/keyboard-events.html
tests/suites/casper/keyboardevents.js
modules/casper.js
View file @
7db58ef
...
...
@@ -869,38 +869,6 @@ Casper.prototype.mouseEvent = function mouseEvent(type, selector) {
};
/**
* Emulates an keyboard event on the element from the provided selector
*
* In case of success, `true` is returned, `false` otherwise.
*
* @param String type Type of event to emulate
* @param String selector A DOM CSS3 compatible selector
* @param String character Character value of the key pressed
* @param String key Key value of the key pressed
* @return Boolean
*/
Casper
.
prototype
.
keyboardEvent
=
function
keyboardEvent
(
type
,
selector
,
character
,
key
)
{
"use strict"
;
this
.
log
(
"Keyboard event '"
+
type
+
"' on selector: "
+
selector
,
"debug"
);
if
(
!
this
.
exists
(
selector
))
{
throw
new
CasperError
(
f
(
"Cannot dispatch %s event on nonexistent selector: %s"
,
type
,
selector
));
}
var
eventSuccess
=
this
.
evaluate
(
function
(
type
,
selector
,
character
,
key
)
{
return
window
.
__utils__
.
keyboardEvent
(
type
,
selector
,
character
,
key
);
},
{
type
:
type
,
selector
:
selector
,
character
:
character
,
key
:
key
});
if
(
!
eventSuccess
)
{
this
.
log
(
f
(
"Couldn't emulate '%s' event on %s: %s"
,
type
,
selector
,
e
),
"error"
);
return
false
;
}
return
true
;
};
/**
* Performs an HTTP request, with optional settings.
*
* Available settings are:
...
...
modules/clientutils.js
View file @
7db58ef
...
...
@@ -415,31 +415,6 @@
};
/**
* Dispatches a keyboard event to the DOM element behind the provided selector.
*
* @see http://www.w3.org/TR/DOM-Level-3-Events/#events-KeyboardEvent
*
* @param String type Type of event to dispatch
* @param String selector A CSS3 selector to the element to click
* @param String character Character value of the key pressed
* @param String key Key value of the key pressed
* @return Boolean
*/
this
.
keyboardEvent
=
function
keyboardEvent
(
type
,
selector
,
character
,
key
)
{
var
elem
=
this
.
findOne
(
selector
);
if
(
!
elem
)
{
this
.
log
(
"keyboardEvent(): Couldn't find any element matching '"
+
selector
+
"' selector"
,
"error"
);
return
false
;
}
var
evt
=
document
.
createEvent
(
"KeyboardEvents"
);
evt
.
initKeyboardEvent
(
type
,
true
,
true
,
window
,
character
,
key
,
false
,
false
,
false
,
false
,
false
);
elem
.
value
+=
character
;
// dispatchEvent return value is false if at least one of the event
// handlers which handled this event called preventDefault
return
elem
.
dispatchEvent
(
evt
);
};
/**
* Processes a selector input, either as a string or an object.
*
* If passed an object, if must be of the form:
...
...
tests/site/keyboard-events.html
deleted
100644 → 0
View file @
eb58473
<!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>
tests/suites/casper/keyboardevents.js
deleted
100644 → 0
View file @
eb58473
casper
.
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
();
});
Please
register
or
sign in
to post a comment