pageify 0.4.0 → 0.4.1
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.
- checksums.yaml +4 -4
- data/lib/pageify.rb +2 -2
- data/lib/pageify/capybara.rb +6 -7
- data/lib/pageify/capybara_experimental.rb +14 -0
- data/lib/pageify/page_object.rb +11 -11
- data/spec/capybara_experimental_spec.rb +24 -0
- data/spec/capybara_spec.rb +5 -13
- data/spec/page_object_spec.rb +63 -0
- data/spec/spec_helper.rb +5 -0
- metadata +20 -3
- data/spec/sample_spec.rb +0 -63
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eebd76157633930a94ba1e764ec548a15726ff46
|
4
|
+
data.tar.gz: 83a2ec1bea6aaf9703a3a7f903f76147b254b211
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 15d42705f83d0a63f511b1dfc084602ecb048c671cf85b2f67168c179d020e1a21c46f97bce3613a94f10e6c7af954bcec1fed099522e0924fb2280d0fa74d7e
|
7
|
+
data.tar.gz: 0f8bcbf39bff06546ec529d9dd2bc84c6b858911a2f9586833de706727261e650ebc22fca2d063c2637ffa0d3946689ecb28c471b93dbdc990cf5f9fcb8146f7
|
data/lib/pageify.rb
CHANGED
@@ -14,9 +14,9 @@ module Pageify
|
|
14
14
|
element = PageObject.create(raw_row)
|
15
15
|
define_method(element.name) do |*arguments|
|
16
16
|
unless arguments.eql? []
|
17
|
-
$
|
17
|
+
$global_selector = (element.self_selector % arguments).strip_quotes.strip
|
18
18
|
else
|
19
|
-
$
|
19
|
+
$global_selector = (element.self_selector % '').strip_quotes.strip
|
20
20
|
end
|
21
21
|
element
|
22
22
|
end
|
data/lib/pageify/capybara.rb
CHANGED
@@ -1,16 +1,15 @@
|
|
1
1
|
class PageObject
|
2
2
|
include Capybara::DSL
|
3
3
|
|
4
|
-
def
|
5
|
-
|
6
|
-
args.empty? ? page_element.send(mtd_name) : page_element.send(mtd_name, *args)
|
4
|
+
def find()
|
5
|
+
page.find(self.selector)
|
7
6
|
end
|
8
7
|
|
9
|
-
def
|
10
|
-
|
8
|
+
def f()
|
9
|
+
self.find
|
11
10
|
end
|
12
11
|
|
13
|
-
def
|
14
|
-
page.
|
12
|
+
def find_all()
|
13
|
+
page.all(self.selector)
|
15
14
|
end
|
16
15
|
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
class PageObject
|
2
|
+
include Capybara::DSL
|
3
|
+
|
4
|
+
(Capybara::Driver::Node.public_instance_methods - Object.public_instance_methods ).each do |method|
|
5
|
+
define_method method do |*args|
|
6
|
+
page_element = page.find(self.selector)
|
7
|
+
args.empty? ? page_element.send(method) : page_element.send(method,*args)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def find_all()
|
12
|
+
page.all(self.selector)
|
13
|
+
end
|
14
|
+
end
|
data/lib/pageify/page_object.rb
CHANGED
@@ -1,19 +1,19 @@
|
|
1
1
|
class PageObject
|
2
|
-
attr_accessor :name,:parent,:
|
2
|
+
attr_accessor :name,:parent,:self_selector,:intend
|
3
3
|
|
4
4
|
def createChild (raw_row)
|
5
5
|
child = PageObject.create(raw_row)
|
6
6
|
child.parent = self
|
7
7
|
define_singleton_method(child.name) do |*arguments|
|
8
8
|
unless arguments.eql? []
|
9
|
-
child_selector = (child.
|
9
|
+
child_selector = (child.self_selector % arguments).strip_quotes.strip
|
10
10
|
else
|
11
|
-
child_selector = (child.
|
11
|
+
child_selector = (child.self_selector % '').strip_quotes.strip
|
12
12
|
end
|
13
13
|
if child_selector.start_with? "&"
|
14
|
-
$
|
14
|
+
$global_selector += child_selector.gsub(/^&/, "")
|
15
15
|
else
|
16
|
-
$
|
16
|
+
$global_selector += " " + child_selector
|
17
17
|
end
|
18
18
|
child
|
19
19
|
end
|
@@ -22,18 +22,18 @@ class PageObject
|
|
22
22
|
|
23
23
|
def self.create (raw_row)
|
24
24
|
name = raw_row.lstrip.split(":").first
|
25
|
-
|
25
|
+
self_selector = raw_row.slice(raw_row.index(':')+1..-1)
|
26
26
|
intend = raw_row.lspace
|
27
|
-
PageObject.new(name,
|
27
|
+
PageObject.new(name,self_selector,intend)
|
28
28
|
end
|
29
29
|
|
30
|
-
def
|
31
|
-
$
|
30
|
+
def selector
|
31
|
+
$global_selector.strip
|
32
32
|
end
|
33
33
|
|
34
|
-
def initialize (name,
|
34
|
+
def initialize (name,self_selector,intend)
|
35
35
|
@name = name
|
36
|
-
@
|
36
|
+
@self_selector = self_selector
|
37
37
|
@intend = intend
|
38
38
|
end
|
39
39
|
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'capybara/dsl'
|
2
|
+
require "pageify/capybara_experimental"
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Capybara do
|
6
|
+
before :each do
|
7
|
+
base_dir = File.expand_path File.join __FILE__, '..', 'pages'
|
8
|
+
@pageModule = Module.new.extend(Pageify)
|
9
|
+
@pageModule.pageify base_dir
|
10
|
+
@page = Class.new.send(:include, @pageModule).new
|
11
|
+
@dummy_page = double('dummy_page')
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should select the element in the page" do
|
15
|
+
mock_selected = double('mock selected')
|
16
|
+
expect(@page.root.simple).to receive(:page).and_return(@dummy_page).twice
|
17
|
+
expect(@dummy_page).to receive(:find).with('.root .simple').and_return(mock_selected).twice
|
18
|
+
expect(mock_selected).to receive(:set).with('something')
|
19
|
+
expect(mock_selected).to receive(:click)
|
20
|
+
expect(@page.root.simple.set('something'))
|
21
|
+
expect(@page.root.simple.click)
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
data/spec/capybara_spec.rb
CHANGED
@@ -13,20 +13,12 @@ describe Capybara do
|
|
13
13
|
|
14
14
|
it "should select the element in the page" do
|
15
15
|
mock_selected = double('mock selected')
|
16
|
-
expect(@page.root.simple).to receive(:page).and_return(@dummy_page).
|
16
|
+
expect(@page.root.simple).to receive(:page).and_return(@dummy_page).exactly(3).times
|
17
17
|
expect(@dummy_page).to receive(:find).with('.root .simple').and_return(mock_selected).twice
|
18
|
-
expect(
|
19
|
-
expect(
|
20
|
-
expect(@page.root.simple.
|
21
|
-
expect(@page.root.simple.
|
22
|
-
end
|
23
|
-
|
24
|
-
it "should select the element collection in the page" do
|
25
|
-
mock_selected = ['mock selected','test']
|
26
|
-
expect(@page.root.simple).to receive(:page).and_return(@dummy_page).twice
|
27
|
-
expect(@dummy_page).to receive(:find_all).with('.root .simple').and_return(mock_selected).twice
|
28
|
-
expect(@page.root.simple[0]).to eq(mock_selected[0])
|
29
|
-
expect(@page.root.simple.all).to eq(mock_selected)
|
18
|
+
expect(@dummy_page).to receive(:all).with('.root .simple').and_return(mock_selected).once
|
19
|
+
expect(@page.root.simple.find)
|
20
|
+
expect(@page.root.simple.f)
|
21
|
+
expect(@page.root.simple.find_all)
|
30
22
|
end
|
31
23
|
|
32
24
|
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Pageify do
|
4
|
+
before :each do
|
5
|
+
base_dir = File.expand_path File.join __FILE__, '..', 'pages'
|
6
|
+
@pageModule = Module.new.extend(Pageify)
|
7
|
+
@pageModule.pageify base_dir
|
8
|
+
@page = Class.new.send(:include, @pageModule).new
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should have root" do
|
12
|
+
expect(@page.root.selector).to eq(".root")
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should heck for root params" do
|
16
|
+
expect(@page.root("#id").simple.selector).to eq(".root #id .simple")
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should have simple page" do
|
20
|
+
expect(@page.root.simple.selector).to eq(".root .simple")
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should have nested pages" do
|
24
|
+
expect(@page.root.complex.selector).to eq(".root .complex")
|
25
|
+
expect(@page.root.complex.nested.selector).to eq(".root .complex .nested")
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should check arguments" do
|
29
|
+
expect(@page.root.complex.arg(1).selector).to eq(".root .complex .arg:nth-of-type(1)")
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should ignore arguments if not present" do
|
33
|
+
expect(@page.root.complex.arg.selector).to eq(".root .complex .arg:nth-of-type()")
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should check pages nested inside arguments" do
|
37
|
+
expect(@page.root.complex.arg(1).arg_nested.selector).to eq(".root .complex .arg:nth-of-type(1) .arg_nested")
|
38
|
+
end
|
39
|
+
|
40
|
+
it "does not support multiple pages at the same time" do
|
41
|
+
p1 = @page.root.simple
|
42
|
+
p2 = @page.root.complex.nested
|
43
|
+
|
44
|
+
expect(p1.selector).to eq(".root .complex .nested")
|
45
|
+
expect(p2.selector).to eq(".root .complex .nested")
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should normalize whitespace" do
|
49
|
+
expect(@page.root.complex.whitespace.selector).to eq(".root .complex .whitespace")
|
50
|
+
expect(@page.root.complex.whitespace.whitespace_nested.selector).to eq(".root .complex .whitespace .whitespace_nested")
|
51
|
+
end
|
52
|
+
|
53
|
+
it "& should add to previous selector" do
|
54
|
+
expect(@page.root.complex.nth(1).nth_variant.nth_nested.selector).to eq(".root .complex:nth-of-type(1).nth_variant .nth_nested")
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should access sections mentioned" do
|
58
|
+
expect(@page.root.complex.nth(1).details.name("seera").initial.letter.selector).to eq(".root .complex:nth-of-type(1) .first_section .name[name=seera] .initial #let")
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should not scan sections as page objects" do
|
62
|
+
end
|
63
|
+
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pageify
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Deepak
|
@@ -80,6 +80,20 @@ dependencies:
|
|
80
80
|
- - '='
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: 0.2.4
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: simplecov
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 0.9.0
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 0.9.0
|
83
97
|
description: Simplify page object definition for UI tests
|
84
98
|
email:
|
85
99
|
executables: []
|
@@ -89,13 +103,15 @@ files:
|
|
89
103
|
- README.md
|
90
104
|
- lib/pageify.rb
|
91
105
|
- lib/pageify/capybara.rb
|
106
|
+
- lib/pageify/capybara_experimental.rb
|
92
107
|
- lib/pageify/page_object.rb
|
93
108
|
- lib/pageify/string.rb
|
109
|
+
- spec/capybara_experimental_spec.rb
|
94
110
|
- spec/capybara_spec.rb
|
111
|
+
- spec/page_object_spec.rb
|
95
112
|
- spec/pages/sample_page.yml
|
96
113
|
- spec/pages/section/_details.yml
|
97
114
|
- spec/pages/section/_initial.yml
|
98
|
-
- spec/sample_spec.rb
|
99
115
|
- spec/spec_helper.rb
|
100
116
|
homepage: https://github.com/paramadeep/pageify
|
101
117
|
licenses:
|
@@ -123,8 +139,9 @@ specification_version: 4
|
|
123
139
|
summary: Simplify page object definition for UI tests
|
124
140
|
test_files:
|
125
141
|
- spec/spec_helper.rb
|
126
|
-
- spec/sample_spec.rb
|
127
142
|
- spec/pages/section/_initial.yml
|
128
143
|
- spec/pages/section/_details.yml
|
129
144
|
- spec/pages/sample_page.yml
|
145
|
+
- spec/page_object_spec.rb
|
130
146
|
- spec/capybara_spec.rb
|
147
|
+
- spec/capybara_experimental_spec.rb
|
data/spec/sample_spec.rb
DELETED
@@ -1,63 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Pageify do
|
4
|
-
before :each do
|
5
|
-
base_dir = File.expand_path File.join __FILE__, '..', 'pages'
|
6
|
-
@pageModule = Module.new.extend(Pageify)
|
7
|
-
@pageModule.pageify base_dir
|
8
|
-
@page = Class.new.send(:include, @pageModule).new
|
9
|
-
end
|
10
|
-
|
11
|
-
it "should have root" do
|
12
|
-
expect(@page.root.current_selector).to eq(".root")
|
13
|
-
end
|
14
|
-
|
15
|
-
it "should heck for root params" do
|
16
|
-
expect(@page.root("#id").simple.current_selector).to eq(".root #id .simple")
|
17
|
-
end
|
18
|
-
|
19
|
-
it "should have simple page" do
|
20
|
-
expect(@page.root.simple.current_selector).to eq(".root .simple")
|
21
|
-
end
|
22
|
-
|
23
|
-
it "should have nested pages" do
|
24
|
-
expect(@page.root.complex.current_selector).to eq(".root .complex")
|
25
|
-
expect(@page.root.complex.nested.current_selector).to eq(".root .complex .nested")
|
26
|
-
end
|
27
|
-
|
28
|
-
it "should check arguments" do
|
29
|
-
expect(@page.root.complex.arg(1).current_selector).to eq(".root .complex .arg:nth-of-type(1)")
|
30
|
-
end
|
31
|
-
|
32
|
-
it "should ignore arguments if not present" do
|
33
|
-
expect(@page.root.complex.arg.current_selector).to eq(".root .complex .arg:nth-of-type()")
|
34
|
-
end
|
35
|
-
|
36
|
-
it "should check pages nested inside arguments" do
|
37
|
-
expect(@page.root.complex.arg(1).arg_nested.current_selector).to eq(".root .complex .arg:nth-of-type(1) .arg_nested")
|
38
|
-
end
|
39
|
-
|
40
|
-
it "does not support multiple pages at the same time" do
|
41
|
-
p1 = @page.root.simple
|
42
|
-
p2 = @page.root.complex.nested
|
43
|
-
|
44
|
-
expect(p1.current_selector).to eq(".root .complex .nested")
|
45
|
-
expect(p2.current_selector).to eq(".root .complex .nested")
|
46
|
-
end
|
47
|
-
|
48
|
-
it "should normalize whitespace" do
|
49
|
-
expect(@page.root.complex.whitespace.current_selector).to eq(".root .complex .whitespace")
|
50
|
-
expect(@page.root.complex.whitespace.whitespace_nested.current_selector).to eq(".root .complex .whitespace .whitespace_nested")
|
51
|
-
end
|
52
|
-
|
53
|
-
it "& should add to previous selector" do
|
54
|
-
expect(@page.root.complex.nth(1).nth_variant.nth_nested.current_selector).to eq(".root .complex:nth-of-type(1).nth_variant .nth_nested")
|
55
|
-
end
|
56
|
-
|
57
|
-
it "should access sections mentioned" do
|
58
|
-
expect(@page.root.complex.nth(1).details.name("seera").initial.letter.current_selector).to eq(".root .complex:nth-of-type(1) .first_section .name[name=seera] .initial #let")
|
59
|
-
end
|
60
|
-
|
61
|
-
it "should not scan sections as page objects" do
|
62
|
-
end
|
63
|
-
end
|