page_object_wrapper 1.4.8 → 1.4.9
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/page_object_wrapper/PageObject.rb +51 -0
- data/lib/version.rb +1 -1
- data/spec/select_raw_from_xxx_spec.rb +91 -0
- metadata +14 -12
@@ -24,6 +24,7 @@ module PageObjectWrapper
|
|
24
24
|
FEED = Regexp.new(/^feed_([\w_]+)$/)
|
25
25
|
FIRE_ACTION = Regexp.new(/^fire_([\w_]+)$/)
|
26
26
|
SELECT_FROM = Regexp.new(/^select_from_([\w_]+)$/)
|
27
|
+
SELECT_ROW_FROM = Regexp.new(/^select_row_from_([\w_]+)$/)
|
27
28
|
PAGINATION_EACH = Regexp.new(/^([\w_]+)_each$/)
|
28
29
|
PAGINATION_OPEN = Regexp.new(/^([\w_]+)_open$/)
|
29
30
|
VALIDATE = Regexp.new(/^validate_([\w_\?]+)$/)
|
@@ -96,6 +97,10 @@ module PageObjectWrapper
|
|
96
97
|
# page_object.select_from_some_table(:header_column, {:column => 'value'})
|
97
98
|
table = table_for($1)
|
98
99
|
select_from(table, *args)
|
100
|
+
when (SELECT_ROW_FROM.match(method_name) and has_table?($1))
|
101
|
+
# page_object.select_row_from_some_table(:number => 1, :column1 => value1, :column2 => value3, ...)
|
102
|
+
table = table_for($1)
|
103
|
+
select_row_from(table, args[0])
|
99
104
|
when (PAGINATION_EACH.match(method_name) and has_pagination?($1))
|
100
105
|
# page_object.each_pagination
|
101
106
|
pagination = pagination_for($1)
|
@@ -147,6 +152,9 @@ module PageObjectWrapper
|
|
147
152
|
when (SELECT_FROM.match(method_name) and has_table?($1))
|
148
153
|
# page_object.select_from_some_table(:header_column, {:column => 'value'})
|
149
154
|
true
|
155
|
+
when (SELECT_ROW_FROM.match(method_name) and has_table?($1))
|
156
|
+
# page_object.select_from_some_table(:header_column, {:column => 'value'})
|
157
|
+
true
|
150
158
|
when (PAGINATION_EACH.match(method_name) and has_pagination?($1))
|
151
159
|
# page_object.each_pagination
|
152
160
|
true
|
@@ -506,6 +514,49 @@ module PageObjectWrapper
|
|
506
514
|
end
|
507
515
|
end
|
508
516
|
|
517
|
+
def select_row_from(table, query)
|
518
|
+
conditions = query.clone
|
519
|
+
conditions.delete(:number)
|
520
|
+
raise PageObjectWrapper::BrowserNotFound if @@browser.nil? or not @@browser.exist?
|
521
|
+
t = @@browser.table(table.locator_value)
|
522
|
+
found_row = {}
|
523
|
+
candidate_rows = nil
|
524
|
+
raise ArgumentError, "argument should be a meaningful Hash, got #{query.inspect}" if not query.is_a?(Hash) or query.empty?
|
525
|
+
if query.has_key?(:number) and query[:number].class != Fixnum
|
526
|
+
raise ArgumentError, "arguments key :number should have Integer value, got #{query[:number].class}"
|
527
|
+
end
|
528
|
+
if not conditions.empty? and (conditions.keys.collect(&:class).uniq != [Symbol] or conditions.values.collect(&:class).uniq != [String])
|
529
|
+
raise ArgumentError, "arguments hash should be like :symbol => 'a string' (for all columns except :number), got #{query.inspect}"
|
530
|
+
end
|
531
|
+
|
532
|
+
if query.has_key? :number
|
533
|
+
candidate_rows = [t[query[:number]]]
|
534
|
+
query.delete(:number)
|
535
|
+
else
|
536
|
+
candidate_rows = t.rows
|
537
|
+
end
|
538
|
+
|
539
|
+
candidate_rows.each{ |r|
|
540
|
+
conditions_met = true
|
541
|
+
unless query.empty?
|
542
|
+
query.each_key{ |column_name|
|
543
|
+
raise ArgumentError, "column #{column_name.inspect} not in table header and not == :number" if not table.header_value.include?(column_name)
|
544
|
+
column_index = table.header_value.index(column_name)
|
545
|
+
conditions_met = false if r[column_index].text != query[column_name]
|
546
|
+
}
|
547
|
+
end
|
548
|
+
if conditions_met
|
549
|
+
column_index = 0
|
550
|
+
r.cells.each{ |cell|
|
551
|
+
found_row[table.header_value[column_index]] = cell
|
552
|
+
column_index += 1
|
553
|
+
}
|
554
|
+
return found_row
|
555
|
+
end
|
556
|
+
}
|
557
|
+
return nil
|
558
|
+
end
|
559
|
+
|
509
560
|
def run_each_subpage(p, opts=nil, &block)
|
510
561
|
raise PageObjectWrapper::BrowserNotFound if @@browser.nil? or not @@browser.exist?
|
511
562
|
limit = opts[:limit] if not opts.nil?
|
data/lib/version.rb
CHANGED
@@ -0,0 +1,91 @@
|
|
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
|
+
tp = PageObjectWrapper.receive_page(:some_test_page)
|
8
|
+
expect{ tp.select_row_from_table_without_header(:column_2 => '') }.to raise_error(PageObjectWrapper::BrowserNotFound)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
context "browser is opened" do
|
12
|
+
before(:all){
|
13
|
+
@b = Watir::Browser.new
|
14
|
+
PageObjectWrapper.use_browser @b
|
15
|
+
}
|
16
|
+
after(:all){ PageObjectWrapper.browser.quit }
|
17
|
+
let!(:tp){ PageObjectWrapper.open_page(:some_test_page)}
|
18
|
+
|
19
|
+
context "wrong arguments" do
|
20
|
+
context "arguments is not a meaningful Hash" do
|
21
|
+
it "raises ArgumentError" do
|
22
|
+
expect{ tp.select_row_from_table_without_header('') }.to raise_error(ArgumentError)
|
23
|
+
expect{ tp.select_row_from_table_with_header({}) }.to raise_error(ArgumentError)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context "values inside arguments Hash are not strings or :number != Integer" do
|
28
|
+
it "raises ArgumentError" do
|
29
|
+
expect{ tp.select_row_from_table_with_header(:country => []) }.to raise_error(ArgumentError)
|
30
|
+
expect{ tp.select_row_from_table_with_header(:number => 'string') }.to raise_error(ArgumentError)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
context "specified column not found inside table" do
|
35
|
+
it "raises ArgumentError" do
|
36
|
+
expect{ tp.select_row_from_table_without_header(:unknown_column => 'some value') }.to raise_error(ArgumentError)
|
37
|
+
expect{ tp.select_row_from_table_with_header(:column_1 => 'some value') }.to raise_error(ArgumentError)
|
38
|
+
expect{ tp.select_row_from_table_with_header(:unknown_column => 'some value') }.to raise_error(ArgumentError)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
context "table with header" do
|
44
|
+
it "returns first found row excluding table header" do
|
45
|
+
t_row = tp.select_row_from_table_with_header(:number => 1)
|
46
|
+
t_row.should be_a Hash
|
47
|
+
t_row[:country].text.should eq 'Denmark'
|
48
|
+
t_row = tp.select_row_from_table_with_header(:country => 'Denmark')
|
49
|
+
t_row.should be_a Hash
|
50
|
+
t_row[:country].text.should eq 'Denmark'
|
51
|
+
t_row = tp.select_row_from_table_with_header(:number => 1, :country => 'Denmark')
|
52
|
+
t_row.should be_a Hash
|
53
|
+
t_row[:country].text.should eq 'Denmark'
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
context "table without header" do
|
58
|
+
it "returns first found row including table header" do
|
59
|
+
t_row = tp.select_row_from_table_without_header(:number => 1)
|
60
|
+
t_row.should be_a Hash
|
61
|
+
t_row[:column_0].text.should eq 'Denmark'
|
62
|
+
t_row = tp.select_row_from_table_without_header(:column_0 => 'Denmark')
|
63
|
+
t_row.should be_a Hash
|
64
|
+
t_row[:column_0].text.should eq 'Denmark'
|
65
|
+
t_row = tp.select_row_from_table_without_header(:number => 1, :column_0 => 'Denmark')
|
66
|
+
t_row.should be_a Hash
|
67
|
+
t_row[:column_0].text.should eq 'Denmark'
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
context "several rows found" do
|
72
|
+
it "returns first found row" do
|
73
|
+
table_page = tp.fire_press_cool_button
|
74
|
+
t_row = table_page.select_row_from_test_table(:column_1 => 'Default text.')
|
75
|
+
t_row.should be_a Hash
|
76
|
+
t_row[:column_0].text.should eq 'text'
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
context "no rows found" do
|
81
|
+
it "returns nil" do
|
82
|
+
t_row = tp.select_row_from_table_with_header(:number => 1, :country => 'Russia')
|
83
|
+
t_row.should eq nil
|
84
|
+
t_row = tp.select_row_from_table_with_header(:country => 'Russia', :land_area => '100')
|
85
|
+
t_row.should eq nil
|
86
|
+
t_row = tp.select_row_from_table_without_header(:number => 1, :column_1 => 'Russia')
|
87
|
+
t_row.should eq nil
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
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: 1.4.
|
4
|
+
version: 1.4.9
|
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: 2013-04-
|
12
|
+
date: 2013-04-15 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: watir-webdriver
|
16
|
-
requirement: &
|
16
|
+
requirement: &13065260 !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: *
|
24
|
+
version_requirements: *13065260
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: activesupport
|
27
|
-
requirement: &
|
27
|
+
requirement: &13100340 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *13100340
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: babosa
|
38
|
-
requirement: &
|
38
|
+
requirement: &13099320 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *13099320
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: rspec
|
49
|
-
requirement: &
|
49
|
+
requirement: &13094780 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: 2.0.0
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *13094780
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: debugger
|
60
|
-
requirement: &
|
60
|
+
requirement: &13116000 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,7 +65,7 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *13116000
|
69
69
|
description: Wraps watir-webdriver with convenient testing interface, based on PageObjects
|
70
70
|
automation testing pattern. Simplifies resulting automated test understanding.
|
71
71
|
email:
|
@@ -116,6 +116,7 @@ files:
|
|
116
116
|
- spec/press_xxx_spec.rb
|
117
117
|
- spec/required_elements_spec.rb
|
118
118
|
- spec/select_from_xxx_spec.rb
|
119
|
+
- spec/select_raw_from_xxx_spec.rb
|
119
120
|
- spec/shared_examples.rb
|
120
121
|
- spec/spec_helper.rb
|
121
122
|
- spec/xxx_each.rb
|
@@ -156,6 +157,7 @@ test_files:
|
|
156
157
|
- spec/press_xxx_spec.rb
|
157
158
|
- spec/required_elements_spec.rb
|
158
159
|
- spec/select_from_xxx_spec.rb
|
160
|
+
- spec/select_raw_from_xxx_spec.rb
|
159
161
|
- spec/shared_examples.rb
|
160
162
|
- spec/spec_helper.rb
|
161
163
|
- spec/xxx_each.rb
|