page_object_wrapper 0.0.6 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. data/README.md +180 -340
  2. data/bad_pages/bad_page.rb +34 -0
  3. data/good_pages/another_test_page.rb +14 -0
  4. data/good_pages/some_test_page.rb +53 -0
  5. data/good_pages/test_table_page.rb +12 -0
  6. data/img/scheme.png +0 -0
  7. data/lib/page_object_wrapper.rb +57 -92
  8. data/lib/page_object_wrapper/Action.rb +11 -0
  9. data/lib/page_object_wrapper/Dsl.rb +35 -0
  10. data/lib/page_object_wrapper/Element.rb +15 -0
  11. data/lib/page_object_wrapper/ElementsSet.rb +22 -0
  12. data/lib/page_object_wrapper/Exceptions.rb +7 -21
  13. data/lib/page_object_wrapper/PageObject.rb +371 -0
  14. data/lib/page_object_wrapper/Pagination.rb +6 -57
  15. data/lib/page_object_wrapper/Table.rb +13 -48
  16. data/lib/page_object_wrapper/known_elements.rb +31 -0
  17. data/lib/page_object_wrapper/version.rb +1 -1
  18. data/spec/define_page_object_spec.rb +162 -0
  19. data/spec/defined_elements_spec.rb +77 -0
  20. data/spec/feed_elements_spec.rb +95 -0
  21. data/spec/fire_event_spec.rb +53 -0
  22. data/spec/generate_spec.rb +20 -0
  23. data/spec/load_spec.rb +46 -0
  24. data/spec/open_spec.rb +70 -0
  25. data/spec/select_from_spec.rb +84 -0
  26. data/spec/shared_examples.rb +12 -0
  27. data/spec/spec_helper.rb +2 -15
  28. metadata +35 -27
  29. data/Gemfile +0 -4
  30. data/LICENSE.txt +0 -22
  31. data/Rakefile +0 -1
  32. data/lib/page_object_wrapper/Distribution.rb +0 -43
  33. data/lib/page_object_wrapper/DynamicClass.rb +0 -31
  34. data/lib/page_object_wrapper/Editable.rb +0 -13
  35. data/lib/page_object_wrapper/Form.rb +0 -116
  36. data/lib/page_object_wrapper/Submitter.rb +0 -8
  37. data/page_object_wrapper.gemspec +0 -22
  38. data/spec/example_spec.rb +0 -42
  39. data/spec/form_spec.rb +0 -176
  40. data/spec/page_object_spec.rb +0 -173
  41. data/spec/pagination_spec.rb +0 -14
  42. data/spec/table_spec.rb +0 -52
  43. data/spec/test_data_spec.rb +0 -38
@@ -0,0 +1,53 @@
1
+ require 'spec_helper'
2
+ require 'shared_examples'
3
+
4
+ describe "page_object.fire_xxx" do
5
+ context "browser is closed" do
6
+ it "raises PageObjectWrapper::BrowserNotFound" do
7
+ begin
8
+ PageObjectWrapper.browser.quit if not PageObjectWrapper.browser.nil?
9
+ PageObjectWrapper.load('./good_pages')
10
+ rescue
11
+ end
12
+ tp = PageObjectWrapper.receive_page(:some_test_page)
13
+ expect{ tp.fire_press_cool_button }.to raise_error(PageObjectWrapper::BrowserNotFound)
14
+ end
15
+ end
16
+ context "browser is opened" do
17
+ before(:all){
18
+ @b = Watir::Browser.new
19
+ PageObjectWrapper.use_browser @b
20
+ begin
21
+ PageObjectWrapper.load('./good_pages')
22
+ rescue
23
+ end
24
+ }
25
+ after(:all){ PageObjectWrapper.browser.close }
26
+
27
+ context "xxx not found among current_page actions" do
28
+ it "raises NoMethodError" do
29
+ tp = PageObjectWrapper.current_page
30
+ expect{tp.fire_nonexistent_action}.to raise_error(NoMethodError)
31
+ end
32
+ end
33
+
34
+ it "executes fire_block in Watir::Browser context" do
35
+ tp = PageObjectWrapper.open_page(:some_test_page)
36
+ tp.fire_fill_textarea
37
+ @b.textarea(:id => 'f2').value.should eq('Default data')
38
+ end
39
+
40
+ it "can be invoked with parameters" do
41
+ tp = PageObjectWrapper.current_page
42
+ tp.fire_fill_textarea('User defined data')
43
+ @b.textarea(:id => 'f2').value.should eq('User defined data')
44
+ end
45
+
46
+ it "returns next_page" do
47
+ tp = PageObjectWrapper.current_page
48
+ np = tp.fire_press_cool_button
49
+ np.should be_a(PageObject)
50
+ np.label_value.should eq(:test_page_with_table)
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+
3
+ describe "PageObjectWrapper.generate" do
4
+ it "accepts two arguments - a path_to_an_html file and an optional array which defines what types of elements to generate" do
5
+ end
6
+
7
+ describe "generation of a PageObject definition" do
8
+ it "generates element_sets for the forms on the page" do
9
+ end
10
+
11
+ it "generates tables found on the page" do
12
+ end
13
+
14
+ it "tries to find and generate pagination on the page" do
15
+ end
16
+ end
17
+
18
+ it "outputs generated data to STDOUT" do
19
+ end
20
+ end
@@ -0,0 +1,46 @@
1
+ require 'spec_helper'
2
+
3
+ describe "PageObjectWrapper.load" do
4
+ it "accepts path to the \'pages\' folder" do
5
+ expect{ PageObjectWrapper.load('unknown/dir')}.to raise_error(PageObjectWrapper::Load)
6
+ end
7
+
8
+ describe "page load" do
9
+ it "raises PageObjectWrapper::Load error with all errors described" do
10
+ begin
11
+ PageObjectWrapper.load(File.dirname(__FILE__)+'/../bad_pages')
12
+ rescue Exception => e
13
+ #puts e.message
14
+ e.should be_a(PageObjectWrapper::Load)
15
+ e.message.should == 'page_object("some_page_with_lost_of_errors"):
16
+ label "some_page_with_lost_of_errors" not a Symbol
17
+ locator "" not a meaningful String
18
+ elements_set("some elements_set label"):
19
+ label "some elements_set label" not a Symbol
20
+ element(""):
21
+ label "" not a Symbol
22
+ locator nil not a meaningful Hash
23
+ element(:e):
24
+ element :e already defined
25
+ locator ":e element locator" not a meaningful Hash
26
+ element(:e):
27
+ element :e already defined
28
+ locator {} not a meaningful Hash
29
+ action(""):
30
+ label "" not a Symbol
31
+ next_page nil not a Symbol
32
+ next_page nil unknown page_object
33
+ table(""):
34
+ label "" not a Symbol
35
+ locator nil not a meaningful Hash
36
+ table(:some_table):
37
+ locator nil not a meaningful Hash
38
+ header [] not a meaningful Array
39
+ pagination(""):
40
+ label "" not a Symbol
41
+ locator "pagination locator" not a meaningful Hash
42
+ '
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,70 @@
1
+ require 'spec_helper'
2
+
3
+ describe "PageObjectWrapper.open_page" do
4
+ let(:define_page_object){
5
+ PageObjectWrapper.define_page(:google_page) do
6
+ locator 'google.com'
7
+ uniq_input :id => 'gbqfq'
8
+ end
9
+ }
10
+ let(:define_wrong_page_object){
11
+ PageObjectWrapper.define_page(:wrong_google_page) do
12
+ locator 'google.com'
13
+ uniq_element :id => 'foobar'
14
+ end
15
+ }
16
+ let(:define_page_object_with_local_path){
17
+ PageObjectWrapper.define_page(:google_as_page) do
18
+ locator '/advanced_search'
19
+ uniq_text_field :name => 'as_q'
20
+ end
21
+ }
22
+
23
+ context "browser is closed" do
24
+ it "raises PageObjectWrapper::BrowserNotFound" do
25
+ define_page_object
26
+ PageObject.browser = nil
27
+ expect{ PageObjectWrapper.open_page(:google_page) }.to raise_error(PageObjectWrapper::BrowserNotFound)
28
+ end
29
+ end
30
+
31
+ context "browser is opened" do
32
+
33
+ before(:all){
34
+ @b = Watir::Browser.new
35
+ PageObjectWrapper.use_browser @b
36
+ define_page_object
37
+ define_wrong_page_object
38
+ define_page_object_with_local_path
39
+ }
40
+
41
+ after(:all){ PageObjectWrapper.browser.close }
42
+
43
+ it "raises errors" do
44
+ expect{ PageObjectWrapper.open_page(:first_arg, :second_arg) }.to raise_error(ArgumentError)
45
+ expect{ PageObjectWrapper.open_page(:unknown_page) }.to raise_error(PageObjectWrapper::UnknownPageObject)
46
+ expect{ PageObjectWrapper.open_page(:wrong_google_page) }.to raise_error(PageObjectWrapper::UnmappedPageObject)
47
+ end
48
+
49
+ it "returns opened PageObject instance" do
50
+ p = PageObjectWrapper.open_page(:google_page)
51
+ p.should be_an_instance_of(PageObject)
52
+ p.label_value.should eq(:google_page)
53
+ end
54
+
55
+ context "domain is not specified" do
56
+ it "opens browser on the page.locator" do
57
+ gp = PageObjectWrapper.open_page(:google_page)
58
+ @b.url.should =~/www\.google/
59
+ end
60
+ end
61
+
62
+ context "domain is specified" do
63
+ it "opens browser on domain+page.locator" do
64
+ PageObjectWrapper.domain = 'google.com'
65
+ PageObjectWrapper.open_page(:google_as_page)
66
+ @b.url.should =~/\/advanced_search/
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,84 @@
1
+ require 'spec_helper'
2
+ require 'shared_examples'
3
+
4
+ describe "page_object.select_from_xxx" do
5
+ context "browser is closed" do
6
+ it "raises PageObjectWrapper::BrowserNotFound" do
7
+ begin
8
+ PageObjectWrapper.load('./good_pages')
9
+ rescue
10
+ end
11
+ PageObject.browser = nil
12
+ tp = PageObjectWrapper.receive_page(:some_test_page)
13
+ expect{ tp.select_from_table_without_header(:column_1, {:column_2 => ''}) }.to raise_error(PageObjectWrapper::BrowserNotFound)
14
+ end
15
+ end
16
+ context "browser is opened" do
17
+ before(:all){
18
+ @b = Watir::Browser.new
19
+ PageObjectWrapper.use_browser @b
20
+ begin
21
+ PageObjectWrapper.load('./good_pages')
22
+ rescue
23
+ end
24
+ }
25
+ after(:all){ PageObjectWrapper.browser.close }
26
+ let!(:tp){ PageObjectWrapper.open_page(:some_test_page)}
27
+
28
+ context "wrong arguments" do
29
+ it "raises ArgumentError if first_arg not a Symbol" do
30
+ expect{ tp.select_from_table_without_header(nil,{}) }.to raise_error ArgumentError, "nil not a Symbol"
31
+ end
32
+ it "raises ArgumentError if first_arg not included in table_header" do
33
+ expect{ tp.select_from_table_without_header(:nonexistent_column, {}) }.to raise_error ArgumentError, ":nonexistent_column not in table header"
34
+ end
35
+ it "raises ArgumentError if second_arg not a meaningful Hash" do
36
+ expect{ tp.select_from_table_without_header(:column_1, 'a string') }.to raise_error ArgumentError, '"a string" not a meaningful Hash'
37
+ end
38
+ it "raises ArgumentError if second_arg has more than 1 keys" do
39
+ expect{ tp.select_from_table_without_header(:column_1, {:column_1 => 'foo', :column_2 => 'bar'})}.to raise_error ArgumentError, '{:column_1=>"foo", :column_2=>"bar"} has more than 1 keys'
40
+ end
41
+ it "raises ArgumentError if second_arg's key not included in table_header" do
42
+ expect{ tp.select_from_table_without_header(:column_1, { :nonexistent_column => 'some value' }) }.to raise_error ArgumentError, ":nonexistent_column not in table header"
43
+ end
44
+ it "raises ArgumentError if second_arg's value not meaningful a String or Regexp" do
45
+ expect{ tp.select_from_table_without_header(:column_1, { :column_2 => Array.new }) }.to raise_error ArgumentError, "[] not a String or Regexp"
46
+ end
47
+ it "raises Watir::Exception::UnknownObjectException if requested for non existing column" do
48
+ expect{ tp.select_from_table_without_header(:column_3).text }.to raise_error(Watir::Exception::UnknownObjectException)
49
+ end
50
+ end
51
+
52
+ context "where == nil" do
53
+ it "returns last row value from provided column" do
54
+ tp.select_from_table_without_header(:column_0).text.should eq 'Sweden'
55
+ tp.select_from_table_without_header(:column_1).text.should eq '449,964'
56
+ tp.select_from_table_without_header(:column_2).text.should eq '410,928'
57
+ end
58
+ end
59
+
60
+ context "where not nil" do
61
+ context "found by String" do
62
+ it "returns found cells" do
63
+ tp.select_from_table_without_header(:column_0, :column_1 => '103,000').text.should eq 'Iceland'
64
+ tp.select_from_table_with_header(:country, :total_area => '337,030').text.should eq 'Finland'
65
+ end
66
+ it "returns nil" do
67
+ tp.select_from_table_without_header(:column_0, :column_1 => '123').should eq nil
68
+ tp.select_from_table_with_header(:country, :total_area => '123').should eq nil
69
+ end
70
+ end
71
+ context "found by Regexp" do
72
+ it "returns found cells" do
73
+ tp.select_from_table_without_header(:column_0, :column_1 => /103/).text.should eq 'Iceland'
74
+ tp.select_from_table_with_header(:country, :total_area => /337/).text.should eq 'Finland'
75
+ end
76
+ it "returns nil" do
77
+ tp.select_from_table_without_header(:column_0, :column_1 => /123/).should eq nil
78
+ tp.select_from_table_with_header(:country, :total_area => /123/).should eq nil
79
+ end
80
+ end
81
+ end
82
+ end
83
+ end
84
+
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+
3
+ shared_examples_for "a label" do
4
+ it { should respond_to(:label)}
5
+ it { should respond_to(:label_value)}
6
+ specify { subject.label_value.should be_a(Symbol)}
7
+ end
8
+
9
+ shared_examples_for "a locator" do
10
+ it { should respond_to(:locator) }
11
+ it { should respond_to(:locator_value)}
12
+ end
@@ -1,15 +1,2 @@
1
- # -*- encoding : utf-8 -*-
2
- require "rspec"
3
- require 'page_object_wrapper'
4
-
5
- RSpec.configure do |config|
6
- config.before(:suite) {
7
- PageObjectWrapper.start_browser
8
- PageObjectWrapper.domain = 'http://google.com'
9
- }
10
-
11
- config.after(:suite) {
12
- PageObjectWrapper.stop_browser
13
- }
14
- end
15
-
1
+ require "page_object_wrapper"
2
+ Selenium::WebDriver::Firefox.path='/opt/firefox/firefox'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: page_object_wrapper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 1.0.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-03 00:00:00.000000000 Z
12
+ date: 2012-12-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: watir-webdriver
16
- requirement: &8651860 !ruby/object:Gem::Requirement
16
+ requirement: &11659160 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *8651860
24
+ version_requirements: *11659160
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rspec
27
- requirement: &8651340 !ruby/object:Gem::Requirement
27
+ requirement: &11658620 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: 2.0.0
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *8651340
35
+ version_requirements: *11658620
36
36
  description: Wraps watir-webdriver with convenient testing interface, based on PageObjects
37
37
  automation testing pattern. Simplifies resulting automated test understanding.
38
38
  email:
@@ -42,28 +42,33 @@ extensions: []
42
42
  extra_rdoc_files: []
43
43
  files:
44
44
  - .gitignore
45
- - Gemfile
46
- - LICENSE.txt
47
45
  - README.md
48
- - Rakefile
46
+ - bad_pages/bad_page.rb
47
+ - good_pages/another_test_page.rb
48
+ - good_pages/some_test_page.rb
49
+ - good_pages/test_table_page.rb
50
+ - img/scheme.png
49
51
  - lib/page_object_wrapper.rb
50
- - lib/page_object_wrapper/Distribution.rb
51
- - lib/page_object_wrapper/DynamicClass.rb
52
- - lib/page_object_wrapper/Editable.rb
52
+ - lib/page_object_wrapper/Action.rb
53
+ - lib/page_object_wrapper/Dsl.rb
54
+ - lib/page_object_wrapper/Element.rb
55
+ - lib/page_object_wrapper/ElementsSet.rb
53
56
  - lib/page_object_wrapper/Exceptions.rb
54
- - lib/page_object_wrapper/Form.rb
57
+ - lib/page_object_wrapper/PageObject.rb
55
58
  - lib/page_object_wrapper/Pagination.rb
56
- - lib/page_object_wrapper/Submitter.rb
57
59
  - lib/page_object_wrapper/Table.rb
60
+ - lib/page_object_wrapper/known_elements.rb
58
61
  - lib/page_object_wrapper/version.rb
59
- - page_object_wrapper.gemspec
60
- - spec/example_spec.rb
61
- - spec/form_spec.rb
62
- - spec/page_object_spec.rb
63
- - spec/pagination_spec.rb
62
+ - spec/define_page_object_spec.rb
63
+ - spec/defined_elements_spec.rb
64
+ - spec/feed_elements_spec.rb
65
+ - spec/fire_event_spec.rb
66
+ - spec/generate_spec.rb
67
+ - spec/load_spec.rb
68
+ - spec/open_spec.rb
69
+ - spec/select_from_spec.rb
70
+ - spec/shared_examples.rb
64
71
  - spec/spec_helper.rb
65
- - spec/table_spec.rb
66
- - spec/test_data_spec.rb
67
72
  homepage: https://github.com/evgeniy-khatko/page_object_wrapper
68
73
  licenses: []
69
74
  post_install_message:
@@ -90,10 +95,13 @@ signing_key:
90
95
  specification_version: 3
91
96
  summary: Wraps watir-webdriver with convenient testing interface.
92
97
  test_files:
93
- - spec/example_spec.rb
94
- - spec/form_spec.rb
95
- - spec/page_object_spec.rb
96
- - spec/pagination_spec.rb
98
+ - spec/define_page_object_spec.rb
99
+ - spec/defined_elements_spec.rb
100
+ - spec/feed_elements_spec.rb
101
+ - spec/fire_event_spec.rb
102
+ - spec/generate_spec.rb
103
+ - spec/load_spec.rb
104
+ - spec/open_spec.rb
105
+ - spec/select_from_spec.rb
106
+ - spec/shared_examples.rb
97
107
  - spec/spec_helper.rb
98
- - spec/table_spec.rb
99
- - spec/test_data_spec.rb
data/Gemfile DELETED
@@ -1,4 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- # Specify your gem's dependencies in page_object_wrapper.gemspec
4
- gemspec
@@ -1,22 +0,0 @@
1
- Copyright (c) 2012 ekhatko
2
-
3
- MIT License
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining
6
- a copy of this software and associated documentation files (the
7
- "Software"), to deal in the Software without restriction, including
8
- without limitation the rights to use, copy, modify, merge, publish,
9
- distribute, sublicense, and/or sell copies of the Software, and to
10
- permit persons to whom the Software is furnished to do so, subject to
11
- the following conditions:
12
-
13
- The above copyright notice and this permission notice shall be
14
- included in all copies or substantial portions of the Software.
15
-
16
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.