Navigation Menu

Skip to content
This repository has been archived by the owner on Mar 3, 2020. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'thoughtbot/master'
Browse files Browse the repository at this point in the history
Conflicts:
	.gitignore
	spec/driver_spec.rb
  • Loading branch information
JonathanTron committed May 25, 2011
2 parents a759712 + e121981 commit 961c36a
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 21 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -11,6 +11,7 @@ qrc_*
moc_*.cpp
.bundle
pkg
src/webkit_server
.rvmrc
src/Info.plist
*.orig
6 changes: 4 additions & 2 deletions capybara-webkit.gemspec
@@ -1,8 +1,10 @@
Gem::Specification.new do |s|
s.name = "capybara-webkit"
s.version = "0.3.0"
s.version = "0.4.0"
s.authors = ["thoughtbot", "Joe Ferris", "Jason Morrison", "Tristan Dunn",
"Joshua Clayton", "Yuichi Tateno", "Aaron Gibralter"]
"Joshua Clayton", "Yuichi Tateno", "Aaron Gibralter",
"Vasily Reys", "petrushka", "John Bintz",
"Christopher Meiklejohn", "John Barker", "Jeremy Wells"]
s.email = "support@thoughtbot.com"
s.files = `git ls-files`.split("\n")
s.test_files = `git ls-files -- {spec,features}/*`.split("\n")
Expand Down
6 changes: 5 additions & 1 deletion lib/capybara/driver/webkit/node.rb
Expand Up @@ -6,7 +6,7 @@ def text

def [](name)
value = invoke("attribute", name)
if name == 'checked'
if name == 'checked' || name == 'disabled'
value == 'true'
else
value
Expand Down Expand Up @@ -53,6 +53,10 @@ def visible?
invoke("visible") == "true"
end

def disabled?
self['disabled']
end

def path
raise Capybara::NotSupportedByDriverError
end
Expand Down
16 changes: 9 additions & 7 deletions lib/capybara_webkit_builder.rb
Expand Up @@ -4,7 +4,14 @@ module CapybaraWebkitBuilder
extend self

def makefile
system("qmake -spec macx-g++")
qmake_binaries = ['qmake', 'qmake-qt4']
qmake = qmake_binaries.detect { |qmake| system("which #{qmake}") }
case RUBY_PLATFORM
when /linux/
system("#{qmake} -spec linux-g++")
else
system("#{qmake} -spec macx-g++")
end
end

def qmake
Expand All @@ -15,12 +22,7 @@ def build
system("make") or return false

FileUtils.mkdir("bin") unless File.directory?("bin")

if File.exist?("src/webkit_server.app")
FileUtils.cp("src/webkit_server.app/Contents/MacOS/webkit_server", "bin", :preserve => true)
else
FileUtils.cp("src/webkit_server", "bin", :preserve => true)
end
FileUtils.cp("src/webkit_server", "bin", :preserve => true)
end

def build_all
Expand Down
57 changes: 51 additions & 6 deletions spec/driver_spec.rb
Expand Up @@ -117,6 +117,7 @@
<div id="display_none">
<div id="invisible">Can't see me</div>
</div>
<input type="text" disabled="disabled"/>
<script type="text/javascript">
document.write("<p id='greeting'>he" + "llo</p>");
</script>
Expand Down Expand Up @@ -243,6 +244,10 @@
subject.find("//p").first.tag_name.should == "p"
end

it "reads disabled property" do
subject.find("//input").first.should be_disabled
end

it "finds visible elements" do
subject.find("//p").first.should be_visible
subject.find("//*[@id='invisible']").first.should_not be_visible
Expand All @@ -267,6 +272,7 @@
<html><body>
<form action="/" method="GET">
<input type="text" name="foo" value="bar"/>
<input type="text" id="disabled_input" disabled="disabled"/>
<input type="checkbox" name="checkedbox" value="1" checked="checked"/>
<input type="checkbox" name="uncheckedbox" value="2"/>
<select name="animal">
Expand Down Expand Up @@ -388,6 +394,17 @@
unchecked_box.set(false)
unchecked_box['checked'].should_not be_true
end

let(:enabled_input) { subject.find("//input[@name='foo']").first }
let(:disabled_input) { subject.find("//input[@id='disabled_input']").first }

it "knows a disabled input is disabled" do
disabled_input['disabled'].should be_true
end

it "knows a not disabled input is not disabled" do
enabled_input['disabled'].should_not be_true
end
end

context "form events app" do
Expand Down Expand Up @@ -416,6 +433,7 @@
var element = elements[i];
element.addEventListener("focus", recordEvent);
element.addEventListener("keydown", recordEvent);
element.addEventListener("keypress", recordEvent);
element.addEventListener("keyup", recordEvent);
element.addEventListener("change", recordEvent);
element.addEventListener("blur", recordEvent);
Expand All @@ -430,19 +448,27 @@
end
end

let(:newtext) { 'newvalue' }

let(:keyevents) do
(%w{focus} +
newtext.length.times.collect { %w{keydown keypress keyup} } +
%w{change blur}).flatten
end

it "triggers text input events" do
subject.find("//input[@type='text']").first.set("newvalue")
subject.find("//li").map(&:text).should == %w(focus keydown keyup change blur)
subject.find("//input[@type='text']").first.set(newtext)
subject.find("//li").map(&:text).should == keyevents
end

it "triggers textarea input events" do
subject.find("//textarea").first.set("newvalue")
subject.find("//li").map(&:text).should == %w(focus keydown keyup change blur)
subject.find("//textarea").first.set(newtext)
subject.find("//li").map(&:text).should == keyevents
end

it "triggers password input events" do
subject.find("//input[@type='password']").first.set("newvalue")
subject.find("//li").map(&:text).should == %w(focus keydown keyup change blur)
subject.find("//input[@type='password']").first.set(newtext)
subject.find("//li").map(&:text).should == keyevents
end

it "triggers radio input events" do
Expand All @@ -464,7 +490,17 @@
<div id="change">Change me</div>
<div id="mouseup">Push me</div>
<div id="mousedown">Release me</div>
<form action="/" method="GET">
<select id="change_select" name="change_select">
<option value="1" id="option-1" selected="selected">one</option>
<option value="2" id="option-2">two</option>
</select>
</form>
<script type="text/javascript">
document.getElementById("change_select").
addEventListener("change", function () {
this.className = "triggered";
});
document.getElementById("change").
addEventListener("change", function () {
this.className = "triggered";
Expand Down Expand Up @@ -502,6 +538,15 @@
subject.find("//*[@class='triggered']").should_not be_empty
end

it "fires a change on select" do
select = subject.find("//select").first
select.value.should == "1"
option = subject.find("//option[@id='option-2']").first
option.select_option
select.value.should == "2"
subject.find("//select[@class='triggered']").should_not be_empty
end

it "fires drag events" do
draggable = subject.find("//*[@id='mousedown']").first
container = subject.find("//*[@id='mouseup']").first
Expand Down
38 changes: 33 additions & 5 deletions src/capybara.js
Expand Up @@ -31,9 +31,16 @@ Capybara = {
},

attribute: function (index, name) {
if (name == "checked") {
switch(name) {
case 'checked':
return this.nodes[index].checked;
} else {
break;

case 'disabled':
return this.nodes[index].disabled;
break;

default:
return this.nodes[index].getAttribute(name);
}
},
Expand All @@ -54,6 +61,19 @@ Capybara = {
this.nodes[index].dispatchEvent(eventObject);
},

keypress: function(index, altKey, ctrlKey, shiftKey, metaKey, keyCode, charCode) {
var eventObject = document.createEvent("Events");
eventObject.initEvent('keypress', true, true);
eventObject.window = window;
eventObject.altKey = altKey;
eventObject.ctrlKey = ctrlKey;
eventObject.shiftKey = shiftKey;
eventObject.metaKey = metaKey;
eventObject.keyCode = keyCode;
eventObject.charCode = charCode;
this.nodes[index].dispatchEvent(eventObject);
},

visible: function (index) {
var element = this.nodes[index];
while (element) {
Expand All @@ -73,9 +93,13 @@ Capybara = {
var type = (node.type || node.tagName).toLowerCase();
if (type == "text" || type == "textarea" || type == "password") {
this.trigger(index, "focus");
node.value = value;
this.trigger(index, "keydown");
this.trigger(index, "keyup");
node.value = "";
for(var strindex = 0; strindex < value.length; strindex++) {
node.value += value[strindex];
this.trigger(index, "keydown");
this.keypress(index, false, false, false, false, 0, value[strindex]);
this.trigger(index, "keyup");
}
this.trigger(index, "change");
this.trigger(index, "blur");
} else if(type == "checkbox" || type == "radio") {
Expand All @@ -87,11 +111,15 @@ Capybara = {
},

selectOption: function(index) {
this.nodes[index].selected = true;
this.nodes[index].setAttribute("selected", "selected");
this.trigger(index, "change");
},

unselectOption: function(index) {
this.nodes[index].selected = false;
this.nodes[index].removeAttribute("selected");
this.trigger(index, "change");
},

centerPostion: function(element) {
Expand Down
1 change: 1 addition & 0 deletions src/webkit_server.pro
Expand Up @@ -6,4 +6,5 @@ SOURCES = main.cpp WebPage.cpp Server.cpp Connection.cpp Command.cpp Visit.cpp F
RESOURCES = webkit_server.qrc
QT += network webkit
CONFIG += console
CONFIG -= app_bundle

0 comments on commit 961c36a

Please sign in to comment.