watirsplash 0.2.14 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. data/History.rdoc +8 -0
  2. data/License.txt +2 -2
  3. data/README.rdoc +5 -5
  4. data/Rakefile +16 -17
  5. data/VERSION +1 -1
  6. data/bin/watirsplash +2 -9
  7. data/lib/watirsplash.rb +5 -7
  8. data/lib/watirsplash/cli.rb +34 -0
  9. data/lib/watirsplash/file_helper.rb +1 -1
  10. data/lib/watirsplash/generators/migrate_project.rb +25 -0
  11. data/lib/watirsplash/generators/new_common_project.rb +18 -0
  12. data/lib/watirsplash/generators/new_project.rb +45 -0
  13. data/{templates/common/config.rb → lib/watirsplash/generators/templates/new_common_project/config.rb.tt} +4 -4
  14. data/{templates/common → lib/watirsplash/generators/templates/new_common_project}/environment.rb +3 -3
  15. data/{templates/common → lib/watirsplash/generators/templates/new_common_project}/lib/common_application_helper.rb +2 -2
  16. data/lib/watirsplash/generators/templates/new_project/.rspec +2 -0
  17. data/lib/watirsplash/generators/templates/new_project/config.rb.tt +22 -0
  18. data/{templates/project/environment.rb → lib/watirsplash/generators/templates/new_project/environment.rb.tt} +4 -5
  19. data/{templates/project/spec/application_helper.rb → lib/watirsplash/generators/templates/new_project/spec/%formatted_name%_helper.rb.tt} +3 -3
  20. data/lib/watirsplash/generators/templates/new_project/spec/dummy_spec.rb.tt +40 -0
  21. data/lib/watirsplash/html_formatter.rb +14 -16
  22. data/lib/watirsplash/rspec_patches.rb +74 -0
  23. data/lib/watirsplash/spec_helper.rb +2 -10
  24. data/lib/watirsplash/util.rb +15 -1
  25. data/lib/watirsplash/{watir.rb → watir_patches.rb} +3 -7
  26. data/spec/file_helper_spec.rb +19 -0
  27. data/spec/spec_helper_spec.rb +0 -13
  28. data/spec/spec_match_array_spec.rb +0 -2
  29. data/spec/util_spec.rb +0 -2
  30. data/spec/watir_ie_spec.rb +14 -31
  31. metadata +61 -50
  32. data/lib/watirsplash/element_extensions.rb +0 -70
  33. data/lib/watirsplash/generator.rb +0 -55
  34. data/lib/watirsplash/spec.rb +0 -53
  35. data/lib/watirsplash/wait_helper.rb +0 -44
  36. data/spec/spec.opts +0 -11
  37. data/spec/watir_element_spec.rb +0 -69
  38. data/spec/watir_table_row_spec.rb +0 -45
  39. data/spec/watir_table_spec.rb +0 -78
  40. data/templates/project/config.rb +0 -22
  41. data/templates/project/spec/dummy_spec.rb +0 -44
  42. data/templates/project/spec/spec.opts +0 -11
@@ -1,70 +0,0 @@
1
- # encoding: utf-8
2
-
3
- # This assumes that Element#visible? is defined
4
- module ElementExtensions
5
-
6
- #
7
- # Wraps a {Celerity,Watir}::Element so that any subsequent method calls are
8
- # put on hold until the element is present on the page.
9
- #
10
-
11
- class WhenPresentDecorator
12
- def initialize(element, timeout)
13
- @element = element
14
- @timeout = timeout
15
- end
16
-
17
- def method_missing(m, *args, &block)
18
- unless @element.respond_to?(m)
19
- raise NoMethodError, "undefined method `#{m}' for #{@element.inspect}:#{@element.class}"
20
- end
21
-
22
- Watir::WaitHelper.wait_until(@timeout) { @element.present? }
23
- @element.send(m, *args, &block)
24
- end
25
- end
26
-
27
- #
28
- # Returns true if the element exists and is visible on the page
29
- #
30
-
31
- def present?
32
- exists? && visible?
33
- end
34
-
35
- def events
36
- raise "only supported on WebDriver" unless GlobalConfig.webdriver?
37
- assert_exists
38
- browser.execute_script("return arguments[0].data('events')", @element)
39
- end
40
-
41
- #
42
- # Waits until the element is present.
43
- #
44
- # Optional argument:
45
- #
46
- # timeout - seconds to wait before timing out (default: 60)
47
- #
48
- # browser.button(:id, 'foo').when_present.click
49
- # browser.div(:id, 'bar').when_present { |div| ... }
50
- # browser.p(:id, 'baz').when_present(60).text
51
- #
52
-
53
- def when_present(timeout = 60)
54
- if block_given?
55
- Watir::WaitHelper.wait_until(timeout) { self.present? }
56
- yield self
57
- else
58
- return WhenPresentDecorator.new(self, timeout)
59
- end
60
- end
61
-
62
- def wait_until_present(timeout = 60)
63
- Watir::WaitHelper.wait_until(timeout) { self.present? }
64
- end
65
-
66
- def wait_while_present(timeout = 60)
67
- Watir::WaitHelper.wait_while(timeout) { self.present? }
68
- end
69
-
70
- end # module ElementExtensions
@@ -1,55 +0,0 @@
1
- module WatirSplash
2
-
3
- # WatirSplash Generator class is responsible for:
4
- # * generating directory structures for projects
5
- class Generator
6
- @@template_directory = File.join(File.dirname(__FILE__), "../../templates/")
7
-
8
- class << self
9
-
10
- # Generates ui-test directory structure for project
11
- def generate
12
- ui_test_dir = File.join(Dir.pwd, "ui-test")
13
- puts "Creating WatirSplash directory structure to #{ui_test_dir}..."
14
- require "fileutils"
15
- FileUtils.cp_r File.join(@@template_directory, "project/."), ui_test_dir
16
- puts "Done"
17
- return 0
18
- rescue => e
19
- puts "Failed:"
20
- puts e.message
21
- return -1
22
- end
23
-
24
- # Generates ui-test-common directory structure
25
- def generate_common
26
- common_dir = File.join(Dir.pwd, "ui-test-common")
27
- puts "Creating WatirSplash ui-test-common directory structure to #{common_dir}..."
28
- require "fileutils"
29
- FileUtils.cp_r File.join(@@template_directory, "common/."), common_dir
30
- puts "Done"
31
- return 0
32
- rescue => e
33
- puts "Failed:"
34
- puts e.message
35
- return -1
36
- end
37
-
38
- # Shows help
39
- def help
40
- puts %Q{WatirSplash:
41
- Usage: watirsplash (COMMAND|FILE(:LINE)?|DIRECTORY|GLOB)+ [options]
42
- Commands:
43
- * generate - generate default directory structure for new project
44
- * generate_common - generate common project directory structure
45
- * help - show this help
46
- * --help - show RSpec's help
47
-
48
- All other commands/options will be passed to RSpec directly.}
49
-
50
- return 1
51
- end
52
-
53
- end
54
- end
55
- end
@@ -1,53 +0,0 @@
1
- Spec::Runner.configure do |config| #:nodoc:
2
- config.include(WatirSplash::SpecHelper)
3
-
4
- config.before(:all) do
5
- open_browser_at "about:blank"
6
- end
7
-
8
- config.after(:all) do
9
- close
10
- end
11
- end
12
-
13
- module Spec #:nodoc:all
14
- class ExampleGroup
15
- subject {self}
16
- end
17
-
18
- module Example
19
- class ExampleGroupProxy
20
- attr_accessor :description
21
- end
22
-
23
- class ExampleProxy
24
- attr_accessor :description
25
- end
26
- end
27
- end
28
-
29
- # match_array is useful for matching arrays where some elements are regular expressions.
30
- # expected_array = ["1", "2", /\d+/, "3"]
31
- #
32
- # ["1", "2", "66", "3"].should match_array(expected_array)
33
- # table(:id => "table_id").to_a.should match_array(expected_array)
34
- Spec::Matchers.define :match_array do |array2|
35
- match do |array1|
36
- raise "match_array works only with Array objects!" unless array1.is_a?(Array) && array2.is_a?(Array)
37
- match?(array1, array2)
38
- end
39
-
40
- def match?(array1, array2)
41
- array2.each_with_index do |element, i|
42
- if element.is_a?(Array)
43
- return false unless match?(array1[i], element)
44
- elsif element.is_a?(Regexp)
45
- return false unless array1[i] =~ element
46
- else
47
- return false unless array1[i] == element
48
- end
49
- end
50
-
51
- true
52
- end
53
- end
@@ -1,44 +0,0 @@
1
- # encoding: utf-8
2
-
3
- # This code is made by Jari Bakken @ https://gist.github.com/1b14247aae08a7e93f54
4
- #
5
- # Added wait_until? and wait_while? methods and reduced sleeping time to 0.1 secs
6
- module Watir
7
- module WaitHelper
8
- extend self
9
-
10
- class TimeoutError < StandardError
11
- end
12
-
13
- #
14
- # Wait until the block evaluates to true or times out.
15
- #
16
-
17
- def wait_until(timeout = 60, &block)
18
- end_time = ::Time.now + timeout
19
-
20
- until ::Time.now > end_time
21
- result = yield(self)
22
- return result if result
23
- sleep 0.1
24
- end
25
-
26
- raise TimeoutError, "timed out after #{timeout} seconds"
27
- end
28
-
29
- #
30
- # Wait while the block evaluates to true or times out.
31
- #
32
-
33
- def wait_while(timeout = 60, &block)
34
- end_time = ::Time.now + timeout
35
-
36
- until ::Time.now > end_time
37
- return unless yield(self)
38
- sleep 0.1
39
- end
40
-
41
- raise TimeoutError, "timed out after #{timeout} seconds"
42
- end
43
- end # WaitHelper
44
- end # Watir
@@ -1,11 +0,0 @@
1
- --require
2
- lib\watirsplash
3
- --require
4
- lib\watirsplash\html_formatter
5
- --format
6
- WatirSplash::HtmlFormatter:results/index.html
7
- --color
8
- --format
9
- nested
10
- --diff
11
- u
@@ -1,69 +0,0 @@
1
- require "spec"
2
-
3
- describe Watir::Element do
4
-
5
- before :each do
6
- goto "http://dl.dropbox.com/u/2731643/WatirSplash/test.html"
7
- @div = div(:id => 'div1')
8
- end
9
-
10
- it "has method #present?" do
11
- @div.should exist
12
- @div.should be_visible
13
- @div.should be_present
14
-
15
- execute_script("toggle()")
16
- @div.should exist
17
- @div.should_not be_visible
18
- @div.should_not be_present
19
-
20
- div = div(:id => 'non-existing')
21
- div.should_not exist
22
- lambda {div.visible?}.should raise_exception
23
- div.should_not be_present
24
- end
25
-
26
- it "has method #when_present" do
27
- @div.should be_visible
28
- @div.when_present.text.should == "Div content"
29
- link(:id => "toggle").click
30
- wait_until {not @div.visible?}
31
-
32
- link(:id => "toggle").click
33
- @div.when_present.text.should == "Div content"
34
- @div.should be_visible
35
-
36
- @div.when_present {1 + 1}.should == 2
37
-
38
- lambda {div(:id => 'non-existing').when_present(0.1).text}.should raise_exception
39
- end
40
-
41
- it "has method #wait_until_present" do
42
- @div.should be_visible
43
- @div.wait_until_present
44
- @div.text.should == "Div content"
45
- link(:id => "toggle").click
46
- wait_until {not @div.visible?}
47
-
48
- link(:id => "toggle").click
49
- @div.wait_until_present
50
- @div.text.should == "Div content"
51
- @div.should be_visible
52
-
53
- lambda {div(:id => 'non-existing').wait_until_present(0.1)}.should raise_exception
54
- end
55
-
56
- it "has method #wait_while_present" do
57
- @div.should be_visible
58
- link(:id => "toggle").click
59
- @div.wait_while_present
60
- @div.should_not be_visible
61
-
62
- link(:id => "toggle").click
63
- @div.wait_while_present
64
- @div.should_not be_visible
65
-
66
- wait_until {@div.visible?}
67
- lambda {@div.wait_while_present(0.1)}.should raise_exception
68
- end
69
- end
@@ -1,45 +0,0 @@
1
- require "spec"
2
-
3
- describe Watir::TableRow do
4
- include WatirSplash::SpecHelper
5
-
6
- before :all do
7
- goto "http://dl.dropbox.com/u/2731643/WatirSplash/test.html"
8
- end
9
-
10
- it "#to_a works with regular row" do
11
- first_row = table(:id => "normal")[1]
12
- first_row.to_a.should == ["1", "2", "3"]
13
- end
14
-
15
- it "#to_a works with headers in row" do
16
- first_row = table(:id => "headers")[1]
17
- first_row.to_a.should == ["1", "2", "3", "4"]
18
- end
19
-
20
- it "#to_a works with nested tables" do
21
- second_row = table(:id => "nested")[2]
22
- second_row.to_a(2).should == [[["11", "12"], ["13", "14"]], "3"]
23
- end
24
-
25
- it "#to_a works with deep-nested tables" do
26
- second_row = table(:id => "deepnested")[2]
27
- second_row.to_a(3).should == [[["11", "12"],
28
- [[["404", "405"], ["406", "407"]], "14"]], "3"]
29
- end
30
-
31
- it "#to_a works with colspan" do
32
- second_row = table(:id => "colspan")[2]
33
- second_row.to_a.should == ["3"]
34
- end
35
-
36
- it "#to_a works with rowspan" do
37
- t = table(:id => "rowspan")
38
- second_row = t[2]
39
- second_row.to_a.should == ["3", "4"]
40
-
41
- third_row = t[3]
42
- third_row.to_a.should == ["5"]
43
- end
44
-
45
- end
@@ -1,78 +0,0 @@
1
- require "spec"
2
-
3
- describe Watir::Table do
4
- include WatirSplash::SpecHelper
5
-
6
- before :all do
7
- goto "http://dl.dropbox.com/u/2731643/WatirSplash/test.html"
8
- end
9
-
10
- it "#to_a works with regular table" do
11
- expected_table = [
12
- ["1", "2", "3"],
13
- ["4", "5", "6"],
14
- ["7", "8", "9"]
15
- ]
16
- table(:id => "normal").to_a.should == expected_table
17
- end
18
-
19
- it "#to_a works with table with headers" do
20
- expected_table = [
21
- ["1", "2", "3", "4"],
22
- ["5", "6", "7", "8"],
23
- ["9", "10", "11", "12"]
24
- ]
25
- table(:id => "headers").to_a.should == expected_table
26
- end
27
-
28
- it "#to_a works with nested tables" do
29
- expected_table =
30
- [
31
- ["1", "2"],
32
- [[["11", "12"],
33
- ["13", "14"]], "3"]
34
- ]
35
- table(:id => "nested").to_a(2).should == expected_table
36
- end
37
-
38
- it "#to_a works with nested table with non-direct child" do
39
- expected_table =
40
- [
41
- ["1", "2"],
42
- [[["11", "12"],
43
- ["13", "14"]], "3"]
44
- ]
45
-
46
- table(:id => "nestednondirectchild").to_a(2).should == expected_table
47
- end
48
-
49
- it "#to_a works with deep-nested tables" do
50
- expected_table =
51
- [
52
- ["1", "2"],
53
- [[["11", "12"],
54
- [[["404", "405"],
55
- ["406", "407"]], "14"]], "3"]
56
- ]
57
- table(:id => "deepnested").to_a(3).should == expected_table
58
- end
59
-
60
- it "#to_a works with colspan" do
61
- expected_table =
62
- [
63
- ["1", "2"],
64
- ["3"]
65
- ]
66
- table(:id => "colspan").to_a.should == expected_table
67
- end
68
-
69
- it "#to_a works with rowspan" do
70
- expected_table =
71
- [
72
- ["1", "2"],
73
- ["3", "4"],
74
- ["5"]
75
- ]
76
- table(:id => "rowspan").to_a.should match_array(expected_table)
77
- end
78
- end
@@ -1,22 +0,0 @@
1
- # Config for your application
2
- module Config
3
- module Application
4
- # URL, which will be opened by every test
5
- #
6
- # Replace it with the URL of your application under test
7
- # or if ui-test-common is used then
8
- # URL = Config.full_url("/relative/url/index.html")
9
- URL = "about:blank"
10
- end
11
- end
12
-
13
- # A global configuration for specs in this project, which will include by default
14
- # a ApplicationHelper module and open Config::Application::URL with
15
- # the browser.
16
- #
17
- # You can read more about RSpec-s before and after syntax from:
18
- # http://rspec.info/documentation/before_and_after.html
19
- Spec::Runner.configure do |config|
20
- config.include(ApplicationHelper)
21
- config.before(:all) {goto Config::Application::URL}
22
- end