capybara-webkit 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/capybara-webkit.gemspec +4 -2
- data/lib/capybara/driver/webkit/node.rb +5 -1
- data/lib/capybara_webkit_builder.rb +9 -7
- data/spec/driver_spec.rb +51 -6
- data/src/capybara.js +33 -5
- data/src/webkit_server.pro +1 -0
- metadata +10 -4
data/.gitignore
CHANGED
data/capybara-webkit.gemspec
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = "capybara-webkit"
|
3
|
-
s.version = "0.
|
3
|
+
s.version = "0.4.0"
|
4
4
|
s.authors = ["thoughtbot", "Joe Ferris", "Jason Morrison", "Tristan Dunn",
|
5
|
-
"Joshua Clayton", "Yuichi Tateno", "Aaron Gibralter"
|
5
|
+
"Joshua Clayton", "Yuichi Tateno", "Aaron Gibralter",
|
6
|
+
"Vasily Reys", "petrushka", "John Bintz",
|
7
|
+
"Christopher Meiklejohn", "John Barker", "Jeremy Wells"]
|
6
8
|
s.email = "support@thoughtbot.com"
|
7
9
|
s.files = `git ls-files`.split("\n")
|
8
10
|
s.test_files = `git ls-files -- {spec,features}/*`.split("\n")
|
@@ -6,7 +6,7 @@ class Capybara::Driver::Webkit
|
|
6
6
|
|
7
7
|
def [](name)
|
8
8
|
value = invoke("attribute", name)
|
9
|
-
if name == 'checked'
|
9
|
+
if name == 'checked' || name == 'disabled'
|
10
10
|
value == 'true'
|
11
11
|
else
|
12
12
|
value
|
@@ -53,6 +53,10 @@ class Capybara::Driver::Webkit
|
|
53
53
|
invoke("visible") == "true"
|
54
54
|
end
|
55
55
|
|
56
|
+
def disabled?
|
57
|
+
self['disabled']
|
58
|
+
end
|
59
|
+
|
56
60
|
def path
|
57
61
|
raise Capybara::NotSupportedByDriverError
|
58
62
|
end
|
@@ -4,7 +4,14 @@ module CapybaraWebkitBuilder
|
|
4
4
|
extend self
|
5
5
|
|
6
6
|
def makefile
|
7
|
-
|
7
|
+
qmake_binaries = ['qmake', 'qmake-qt4']
|
8
|
+
qmake = qmake_binaries.detect { |qmake| system("which #{qmake}") }
|
9
|
+
case RUBY_PLATFORM
|
10
|
+
when /linux/
|
11
|
+
system("#{qmake} -spec linux-g++")
|
12
|
+
else
|
13
|
+
system("#{qmake} -spec macx-g++")
|
14
|
+
end
|
8
15
|
end
|
9
16
|
|
10
17
|
def qmake
|
@@ -15,12 +22,7 @@ module CapybaraWebkitBuilder
|
|
15
22
|
system("make") or return false
|
16
23
|
|
17
24
|
FileUtils.mkdir("bin") unless File.directory?("bin")
|
18
|
-
|
19
|
-
if File.exist?("src/webkit_server.app")
|
20
|
-
FileUtils.cp("src/webkit_server.app/Contents/MacOS/webkit_server", "bin", :preserve => true)
|
21
|
-
else
|
22
|
-
FileUtils.cp("src/webkit_server", "bin", :preserve => true)
|
23
|
-
end
|
25
|
+
FileUtils.cp("src/webkit_server", "bin", :preserve => true)
|
24
26
|
end
|
25
27
|
|
26
28
|
def build_all
|
data/spec/driver_spec.rb
CHANGED
@@ -118,6 +118,7 @@ describe Capybara::Driver::Webkit do
|
|
118
118
|
<div id="display_none">
|
119
119
|
<div id="invisible">Can't see me</div>
|
120
120
|
</div>
|
121
|
+
<input type="text" disabled="disabled"/>
|
121
122
|
<script type="text/javascript">
|
122
123
|
document.write("<p id='greeting'>he" + "llo</p>");
|
123
124
|
</script>
|
@@ -243,6 +244,10 @@ describe Capybara::Driver::Webkit do
|
|
243
244
|
subject.find("//p").first.tag_name.should == "p"
|
244
245
|
end
|
245
246
|
|
247
|
+
it "reads disabled property" do
|
248
|
+
subject.find("//input").first.should be_disabled
|
249
|
+
end
|
250
|
+
|
246
251
|
it "finds visible elements" do
|
247
252
|
subject.find("//p").first.should be_visible
|
248
253
|
subject.find("//*[@id='invisible']").first.should_not be_visible
|
@@ -256,6 +261,7 @@ describe Capybara::Driver::Webkit do
|
|
256
261
|
<html><body>
|
257
262
|
<form action="/" method="GET">
|
258
263
|
<input type="text" name="foo" value="bar"/>
|
264
|
+
<input type="text" id="disabled_input" disabled="disabled"/>
|
259
265
|
<input type="checkbox" name="checkedbox" value="1" checked="checked"/>
|
260
266
|
<input type="checkbox" name="uncheckedbox" value="2"/>
|
261
267
|
<select name="animal">
|
@@ -377,6 +383,17 @@ describe Capybara::Driver::Webkit do
|
|
377
383
|
unchecked_box.set(false)
|
378
384
|
unchecked_box['checked'].should_not be_true
|
379
385
|
end
|
386
|
+
|
387
|
+
let(:enabled_input) { subject.find("//input[@name='foo']").first }
|
388
|
+
let(:disabled_input) { subject.find("//input[@id='disabled_input']").first }
|
389
|
+
|
390
|
+
it "knows a disabled input is disabled" do
|
391
|
+
disabled_input['disabled'].should be_true
|
392
|
+
end
|
393
|
+
|
394
|
+
it "knows a not disabled input is not disabled" do
|
395
|
+
enabled_input['disabled'].should_not be_true
|
396
|
+
end
|
380
397
|
end
|
381
398
|
|
382
399
|
context "form events app" do
|
@@ -405,6 +422,7 @@ describe Capybara::Driver::Webkit do
|
|
405
422
|
var element = elements[i];
|
406
423
|
element.addEventListener("focus", recordEvent);
|
407
424
|
element.addEventListener("keydown", recordEvent);
|
425
|
+
element.addEventListener("keypress", recordEvent);
|
408
426
|
element.addEventListener("keyup", recordEvent);
|
409
427
|
element.addEventListener("change", recordEvent);
|
410
428
|
element.addEventListener("blur", recordEvent);
|
@@ -419,19 +437,27 @@ describe Capybara::Driver::Webkit do
|
|
419
437
|
end
|
420
438
|
end
|
421
439
|
|
440
|
+
let(:newtext) { 'newvalue' }
|
441
|
+
|
442
|
+
let(:keyevents) do
|
443
|
+
(%w{focus} +
|
444
|
+
newtext.length.times.collect { %w{keydown keypress keyup} } +
|
445
|
+
%w{change blur}).flatten
|
446
|
+
end
|
447
|
+
|
422
448
|
it "triggers text input events" do
|
423
|
-
subject.find("//input[@type='text']").first.set(
|
424
|
-
subject.find("//li").map(&:text).should ==
|
449
|
+
subject.find("//input[@type='text']").first.set(newtext)
|
450
|
+
subject.find("//li").map(&:text).should == keyevents
|
425
451
|
end
|
426
452
|
|
427
453
|
it "triggers textarea input events" do
|
428
|
-
subject.find("//textarea").first.set(
|
429
|
-
subject.find("//li").map(&:text).should ==
|
454
|
+
subject.find("//textarea").first.set(newtext)
|
455
|
+
subject.find("//li").map(&:text).should == keyevents
|
430
456
|
end
|
431
457
|
|
432
458
|
it "triggers password input events" do
|
433
|
-
subject.find("//input[@type='password']").first.set(
|
434
|
-
subject.find("//li").map(&:text).should ==
|
459
|
+
subject.find("//input[@type='password']").first.set(newtext)
|
460
|
+
subject.find("//li").map(&:text).should == keyevents
|
435
461
|
end
|
436
462
|
|
437
463
|
it "triggers radio input events" do
|
@@ -453,7 +479,17 @@ describe Capybara::Driver::Webkit do
|
|
453
479
|
<div id="change">Change me</div>
|
454
480
|
<div id="mouseup">Push me</div>
|
455
481
|
<div id="mousedown">Release me</div>
|
482
|
+
<form action="/" method="GET">
|
483
|
+
<select id="change_select" name="change_select">
|
484
|
+
<option value="1" id="option-1" selected="selected">one</option>
|
485
|
+
<option value="2" id="option-2">two</option>
|
486
|
+
</select>
|
487
|
+
</form>
|
456
488
|
<script type="text/javascript">
|
489
|
+
document.getElementById("change_select").
|
490
|
+
addEventListener("change", function () {
|
491
|
+
this.className = "triggered";
|
492
|
+
});
|
457
493
|
document.getElementById("change").
|
458
494
|
addEventListener("change", function () {
|
459
495
|
this.className = "triggered";
|
@@ -491,6 +527,15 @@ describe Capybara::Driver::Webkit do
|
|
491
527
|
subject.find("//*[@class='triggered']").should_not be_empty
|
492
528
|
end
|
493
529
|
|
530
|
+
it "fires a change on select" do
|
531
|
+
select = subject.find("//select").first
|
532
|
+
select.value.should == "1"
|
533
|
+
option = subject.find("//option[@id='option-2']").first
|
534
|
+
option.select_option
|
535
|
+
select.value.should == "2"
|
536
|
+
subject.find("//select[@class='triggered']").should_not be_empty
|
537
|
+
end
|
538
|
+
|
494
539
|
it "fires drag events" do
|
495
540
|
draggable = subject.find("//*[@id='mousedown']").first
|
496
541
|
container = subject.find("//*[@id='mouseup']").first
|
data/src/capybara.js
CHANGED
@@ -31,9 +31,16 @@ Capybara = {
|
|
31
31
|
},
|
32
32
|
|
33
33
|
attribute: function (index, name) {
|
34
|
-
|
34
|
+
switch(name) {
|
35
|
+
case 'checked':
|
35
36
|
return this.nodes[index].checked;
|
36
|
-
|
37
|
+
break;
|
38
|
+
|
39
|
+
case 'disabled':
|
40
|
+
return this.nodes[index].disabled;
|
41
|
+
break;
|
42
|
+
|
43
|
+
default:
|
37
44
|
return this.nodes[index].getAttribute(name);
|
38
45
|
}
|
39
46
|
},
|
@@ -54,6 +61,19 @@ Capybara = {
|
|
54
61
|
this.nodes[index].dispatchEvent(eventObject);
|
55
62
|
},
|
56
63
|
|
64
|
+
keypress: function(index, altKey, ctrlKey, shiftKey, metaKey, keyCode, charCode) {
|
65
|
+
var eventObject = document.createEvent("Events");
|
66
|
+
eventObject.initEvent('keypress', true, true);
|
67
|
+
eventObject.window = window;
|
68
|
+
eventObject.altKey = altKey;
|
69
|
+
eventObject.ctrlKey = ctrlKey;
|
70
|
+
eventObject.shiftKey = shiftKey;
|
71
|
+
eventObject.metaKey = metaKey;
|
72
|
+
eventObject.keyCode = keyCode;
|
73
|
+
eventObject.charCode = charCode;
|
74
|
+
this.nodes[index].dispatchEvent(eventObject);
|
75
|
+
},
|
76
|
+
|
57
77
|
visible: function (index) {
|
58
78
|
var element = this.nodes[index];
|
59
79
|
while (element) {
|
@@ -73,9 +93,13 @@ Capybara = {
|
|
73
93
|
var type = (node.type || node.tagName).toLowerCase();
|
74
94
|
if (type == "text" || type == "textarea" || type == "password") {
|
75
95
|
this.trigger(index, "focus");
|
76
|
-
node.value =
|
77
|
-
|
78
|
-
|
96
|
+
node.value = "";
|
97
|
+
for(var strindex = 0; strindex < value.length; strindex++) {
|
98
|
+
node.value += value[strindex];
|
99
|
+
this.trigger(index, "keydown");
|
100
|
+
this.keypress(index, false, false, false, false, 0, value[strindex]);
|
101
|
+
this.trigger(index, "keyup");
|
102
|
+
}
|
79
103
|
this.trigger(index, "change");
|
80
104
|
this.trigger(index, "blur");
|
81
105
|
} else if(type == "checkbox" || type == "radio") {
|
@@ -87,11 +111,15 @@ Capybara = {
|
|
87
111
|
},
|
88
112
|
|
89
113
|
selectOption: function(index) {
|
114
|
+
this.nodes[index].selected = true;
|
90
115
|
this.nodes[index].setAttribute("selected", "selected");
|
116
|
+
this.trigger(index, "change");
|
91
117
|
},
|
92
118
|
|
93
119
|
unselectOption: function(index) {
|
120
|
+
this.nodes[index].selected = false;
|
94
121
|
this.nodes[index].removeAttribute("selected");
|
122
|
+
this.trigger(index, "change");
|
95
123
|
},
|
96
124
|
|
97
125
|
centerPostion: function(element) {
|
data/src/webkit_server.pro
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: capybara-webkit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 15
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
8
|
+
- 4
|
9
9
|
- 0
|
10
|
-
version: 0.
|
10
|
+
version: 0.4.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- thoughtbot
|
@@ -17,11 +17,17 @@ authors:
|
|
17
17
|
- Joshua Clayton
|
18
18
|
- Yuichi Tateno
|
19
19
|
- Aaron Gibralter
|
20
|
+
- Vasily Reys
|
21
|
+
- petrushka
|
22
|
+
- John Bintz
|
23
|
+
- Christopher Meiklejohn
|
24
|
+
- John Barker
|
25
|
+
- Jeremy Wells
|
20
26
|
autorequire:
|
21
27
|
bindir: bin
|
22
28
|
cert_chain: []
|
23
29
|
|
24
|
-
date: 2011-05-
|
30
|
+
date: 2011-05-24 00:00:00 -04:00
|
25
31
|
default_executable:
|
26
32
|
dependencies:
|
27
33
|
- !ruby/object:Gem::Dependency
|