support for non-alpha characters for keyCode
This commit is contained in:
parent
399a8fbfb9
commit
fb97fe8577
|
@ -1461,18 +1461,29 @@ describe Capybara::Driver::Webkit do
|
||||||
|
|
||||||
it "returns the charCode for the keypressed" do
|
it "returns the charCode for the keypressed" do
|
||||||
charCode_for("a").should == "97"
|
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
|
end
|
||||||
|
|
||||||
it "returns the keyCode for the keypressed" do
|
it "returns the keyCode for the keypressed" do
|
||||||
keyCode_for("a").should == "97"
|
keyCode_for("a").should == "97"
|
||||||
keyCode_for("A").should == "65"
|
keyCode_for("A").should == "65"
|
||||||
keyCode_for("\r").should == "13"
|
keyCode_for("\r").should == "13"
|
||||||
|
keyCode_for(",").should == "44"
|
||||||
|
keyCode_for("<").should == "60"
|
||||||
|
keyCode_for("0").should == "48"
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns the which for the keypressed" do
|
it "returns the which for the keypressed" do
|
||||||
which_for("a").should == "97"
|
which_for("a").should == "97"
|
||||||
which_for("A").should == "65"
|
which_for("A").should == "65"
|
||||||
which_for("\r").should == "13"
|
which_for("\r").should == "13"
|
||||||
|
which_for(",").should == "44"
|
||||||
|
which_for("<").should == "60"
|
||||||
|
which_for("0").should == "48"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -1481,18 +1492,27 @@ describe Capybara::Driver::Webkit do
|
||||||
charCode_for("a").should == "0"
|
charCode_for("a").should == "0"
|
||||||
charCode_for("A").should == "0"
|
charCode_for("A").should == "0"
|
||||||
charCode_for("\r").should == "0"
|
charCode_for("\r").should == "0"
|
||||||
|
charCode_for(",").should == "0"
|
||||||
|
charCode_for("<").should == "0"
|
||||||
|
charCode_for("0").should == "0"
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns the keyCode for the event" do
|
it "returns the keyCode for the event" do
|
||||||
keyCode_for("a").should == "65"
|
keyCode_for("a").should == "65"
|
||||||
keyCode_for("A").should == "65"
|
keyCode_for("A").should == "65"
|
||||||
keyCode_for("\r").should == "13"
|
keyCode_for("\r").should == "13"
|
||||||
|
keyCode_for(",").should == "188"
|
||||||
|
keyCode_for("<").should == "188"
|
||||||
|
keyCode_for("0").should == "48"
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns the which for the event" do
|
it "returns the which for the event" do
|
||||||
which_for("a").should == "65"
|
which_for("a").should == "65"
|
||||||
which_for("A").should == "65"
|
which_for("A").should == "65"
|
||||||
which_for("\r").should == "13"
|
which_for("\r").should == "13"
|
||||||
|
which_for(",").should == "188"
|
||||||
|
which_for("<").should == "188"
|
||||||
|
which_for("0").should == "48"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -163,6 +163,49 @@ Capybara = {
|
||||||
return this.nodes[index].value;
|
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) {
|
set: function (index, value) {
|
||||||
var length, maxLength, node, strindex, textTypes, type;
|
var length, maxLength, node, strindex, textTypes, type;
|
||||||
|
|
||||||
|
@ -183,7 +226,7 @@ Capybara = {
|
||||||
node.value = "";
|
node.value = "";
|
||||||
for (strindex = 0; strindex < length; strindex++) {
|
for (strindex = 0; strindex < length; strindex++) {
|
||||||
node.value += value[strindex];
|
node.value += value[strindex];
|
||||||
var keyCode = value[strindex].toUpperCase().charCodeAt(0);
|
var keyCode = this.characterToKeyCode(value[strindex]);
|
||||||
this.keyupdown(index, "keydown", keyCode);
|
this.keyupdown(index, "keydown", keyCode);
|
||||||
this.keypress(index, false, false, false, false, value.charCodeAt(strindex), value.charCodeAt(strindex));
|
this.keypress(index, false, false, false, false, value.charCodeAt(strindex), value.charCodeAt(strindex));
|
||||||
this.keyupdown(index, "keyup", keyCode);
|
this.keyupdown(index, "keyup", keyCode);
|
||||||
|
|
Loading…
Reference in New Issue