pageify 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 21866c9cee127dec9164e74933463e07f4f2b99f
4
- data.tar.gz: 6dd3dc9b9115c98f08f480265a612745afedb191
3
+ metadata.gz: eebd76157633930a94ba1e764ec548a15726ff46
4
+ data.tar.gz: 83a2ec1bea6aaf9703a3a7f903f76147b254b211
5
5
  SHA512:
6
- metadata.gz: 28395f7d706942ae9ef150e79be35c2dea6d33601d60f6abf0c484d5cd563a8ee6bbd954e3357a622f69e0cd5f8ebaacaeb1dec3e3ea15707a2949e50af80f5c
7
- data.tar.gz: 0830d41fafaf536beaeb8d066910a4712d5ae387677955ae26eabd3190b4fb6344fbdeb21493d8e47436a8cba5086e65d7fed3c3be2b7a380e962c306d448f80
6
+ metadata.gz: 15d42705f83d0a63f511b1dfc084602ecb048c671cf85b2f67168c179d020e1a21c46f97bce3613a94f10e6c7af954bcec1fed099522e0924fb2280d0fa74d7e
7
+ data.tar.gz: 0f8bcbf39bff06546ec529d9dd2bc84c6b858911a2f9586833de706727261e650ebc22fca2d063c2637ffa0d3946689ecb28c471b93dbdc990cf5f9fcb8146f7
@@ -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
- $selector = (element.selector % arguments).strip_quotes.strip
17
+ $global_selector = (element.self_selector % arguments).strip_quotes.strip
18
18
  else
19
- $selector = (element.selector % '').strip_quotes.strip
19
+ $global_selector = (element.self_selector % '').strip_quotes.strip
20
20
  end
21
21
  element
22
22
  end
@@ -1,16 +1,15 @@
1
1
  class PageObject
2
2
  include Capybara::DSL
3
3
 
4
- def method_missing(mtd_name, *args)
5
- page_element = page.find(self.current_selector)
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 [](index)
10
- all()[index]
8
+ def f()
9
+ self.find
11
10
  end
12
11
 
13
- def all()
14
- page.find_all(self.current_selector)
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
@@ -1,19 +1,19 @@
1
1
  class PageObject
2
- attr_accessor :name,:parent,:selector,:intend
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.selector % arguments).strip_quotes.strip
9
+ child_selector = (child.self_selector % arguments).strip_quotes.strip
10
10
  else
11
- child_selector = (child.selector % '').strip_quotes.strip
11
+ child_selector = (child.self_selector % '').strip_quotes.strip
12
12
  end
13
13
  if child_selector.start_with? "&"
14
- $selector += child_selector.gsub(/^&/, "")
14
+ $global_selector += child_selector.gsub(/^&/, "")
15
15
  else
16
- $selector += " " + child_selector
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
- selector = raw_row.slice(raw_row.index(':')+1..-1)
25
+ self_selector = raw_row.slice(raw_row.index(':')+1..-1)
26
26
  intend = raw_row.lspace
27
- PageObject.new(name,selector,intend)
27
+ PageObject.new(name,self_selector,intend)
28
28
  end
29
29
 
30
- def current_selector
31
- $selector.strip
30
+ def selector
31
+ $global_selector.strip
32
32
  end
33
33
 
34
- def initialize (name,selector,intend)
34
+ def initialize (name,self_selector,intend)
35
35
  @name = name
36
- @selector = selector
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
@@ -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).twice
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(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
- 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
@@ -3,5 +3,10 @@ Bundler.setup
3
3
 
4
4
  require 'pageify'
5
5
 
6
+ require 'simplecov'
7
+ SimpleCov.start
8
+ SimpleCov.minimum_coverage 100
9
+ SimpleCov.formatter = SimpleCov::Formatter::HTMLFormatter
10
+
6
11
  RSpec.configure do |config|
7
12
  end
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.0
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
@@ -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