spec_ui 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +5 -0
- data/Manifest.txt +25 -0
- data/README.txt +12 -0
- data/Rakefile +48 -0
- data/examples/selenium/README.txt +29 -0
- data/examples/selenium/Rakefile +2 -0
- data/examples/selenium/spec/google/find_rspecs_homepage_spec.rb +38 -0
- data/examples/selenium/spec/spec_helper.rb +11 -0
- data/examples/watir/README.txt +12 -0
- data/examples/watir/Rakefile +2 -0
- data/examples/watir/spec/google/find_rspecs_homepage_spec.rb +37 -0
- data/examples/watir/spec/spec_helper.rb +11 -0
- data/lib/spec/ui.rb +7 -0
- data/lib/spec/ui/behaviour.rb +6 -0
- data/lib/spec/ui/configuration.rb +7 -0
- data/lib/spec/ui/formatter.rb +15 -0
- data/lib/spec/ui/rake_tasks.rb +31 -0
- data/lib/spec/ui/rmagick_not_installed.png +0 -0
- data/lib/spec/ui/screenshot_helper.rb +62 -0
- data/lib/spec/ui/selenium_helper.rb +21 -0
- data/lib/spec/ui/version.rb +11 -0
- data/lib/spec/ui/watir_helper.rb +167 -0
- data/lib/spec/ui/webapp_helper.rb +23 -0
- data/lib/spec/ui/win32screenshot_not_installed.png +0 -0
- data/lib/spec/ui/wrong_win32screenshot.png +0 -0
- metadata +78 -0
data/History.txt
ADDED
data/Manifest.txt
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
History.txt
|
2
|
+
Manifest.txt
|
3
|
+
README.txt
|
4
|
+
Rakefile
|
5
|
+
lib/spec/ui.rb
|
6
|
+
lib/spec/ui/behaviour.rb
|
7
|
+
lib/spec/ui/configuration.rb
|
8
|
+
lib/spec/ui/formatter.rb
|
9
|
+
lib/spec/ui/rake_tasks.rb
|
10
|
+
lib/spec/ui/rmagick_not_installed.png
|
11
|
+
lib/spec/ui/screenshot_helper.rb
|
12
|
+
lib/spec/ui/selenium_helper.rb
|
13
|
+
lib/spec/ui/version.rb
|
14
|
+
lib/spec/ui/watir_helper.rb
|
15
|
+
lib/spec/ui/webapp_helper.rb
|
16
|
+
lib/spec/ui/win32screenshot_not_installed.png
|
17
|
+
lib/spec/ui/wrong_win32screenshot.png
|
18
|
+
examples/selenium/Rakefile
|
19
|
+
examples/selenium/README.txt
|
20
|
+
examples/selenium/spec/google/find_rspecs_homepage_spec.rb
|
21
|
+
examples/selenium/spec/spec_helper.rb
|
22
|
+
examples/watir/Rakefile
|
23
|
+
examples/watir/README.txt
|
24
|
+
examples/watir/spec/google/find_rspecs_homepage_spec.rb
|
25
|
+
examples/watir/spec/spec_helper.rb
|
data/README.txt
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
README for spec/ui
|
2
|
+
==================
|
3
|
+
|
4
|
+
spec/ui is an add-on to RSpec that lets you use a UI-testing framework
|
5
|
+
such as Selenium or Watir/Safariwatir from RSpec. spec/ui also makes it
|
6
|
+
easy to create HTML reports with screenshots as described in this blogpost:
|
7
|
+
|
8
|
+
http://blog.aslakhellesoy.com/articles/2006/12/02/getting-screenshots-from-watir
|
9
|
+
|
10
|
+
As much as possible of the supporting code has been factored out to separate files
|
11
|
+
under spec/ui, and the distribution contains examples with a spec_helper and a Rakefile
|
12
|
+
that you can copy into your own project and tweak if needed.
|
data/Rakefile
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
require 'rake/clean'
|
4
|
+
require 'rake/testtask'
|
5
|
+
require 'rake/packagetask'
|
6
|
+
require 'rake/gempackagetask'
|
7
|
+
require 'rake/rdoctask'
|
8
|
+
require 'rake/contrib/rubyforgepublisher'
|
9
|
+
require 'fileutils'
|
10
|
+
require 'hoe'
|
11
|
+
include FileUtils
|
12
|
+
require File.join(File.dirname(__FILE__), 'lib', 'spec', 'ui', 'version')
|
13
|
+
|
14
|
+
AUTHOR = "Aslak Hellesoy" # can also be an array of Authors
|
15
|
+
EMAIL = "rspec-user@rubyforge.org"
|
16
|
+
DESCRIPTION = "Run UI RSpec examples with screenshot reports"
|
17
|
+
GEM_NAME = "spec_ui" # what ppl will type to install your gem
|
18
|
+
RUBYFORGE_PROJECT = "rspec" # The unix name for your project
|
19
|
+
HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
|
20
|
+
RELEASE_TYPES = %w( gem ) # can use: gem, tar, zip
|
21
|
+
|
22
|
+
|
23
|
+
NAME = "spec_ui"
|
24
|
+
REV = File.read(".svn/entries")[/committed-rev="(d+)"/, 1] rescue nil
|
25
|
+
VERS = ENV['VERSION'] || (Spec::Ui::VERSION::STRING + (REV ? ".#{REV}" : ""))
|
26
|
+
CLEAN.include ['**/.*.sw?', '*.gem', '.config']
|
27
|
+
RDOC_OPTS = ['--quiet', '--title', "spec/ui documentation",
|
28
|
+
"--opname", "index.html",
|
29
|
+
"--line-numbers",
|
30
|
+
"--main", "README",
|
31
|
+
"--inline-source"]
|
32
|
+
|
33
|
+
# Generate all the Rake tasks
|
34
|
+
# Run 'rake -T' to see list of generated tasks (from gem root directory)
|
35
|
+
hoe = Hoe.new(GEM_NAME, VERS) do |p|
|
36
|
+
p.author = AUTHOR
|
37
|
+
p.description = DESCRIPTION
|
38
|
+
p.email = EMAIL
|
39
|
+
p.summary = DESCRIPTION
|
40
|
+
p.url = HOMEPATH
|
41
|
+
p.rubyforge_name = RUBYFORGE_PROJECT
|
42
|
+
p.clean_globs = CLEAN #An array of file patterns to delete on clean.
|
43
|
+
|
44
|
+
# == Optional
|
45
|
+
#p.changes - A description of the release's latest changes.
|
46
|
+
#p.extra_deps - An array of rubygem dependencies.
|
47
|
+
#p.spec_extras - A hash of extra values to set in the gemspec.
|
48
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
= Using Selenium with spec/ui =
|
2
|
+
|
3
|
+
The files in this directory are examples illustrating how to use Selenium
|
4
|
+
with spec/ui. Prerequisites:
|
5
|
+
|
6
|
+
* Install Java 1.4 or later
|
7
|
+
* Download SeleniumRC 0.9.0 or later (http://www.openqa.org/selenium-rc/)
|
8
|
+
* Copy selenium-server.jar into the spec directory.
|
9
|
+
* Copy selenium.rb into the spec directory.
|
10
|
+
|
11
|
+
After this is installed, open two shells in this directory.
|
12
|
+
|
13
|
+
In the first one, run:
|
14
|
+
|
15
|
+
java -jar spec/selenium-server.jar
|
16
|
+
|
17
|
+
In the second one, run:
|
18
|
+
|
19
|
+
rake spec:ui
|
20
|
+
|
21
|
+
= Note for OS X users =
|
22
|
+
|
23
|
+
== Firefox 2.0.0.1 ==
|
24
|
+
If you experience that the selenium server is just hanging, read this:
|
25
|
+
http://forums.openqa.org/message.jspa?messageID=16541
|
26
|
+
|
27
|
+
== Safari ==
|
28
|
+
You may have to set up Safari's proxy settings manually:
|
29
|
+
http://forums.openqa.org/thread.jspa?messageID=20570做
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe "Google's search page" do
|
4
|
+
before(:all) do
|
5
|
+
@browser = Selenium::SeleniumDriver.new("localhost", 4444, "*safari", "http://www.google.no", 10000)
|
6
|
+
@browser.start
|
7
|
+
end
|
8
|
+
|
9
|
+
before(:each) do
|
10
|
+
@browser.open('http://www.google.no')
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should find rspec's home page when I search for rspec" do
|
14
|
+
@browser.type "name=q", "rspec"
|
15
|
+
@browser.click_and_wait "name=btnG"
|
16
|
+
@browser.is_text_present("rspec.rubyforge.org").should be_true
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should find rspec's home page when I search for 'better than fudge' (will probably fail)" do
|
20
|
+
@browser.type "name=q", "better than fudge"
|
21
|
+
@browser.click_and_wait "name=btnG"
|
22
|
+
@browser.is_text_present("rspec.rubyforge.org").should be_true
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should not find Ali G when I search for rspec" do
|
26
|
+
@browser.type "name=q", "rspec"
|
27
|
+
@browser.click_and_wait "name=btnG"
|
28
|
+
@browser.is_text_present("Ali G").should be_false
|
29
|
+
end
|
30
|
+
|
31
|
+
after(:each) do
|
32
|
+
save_screenshot_and_source(@browser)
|
33
|
+
end
|
34
|
+
|
35
|
+
after(:all) do
|
36
|
+
@browser.kill! rescue nil
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# You don't need to tweak the $LOAD_PATH if you have RSpec and Spec::Ui installed as gems
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__) + '/../../../../rspec/lib')
|
3
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__) + '/../../../lib')
|
4
|
+
|
5
|
+
require 'rubygems'
|
6
|
+
require 'spec'
|
7
|
+
require 'spec/ui'
|
8
|
+
|
9
|
+
Spec::Runner.configure do |config|
|
10
|
+
config.spec_ui_report_dir = File.dirname(__FILE__) + '/report'
|
11
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
= Using Watir with spec/ui =
|
2
|
+
|
3
|
+
The files in this directory are examples illustrating how to use Watir
|
4
|
+
with spec/ui. Prerequisites:
|
5
|
+
|
6
|
+
* See the general prerequisites in the toplevel README
|
7
|
+
* gem install watir -y # If you're on Windows
|
8
|
+
* gem install safariwatir -y # If you're on OS X
|
9
|
+
|
10
|
+
After this is installed, run the watir specs:
|
11
|
+
|
12
|
+
rake spec:ui
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe "Google's search page" do
|
4
|
+
before(:all) do
|
5
|
+
@browser = Watir::Browser.new
|
6
|
+
end
|
7
|
+
|
8
|
+
before(:each) do
|
9
|
+
@browser.goto('http://www.google.com')
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should find rspec's home page when I search for rspec" do
|
13
|
+
@browser.text_field(:name, "q").set("rspec")
|
14
|
+
@browser.button(:name, "btnG").click
|
15
|
+
@browser.should have_link(:url, "http://rspec.rubyforge.org/")
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should find rspec's home page when I search for 'better than fudge' (this is supposed to fail)" do
|
19
|
+
@browser.text_field(:name, "q").set("better than fudge")
|
20
|
+
@browser.button(:name, "btnG").click
|
21
|
+
@browser.should have_link(:url, "http://rspec.rubyforge.org/")
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should not find Ali G when I search for respec" do
|
25
|
+
@browser.text_field(:name, "q").set("respec")
|
26
|
+
@browser.button(:name, "btnG").click
|
27
|
+
@browser.should_not have_text("Ali G")
|
28
|
+
end
|
29
|
+
|
30
|
+
after(:each) do
|
31
|
+
save_screenshot_and_source(@browser)
|
32
|
+
end
|
33
|
+
|
34
|
+
after(:all) do
|
35
|
+
@browser.kill! rescue nil
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# You don't need to tweak the $LOAD_PATH if you have RSpec and Spec::Ui installed as gems
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__) + '/../../../../rspec/lib')
|
3
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__) + '/../../../lib')
|
4
|
+
|
5
|
+
require 'rubygems'
|
6
|
+
require 'spec'
|
7
|
+
require 'spec/ui'
|
8
|
+
|
9
|
+
Spec::Runner.configure do |config|
|
10
|
+
config.spec_ui_report_dir = File.dirname(__FILE__) + '/report'
|
11
|
+
end
|
data/lib/spec/ui.rb
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/ui/configuration'
|
2
|
+
require File.dirname(__FILE__) + '/ui/behaviour'
|
3
|
+
require File.dirname(__FILE__) + '/ui/webapp_helper'
|
4
|
+
require File.dirname(__FILE__) + '/ui/watir_helper'
|
5
|
+
require File.dirname(__FILE__) + '/ui/selenium_helper'
|
6
|
+
require File.dirname(__FILE__) + '/ui/screenshot_helper'
|
7
|
+
require File.dirname(__FILE__) + '/ui/rake_tasks'
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Spec
|
2
|
+
module Ui
|
3
|
+
class ScreenshotFormatter < Spec::Runner::Formatter::HtmlFormatter
|
4
|
+
def extra_failure_content(failure)
|
5
|
+
super + " <div><a href=\"images/#{current_example_number}.png\"><img width=\"25%\" height=\"25%\" src=\"images/#{current_example_number}.png\"></a></div>\n"
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
class WebappFormatter < ScreenshotFormatter
|
10
|
+
def extra_failure_content(failure)
|
11
|
+
super + " <div><a href=\"images/#{current_example_number}.html\">HTML source</a></div>\n"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Spec
|
2
|
+
module Ui
|
3
|
+
def self.create_tasks
|
4
|
+
require 'spec/rake/spectask'
|
5
|
+
|
6
|
+
if Spec::Runner.configuration.spec_ui_report_dir.nil?
|
7
|
+
STDERR.puts <<-EOF
|
8
|
+
You must tell Spec::Ui where the report should go.
|
9
|
+
Please put the following in your spec/spec_helper.rb file:
|
10
|
+
|
11
|
+
require 'spec'
|
12
|
+
require 'spec/ui'
|
13
|
+
|
14
|
+
Spec::Runner.configure do |config|
|
15
|
+
config.spec_ui_report_dir = File.dirname(__FILE__) + '/report'
|
16
|
+
end
|
17
|
+
EOF
|
18
|
+
end
|
19
|
+
|
20
|
+
FileUtils.rm_rf(Spec::Runner.configuration.spec_ui_report_dir) if File.exist?(Spec::Runner.configuration.spec_ui_report_dir)
|
21
|
+
FileUtils.mkdir_p(Spec::Runner.configuration.spec_ui_report_dir)
|
22
|
+
|
23
|
+
desc "Run UI Specs"
|
24
|
+
Spec::Rake::SpecTask.new('spec:ui') do |t|
|
25
|
+
t.spec_files = FileList['spec/**/*.rb']
|
26
|
+
t.spec_opts = ['--require', 'spec/spec_helper', '--format', 'Spec::Ui::WebappFormatter']
|
27
|
+
t.out = "#{Spec::Runner.configuration.spec_ui_report_dir}/index.html"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
Binary file
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
|
3
|
+
module Spec
|
4
|
+
module Ui
|
5
|
+
module ScreenshotHelper
|
6
|
+
def md(dir)
|
7
|
+
FileUtils.mkdir_p(dir) unless File.directory?(dir)
|
8
|
+
end
|
9
|
+
|
10
|
+
if RUBY_PLATFORM =~ /darwin/
|
11
|
+
def save_screenshot(dir, spec_number)
|
12
|
+
md(dir)
|
13
|
+
img_path = "#{dir}/#{spec_number}.png"
|
14
|
+
# How do we capture the current window??
|
15
|
+
`screencapture #{img_path}`
|
16
|
+
end
|
17
|
+
else # Win32
|
18
|
+
begin
|
19
|
+
require 'rubygems'
|
20
|
+
require 'RMagick'
|
21
|
+
gem 'win32screenshot', '>=0.0.2'
|
22
|
+
require 'win32screenshot'
|
23
|
+
def save_screenshot(dir, spec_number)
|
24
|
+
md(dir)
|
25
|
+
width, height, bmp = ::Win32::Screenshot.foreground
|
26
|
+
begin
|
27
|
+
img = Magick::Image.from_blob(bmp)[0]
|
28
|
+
img_path = "#{dir}/#{spec_number}.png"
|
29
|
+
dir = File.dirname(img_path)
|
30
|
+
FileUtils.mkdir_p(dir) unless File.exist?(dir)
|
31
|
+
img.write(img_path)
|
32
|
+
img
|
33
|
+
rescue Magick::ImageMagickError => e
|
34
|
+
if e.message =~ /Insufficient image data in file/
|
35
|
+
e.message << "\nTry this:\n1) Open your app (e.g. Internet Explorer)\n2) Resize the app to be bigger (without maximizing).\n3) close it so Windows remembers its size.\n" +
|
36
|
+
"This *may* make this error go away."
|
37
|
+
end
|
38
|
+
raise e
|
39
|
+
end
|
40
|
+
end
|
41
|
+
rescue Gem::LoadError => e
|
42
|
+
def save_screenshot(dir, spec_number)
|
43
|
+
md(dir)
|
44
|
+
FileUtils.cp(File.dirname(__FILE__) + '/wrong_win32screenshot.png', "#{dir}/#{spec_number}.png")
|
45
|
+
end
|
46
|
+
rescue LoadError => e
|
47
|
+
if(e.message =~ /win32screenshot/)
|
48
|
+
def save_screenshot(dir, spec_number)
|
49
|
+
md(dir)
|
50
|
+
FileUtils.cp(File.dirname(__FILE__) + '/win32screenshot_not_installed.png', "#{dir}/#{spec_number}.png")
|
51
|
+
end
|
52
|
+
else
|
53
|
+
def save_screenshot(dir, spec_number)
|
54
|
+
md(dir)
|
55
|
+
FileUtils.cp(File.dirname(__FILE__) + '/rmagick_not_installed.png', "#{dir}/#{spec_number}.png")
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Selenium
|
2
|
+
class SeleniumDriver
|
3
|
+
def click_and_wait(locator, timeout="5000")
|
4
|
+
click(locator)
|
5
|
+
wait_for_page_to_load(timeout)
|
6
|
+
end
|
7
|
+
|
8
|
+
def open_and_wait(url, timeout="5000")
|
9
|
+
open(url)
|
10
|
+
wait_for_page_to_load(timeout)
|
11
|
+
end
|
12
|
+
|
13
|
+
def html
|
14
|
+
get_html_source
|
15
|
+
end
|
16
|
+
|
17
|
+
def kill!
|
18
|
+
stop
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,167 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/webapp_helper'
|
2
|
+
require 'rubygems'
|
3
|
+
|
4
|
+
if RUBY_PLATFORM =~ /darwin/
|
5
|
+
require 'safariwatir'
|
6
|
+
Watir::Browser = Watir::Safari
|
7
|
+
else
|
8
|
+
require 'watir'
|
9
|
+
Watir::Browser = Watir::IE
|
10
|
+
|
11
|
+
class Watir::Browser
|
12
|
+
alias old_initialize initialize
|
13
|
+
# Brings the IE to the foreground (provided Win32::Screenshot is installed)
|
14
|
+
def initialize
|
15
|
+
result = old_initialize
|
16
|
+
::Win32::Screenshot.setForegroundWindow(self.getIE.hwnd) rescue nil
|
17
|
+
result
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
class Watir::Browser
|
23
|
+
def kill!
|
24
|
+
close
|
25
|
+
end
|
26
|
+
|
27
|
+
alias contain_text? contains_text
|
28
|
+
|
29
|
+
alias old_goto goto
|
30
|
+
# Redefinition of Watir's original goto, which gives a better
|
31
|
+
# exception message (the URL is in the message)
|
32
|
+
def goto(url)
|
33
|
+
begin
|
34
|
+
old_goto(url)
|
35
|
+
rescue => e
|
36
|
+
e.message << "\nURL: #{url}"
|
37
|
+
raise e
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
module Spec
|
43
|
+
# Matchers for Watir::IE/Watir::Safari instances
|
44
|
+
module Watir
|
45
|
+
# RSpec matcher that passes if @browser#text matches +text+ (String or Regexp)
|
46
|
+
def have_text(text)
|
47
|
+
Spec::Watir::HaveText.new(text)
|
48
|
+
end
|
49
|
+
|
50
|
+
class HaveText # :nodoc
|
51
|
+
def initialize(text_or_regexp)
|
52
|
+
@text_or_regexp = text_or_regexp
|
53
|
+
end
|
54
|
+
|
55
|
+
def matches?(browser)
|
56
|
+
@browser = browser
|
57
|
+
if @text_or_regexp.is_a?(Regexp)
|
58
|
+
!!browser.text =~ @text_or_regexp
|
59
|
+
else
|
60
|
+
!!browser.text.index(@text_or_regexp.to_s)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def failure_message
|
65
|
+
"Expected browser to have text matching #{@text_or_regexp}, but it was not found in:\n#{@browser.text}"
|
66
|
+
end
|
67
|
+
|
68
|
+
def negative_failure_message
|
69
|
+
"Expected browser to not have text matching #{@text_or_regexp}, but it was found in:\n#{@browser.text}"
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
# RSpec matcher that passes if @browser#html matches +text+ (String or Regexp)
|
74
|
+
def have_html(text)
|
75
|
+
Spec::Watir::HaveHtml.new(text)
|
76
|
+
end
|
77
|
+
|
78
|
+
class HaveHtml # :nodoc
|
79
|
+
def initialize(text_or_regexp)
|
80
|
+
@text_or_regexp = text_or_regexp
|
81
|
+
end
|
82
|
+
|
83
|
+
def matches?(browser)
|
84
|
+
@browser = browser
|
85
|
+
if @text_or_regexp.is_a?(Regexp)
|
86
|
+
!!browser.html =~ @text_or_regexp
|
87
|
+
else
|
88
|
+
!!browser.html.index(@text_or_regexp.to_s)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
def failure_message
|
93
|
+
"Expected browser to have HTML matching #{@text_or_regexp}, but it was not found in:\n#{@browser.html}"
|
94
|
+
end
|
95
|
+
|
96
|
+
def negative_failure_message
|
97
|
+
"Expected browser to not have HTML matching #{@text_or_regexp}, but it was found in:\n#{@browser.html}"
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
# RSpec matcher that passes if @browser#link(+how+,+what+) returns an existing link.
|
102
|
+
def have_link(how, what)
|
103
|
+
Spec::Watir::HaveLink.new(how, what)
|
104
|
+
end
|
105
|
+
|
106
|
+
class HaveLink # :nodoc
|
107
|
+
def initialize(how, what)
|
108
|
+
@how, @what = how, what
|
109
|
+
end
|
110
|
+
|
111
|
+
def matches?(browser)
|
112
|
+
@browser = browser
|
113
|
+
begin
|
114
|
+
link = @browser.link(@how, @what)
|
115
|
+
if link.respond_to?(:assert_exists)
|
116
|
+
# IE
|
117
|
+
link.assert_exists
|
118
|
+
true
|
119
|
+
else
|
120
|
+
# Safari
|
121
|
+
link.exists?
|
122
|
+
end
|
123
|
+
rescue ::Watir::Exception::UnknownObjectException => e
|
124
|
+
false
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
def failure_message
|
129
|
+
"Expected browser to have link(#{@how}, #{@what}), but it was not found"
|
130
|
+
end
|
131
|
+
|
132
|
+
def negative_failure_message
|
133
|
+
"Expected browser not to have link(#{@how}, #{@what}), but it was found"
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
# RSpec matcher that passes if @browser#text_field(+how+,+what+) returns an existing text field.
|
138
|
+
def have_text_field(how, what)
|
139
|
+
Spec::Watir::HaveTextField.new(how, what)
|
140
|
+
end
|
141
|
+
|
142
|
+
class HaveTextField # :nodoc
|
143
|
+
def initialize(how, what)
|
144
|
+
@how, @what = how, what
|
145
|
+
end
|
146
|
+
|
147
|
+
def matches?(browser)
|
148
|
+
@browser = browser
|
149
|
+
begin
|
150
|
+
text_field = @browser.text_field(@how, @what)
|
151
|
+
text_field.assert_exists
|
152
|
+
true
|
153
|
+
rescue ::Watir::Exception::UnknownObjectException => e
|
154
|
+
false
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
def failure_message
|
159
|
+
"Expected browser to have text_field(#{@how}, #{@what}), but it was not found"
|
160
|
+
end
|
161
|
+
|
162
|
+
def negative_failure_message
|
163
|
+
"Expected browser not to have text_field(#{@how}, #{@what}), but it was found"
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec'
|
2
|
+
require File.dirname(__FILE__) + '/screenshot_helper'
|
3
|
+
require File.dirname(__FILE__) + '/formatter'
|
4
|
+
|
5
|
+
module Spec
|
6
|
+
module Ui
|
7
|
+
module WebappHelper
|
8
|
+
include Spec::Ui::ScreenshotHelper
|
9
|
+
@@spec_number = 0
|
10
|
+
|
11
|
+
# Call this method from your teardown block to have source and screenshot written to disk.
|
12
|
+
def save_screenshot_and_source(browser)
|
13
|
+
save_screenshot(Spec::Runner.configuration.spec_ui_image_dir, @@spec_number)
|
14
|
+
save_source(Spec::Runner.configuration.spec_ui_image_dir, @@spec_number, browser.html)
|
15
|
+
@@spec_number += 1
|
16
|
+
end
|
17
|
+
|
18
|
+
def save_source(dir, spec_number, html)
|
19
|
+
File.open("#{dir}/#{spec_number}.html", "w") {|io| io.write(html)}
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
Binary file
|
Binary file
|
metadata
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
rubygems_version: 0.9.1
|
3
|
+
specification_version: 1
|
4
|
+
name: spec_ui
|
5
|
+
version: !ruby/object:Gem::Version
|
6
|
+
version: 0.1.0
|
7
|
+
date: 2007-05-01 00:00:00 +02:00
|
8
|
+
summary: Run UI RSpec examples with screenshot reports
|
9
|
+
require_paths:
|
10
|
+
- lib
|
11
|
+
email: rspec-user@rubyforge.org
|
12
|
+
homepage: http://rspec.rubyforge.org
|
13
|
+
rubyforge_project: rspec
|
14
|
+
description: Run UI RSpec examples with screenshot reports
|
15
|
+
autorequire:
|
16
|
+
default_executable:
|
17
|
+
bindir: bin
|
18
|
+
has_rdoc: true
|
19
|
+
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">"
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.0.0
|
24
|
+
version:
|
25
|
+
platform: ruby
|
26
|
+
signing_key:
|
27
|
+
cert_chain:
|
28
|
+
post_install_message:
|
29
|
+
authors:
|
30
|
+
- Aslak Hellesoy
|
31
|
+
files:
|
32
|
+
- History.txt
|
33
|
+
- Manifest.txt
|
34
|
+
- README.txt
|
35
|
+
- Rakefile
|
36
|
+
- lib/spec/ui.rb
|
37
|
+
- lib/spec/ui/behaviour.rb
|
38
|
+
- lib/spec/ui/configuration.rb
|
39
|
+
- lib/spec/ui/formatter.rb
|
40
|
+
- lib/spec/ui/rake_tasks.rb
|
41
|
+
- lib/spec/ui/rmagick_not_installed.png
|
42
|
+
- lib/spec/ui/screenshot_helper.rb
|
43
|
+
- lib/spec/ui/selenium_helper.rb
|
44
|
+
- lib/spec/ui/version.rb
|
45
|
+
- lib/spec/ui/watir_helper.rb
|
46
|
+
- lib/spec/ui/webapp_helper.rb
|
47
|
+
- lib/spec/ui/win32screenshot_not_installed.png
|
48
|
+
- lib/spec/ui/wrong_win32screenshot.png
|
49
|
+
- examples/selenium/Rakefile
|
50
|
+
- examples/selenium/README.txt
|
51
|
+
- examples/selenium/spec/google/find_rspecs_homepage_spec.rb
|
52
|
+
- examples/selenium/spec/spec_helper.rb
|
53
|
+
- examples/watir/Rakefile
|
54
|
+
- examples/watir/README.txt
|
55
|
+
- examples/watir/spec/google/find_rspecs_homepage_spec.rb
|
56
|
+
- examples/watir/spec/spec_helper.rb
|
57
|
+
test_files: []
|
58
|
+
|
59
|
+
rdoc_options: []
|
60
|
+
|
61
|
+
extra_rdoc_files: []
|
62
|
+
|
63
|
+
executables: []
|
64
|
+
|
65
|
+
extensions: []
|
66
|
+
|
67
|
+
requirements: []
|
68
|
+
|
69
|
+
dependencies:
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: hoe
|
72
|
+
version_requirement:
|
73
|
+
version_requirements: !ruby/object:Gem::Version::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 1.2.0
|
78
|
+
version:
|