Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

support for non-alpha characters for keyCode

  • Loading branch information...
commit fb97fe8577661d73ba715853ff39ef059ba2d30a 1 parent 399a8fb
@willryan willryan authored
Showing with 64 additions and 1 deletion.
  1. +20 −0 spec/driver_spec.rb
  2. +44 −1 src/capybara.js
View
20 spec/driver_spec.rb
@@ -1461,18 +1461,29 @@ def which_for(character)
it "returns the charCode for the keypressed" do
charCode_for("a").should == "97"
+ charCode_for("A").should == "65"
+ charCode_for("\r").should == "13"
+ charCode_for(",").should == "44"
+ charCode_for("<").should == "60"
+ charCode_for("0").should == "48"
end
it "returns the keyCode for the keypressed" do
keyCode_for("a").should == "97"
keyCode_for("A").should == "65"
keyCode_for("\r").should == "13"
+ keyCode_for(",").should == "44"
+ keyCode_for("<").should == "60"
+ keyCode_for("0").should == "48"
end
it "returns the which for the keypressed" do
which_for("a").should == "97"
which_for("A").should == "65"
which_for("\r").should == "13"
+ which_for(",").should == "44"
+ which_for("<").should == "60"
+ which_for("0").should == "48"
end
end
@@ -1481,18 +1492,27 @@ def which_for(character)
charCode_for("a").should == "0"
charCode_for("A").should == "0"
charCode_for("\r").should == "0"
+ charCode_for(",").should == "0"
+ charCode_for("<").should == "0"
+ charCode_for("0").should == "0"
end
it "returns the keyCode for the event" do
keyCode_for("a").should == "65"
keyCode_for("A").should == "65"
keyCode_for("\r").should == "13"
+ keyCode_for(",").should == "188"
+ keyCode_for("<").should == "188"
+ keyCode_for("0").should == "48"
end
it "returns the which for the event" do
which_for("a").should == "65"
which_for("A").should == "65"
which_for("\r").should == "13"
+ which_for(",").should == "188"
+ which_for("<").should == "188"
+ which_for("0").should == "48"
end
end
View
45 src/capybara.js
@@ -163,6 +163,49 @@ Capybara = {
return this.nodes[index].value;
},
+ characterToKeyCode: function(character) {
+ var code = character.toUpperCase().charCodeAt(0);
+ var specialKeys = {
+ 96: 192, //`
+ 45: 189, //-
+ 61: 187, //=
+ 91: 219, //[
+ 93: 221, //]
+ 92: 220, //\
+ 59: 186, //;
+ 39: 222, //'
+ 44: 188, //,
+ 46: 190, //.
+ 47: 191, ///
+ 127: 46, //delete
+ 126: 192, //~
+ 33: 49, //!
+ 64: 50, //@
+ 35: 51, //#
+ 36: 52, //$
+ 37: 53, //%
+ 94: 54, //^
+ 38: 55, //&
+ 42: 56, //*
+ 40: 57, //(
+ 41: 48, //)
+ 95: 189, //_
+ 43: 187, //+
+ 123: 219, //{
+ 125: 221, //}
+ 124: 220, //|
+ 58: 186, //:
+ 34: 222, //"
+ 60: 188, //<
+ 62: 190, //>
+ 63: 191 //?
+ };
+ if (specialKeys[code]) {
+ code = specialKeys[code];
+ }
+ return code;
+ },
+
set: function (index, value) {
var length, maxLength, node, strindex, textTypes, type;
@@ -183,7 +226,7 @@ Capybara = {
node.value = "";
for (strindex = 0; strindex < length; strindex++) {
node.value += value[strindex];
- var keyCode = value[strindex].toUpperCase().charCodeAt(0);
+ var keyCode = this.characterToKeyCode(value[strindex]);
this.keyupdown(index, "keydown", keyCode);
this.keypress(index, false, false, false, false, value.charCodeAt(strindex), value.charCodeAt(strindex));
this.keyupdown(index, "keyup", keyCode);
Please sign in to comment.
Something went wrong with that request. Please try again.