This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class HaveXpathContaining < Struct.new( :xpath, :contents ) | |
def matches?( page ) | |
if self.contents.blank? | |
page.has_xpath?( self.xpath + "[not( text() )]" ) || page.has_xpath?( self.xpath + "[string-length( normalize-space( . ) ) = 0]" ) | |
else | |
page.has_xpath?( self.xpath + "[contains( ., '#{ self.contents }' )]" ) | |
end | |
end | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe 'application flow' | |
before_each | |
$page = $( fixture( "jqt.html" ) ) | |
end | |
it 'should start on the login page' | |
$page.find( "#login" ).should.have_class "current" | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset='UTF-8'> | |
<title>Penny</title> | |
</head> | |
<body> | |
<form accept-charset='utf-8' action='/session.json' class='current' id='login' method='post'> | |
<div class='toolbar'> | |
<h1>Login</h1> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe 'application flow' | |
before_each | |
$page = $( fixture( "jqt" ) ) | |
end | |
it 'should start on the login page' | |
$page.find( "#login" ).should.have_class( "current" ) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset='UTF-8' /> | |
<title>Penny</title> | |
</head> | |
<body id="body"> | |
<form accept-charset='utf-8' action='/session.json' class='current' id='login' method='post'> | |
<div class='toolbar' id='login-c'> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
When /^I enter "([^\"]*)"$/ do |value| | |
find( "//*[@class = 'current']//input" ).set( value ) | |
find( "//*[@class = 'current']//input" ).value.should == value | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# features/support/my_env.rb | |
def enter_text( input, text ) | |
input.node.clear | |
input.node.send_keys( text.to_s ) | |
end | |
# features/steps/feature_steps.rb | |
When /^I enter "([^\"]*)"$/ do |value| | |
enter_text( "//*[@class = 'current']//input", value ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# My page wrote alert p elements to the body (due to a hack to allow alerts in my app that wouldn't upset cuke flow), | |
# but iterating through them with all() didn't work, as when I called the text() method, it returned nil, even though | |
# there was text there -- so I used this instead. | |
# | |
# Get all alert p's off the page and dump their contents. | |
# | |
def _dump_alerts | |
doc = Nokogiri.HTML( page.body ) | |
doc.xpath( "//p[@class = 'alert']" ).reverse.each do |p| |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Again, the text() method wouldn't give me what I wanted, so I came up with this to get at it (and to remove any | |
# whitespace either side of it). | |
# Used like: | |
# find( "//a[@id = 'messages']" ).should contain_text( "Review Your Messages" ) | |
class ContainText | |
def initialize( text ) | |
@text = text |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Rob's fix to dump in my_env.rb | |
class Capybara::Driver::Selenium::Node | |
def set( value ) | |
if tag_name == 'input' and type == 'radio' | |
node.select | |
elsif tag_name == 'input' and type == 'checkbox' | |
node.toggle | |
else | |
node.clear |
OlderNewer