edsl-pageobject 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +13 -0
- data/.rspec +3 -0
- data/.rubocop.yml +27 -0
- data/.travis.yml +7 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +109 -0
- data/Rakefile +6 -0
- data/bin/console +22 -0
- data/bin/setup +8 -0
- data/edsl-pageobject.gemspec +37 -0
- data/examples/google_search +45 -0
- data/lib/edsl/page_object/page.rb +57 -0
- data/lib/edsl/page_object/population.rb +70 -0
- data/lib/edsl/page_object/section.rb +45 -0
- data/lib/edsl/page_object/version.rb +5 -0
- data/lib/edsl/page_object/visitation.rb +109 -0
- data/lib/edsl/page_object.rb +7 -0
- metadata +191 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 00c1308f4b87e989cc86ca1f6539cbd8621db51f7f082386730975d2037e5538
|
4
|
+
data.tar.gz: 52e3124320fdb916fa4c410f8685f00447c3d6a3ae18ed81062aa077f40641cc
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 95c8755cb152df6b160f1dcb7943af7bca0288659a1e2bddccb68e5dd5685a42b61c295245e4a916b38513749d05c0e6f7d7a311c3e847a01393dc7ede666910
|
7
|
+
data.tar.gz: 125318710f26cfae63aab3850c98f15c155e9fa26fd6c8cbde37e031186a56785de5b3b80a49ed1081a5938d05516b0edda83af008f99b5fee215a9c7834ec55
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# Offense count: 1
|
2
|
+
Lint/Debugger:
|
3
|
+
Exclude:
|
4
|
+
- 'bin/console'
|
5
|
+
|
6
|
+
|
7
|
+
Style/FrozenStringLiteralComment:
|
8
|
+
Exclude:
|
9
|
+
- 'Gemfile'
|
10
|
+
- 'Rakefile'
|
11
|
+
|
12
|
+
Metrics/LineLength:
|
13
|
+
Max: 140
|
14
|
+
IgnoredPatterns: ['(\A|\s)#','Nenv\.']
|
15
|
+
|
16
|
+
Metrics/PerceivedComplexity:
|
17
|
+
Max: 8
|
18
|
+
|
19
|
+
Layout/FirstParameterIndentation:
|
20
|
+
Enabled: false
|
21
|
+
|
22
|
+
# Robocop misses when we have an out variable so don't let it 'fix' things.
|
23
|
+
Lint/UnusedMethodArgument:
|
24
|
+
AutoCorrect: false
|
25
|
+
|
26
|
+
Metrics/MethodLength:
|
27
|
+
Max: 25
|
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at donavan.stanley@gmail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 Donavan Stanley
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
# EDSL-pageobject
|
2
|
+
|
3
|
+
This gem implements the page object pattern using [EDSL](https://github.com/donavan/edsl). It provides a familiar syntax while allowing us to take advantage of the flexibility of EDSL.
|
4
|
+
|
5
|
+
If you're familiar with the PageObject gem, this gem has a mostly compatible syntax. While not a drop-in replacement, refactoring PageObject based code is fairly simple.
|
6
|
+
|
7
|
+
* Pages and Sections are classes, not modules. Instead of including PageObject, you would inherit from Page or Section.
|
8
|
+
* Instead of using PageFactory to provide on_page, use EDSL::PageObject::Visitation
|
9
|
+
|
10
|
+
This is still very much a work in progress.
|
11
|
+
|
12
|
+
## Installation
|
13
|
+
|
14
|
+
Add this line to your application's Gemfile:
|
15
|
+
|
16
|
+
```ruby
|
17
|
+
gem 'edsl-pageobject'
|
18
|
+
```
|
19
|
+
|
20
|
+
And then execute:
|
21
|
+
|
22
|
+
$ bundle
|
23
|
+
|
24
|
+
Or install it yourself as:
|
25
|
+
|
26
|
+
$ gem install edsl-pageobject
|
27
|
+
|
28
|
+
## Usage
|
29
|
+
Here's some code from the google_search example.
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
class GoogleSearchPage < EDSL::PageObject::Page
|
33
|
+
page_url 'https://www.google.com'
|
34
|
+
|
35
|
+
TEST_HOOKS = CptHook.define_hooks do
|
36
|
+
after(:set).call(:search)
|
37
|
+
end
|
38
|
+
text_field(:query, name: 'q', hooks: TEST_HOOKS)
|
39
|
+
button(:search, name: 'btnK')
|
40
|
+
end
|
41
|
+
```
|
42
|
+
|
43
|
+
Here we define a page class to represent the landing page for google search. Aside from the hooks, this looks like pretty much any ole page object. Adding a :hooks key to the options hash in the accessor will cause EDSL to wrap our element in a CptHook::Hookable. See the EDSL docs for more info.
|
44
|
+
|
45
|
+
|
46
|
+
```ruby
|
47
|
+
class AppBar < EDSL::PageObject::Section
|
48
|
+
div(:results_stats, id: 'resultStats')
|
49
|
+
end
|
50
|
+
|
51
|
+
class SearchResult < EDSL::PageObject::Section
|
52
|
+
h3(:title, index: 0)
|
53
|
+
link(:result_link, index: 0, default_method: :href)
|
54
|
+
end
|
55
|
+
```
|
56
|
+
|
57
|
+
Here we define a couple classes to represent subsets of the page. Normally calling `result_link` would click the link, but for our pruposes we need the href of the link. By providing `:href` for `:default_method` key EDSL will return the href instead of clicking the link when we call `result_link`.
|
58
|
+
|
59
|
+
Sections in EDSL-pageobject maintain a hierarchical structure and can access their parent via the `parent_container` property. They also have access to the browser via a `browser` property.
|
60
|
+
|
61
|
+
```ruby
|
62
|
+
class GoogleResultsPage < GoogleSearchPage
|
63
|
+
section(:app_bar, AppBar, id: 'appbar')
|
64
|
+
sections(:search_results, SearchResult, id: 'search',
|
65
|
+
item: { how: :divs, class: 'g' })
|
66
|
+
end
|
67
|
+
```
|
68
|
+
|
69
|
+
Now we define a Google results page, using the sections from above. `app-bar` is a single section, while `search_results` is a collection of repeating sections.
|
70
|
+
|
71
|
+
When declaring a collection of sections you tell EDSL how to find the container with the repeating elements as well as how to find the items within it. In the example above we're saying "for every div with a class of 'g' within the div with the id of 'search' return them as a collection of `SearchResult` objects.
|
72
|
+
|
73
|
+
```ruby
|
74
|
+
module GoogleDemo
|
75
|
+
extend EDSL::PageObject::Visitation
|
76
|
+
|
77
|
+
query = ARGV[0] || 'ruby'
|
78
|
+
|
79
|
+
@browser = Watir::Browser.new :chrome, headless: true
|
80
|
+
visit(GoogleSearchPage).populate_with( query: query)
|
81
|
+
|
82
|
+
on(GoogleResultsPage) do |page|
|
83
|
+
puts "There are #{page.app_bar.results_stats.strip} for #{query}"
|
84
|
+
|
85
|
+
result = page.search_results.first
|
86
|
+
puts "The first result is titled \"#{result.title}\" and points to #{result.result_link}"
|
87
|
+
end
|
88
|
+
end
|
89
|
+
```
|
90
|
+
This is pretty much bog standard PageObject code
|
91
|
+
|
92
|
+
|
93
|
+
## Development
|
94
|
+
|
95
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
96
|
+
|
97
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
98
|
+
|
99
|
+
## Contributing
|
100
|
+
|
101
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/edsl. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
102
|
+
|
103
|
+
## License
|
104
|
+
|
105
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
106
|
+
|
107
|
+
## Code of Conduct
|
108
|
+
|
109
|
+
Everyone interacting in the Edsl project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/edsl/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'edsl'
|
5
|
+
|
6
|
+
# Simple test class
|
7
|
+
class GoogleSearchPage < EDSL::ElementContainer
|
8
|
+
TEST_HOOKS = CptHook.define_hooks do
|
9
|
+
after(:set).call(:search)
|
10
|
+
end
|
11
|
+
text_field(:query, name: 'q', hooks: TEST_HOOKS)
|
12
|
+
button(:search, name: 'btnK')
|
13
|
+
end
|
14
|
+
|
15
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
16
|
+
# with your gem easier. You can also use a different console, if you like.
|
17
|
+
browser = Watir::Browser.new :chrome
|
18
|
+
browser.goto 'https://www.google.com'
|
19
|
+
w = GoogleSearchPage.new(browser)
|
20
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
21
|
+
require 'pry'
|
22
|
+
Pry.start
|
data/bin/setup
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
lib = File.expand_path('lib', __dir__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'edsl/page_object/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'edsl-pageobject'
|
7
|
+
spec.version = EDSL::PageObject::VERSION
|
8
|
+
spec.authors = ['Donavan Stanley']
|
9
|
+
spec.email = ['donavan.stanley@gmail.com']
|
10
|
+
|
11
|
+
spec.summary = 'Page object pattern using EDSL'
|
12
|
+
spec.homepage = 'https://github.com/donavan/edsl-pageobject'
|
13
|
+
spec.license = 'MIT'
|
14
|
+
|
15
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
16
|
+
spec.metadata['source_code_uri'] = spec.homepage
|
17
|
+
|
18
|
+
# Specify which files should be added to the gem when it is released.
|
19
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
20
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
21
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
22
|
+
end
|
23
|
+
spec.bindir = 'exe'
|
24
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
25
|
+
spec.require_paths = ['lib']
|
26
|
+
|
27
|
+
spec.add_development_dependency 'bundler', '~> 1.16'
|
28
|
+
spec.add_development_dependency 'pry'
|
29
|
+
spec.add_development_dependency 'pry-byebug'
|
30
|
+
spec.add_development_dependency 'pry-stack_explorer'
|
31
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
32
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
33
|
+
spec.add_development_dependency 'rubocop'
|
34
|
+
spec.add_development_dependency 'simplecov'
|
35
|
+
|
36
|
+
spec.add_runtime_dependency 'edsl'
|
37
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'pry'
|
5
|
+
require 'edsl/page_object'
|
6
|
+
|
7
|
+
# Simple class to represent the initial search screen
|
8
|
+
class GoogleSearchPage < EDSL::PageObject::Page
|
9
|
+
page_url 'https://www.google.com'
|
10
|
+
|
11
|
+
TEST_HOOKS = CptHook.define_hooks do
|
12
|
+
after(:set).call(:search)
|
13
|
+
end
|
14
|
+
text_field(:query, name: 'q', hooks: TEST_HOOKS)
|
15
|
+
button(:search, name: 'btnK')
|
16
|
+
end
|
17
|
+
|
18
|
+
class AppBar < EDSL::PageObject::Section
|
19
|
+
div(:results_stats, id: 'resultStats')
|
20
|
+
end
|
21
|
+
|
22
|
+
class SearchResult < EDSL::PageObject::Section
|
23
|
+
h3(:title, index: 0)
|
24
|
+
link(:result_link, index: 0, default_method: :href)
|
25
|
+
end
|
26
|
+
|
27
|
+
class GoogleResultsPage < GoogleSearchPage
|
28
|
+
section(:app_bar, AppBar, id: 'appbar')
|
29
|
+
sections(:search_results, SearchResult, id: 'search', item: { how: :divs, class: 'g' })
|
30
|
+
end
|
31
|
+
|
32
|
+
module GoogleDemo
|
33
|
+
extend EDSL::PageObject::Visitation
|
34
|
+
|
35
|
+
query = ARGV[0] || 'ruby'
|
36
|
+
|
37
|
+
@browser = Watir::Browser.new :chrome, headless: true
|
38
|
+
visit(GoogleSearchPage).populate_with( query: query)
|
39
|
+
|
40
|
+
on(GoogleResultsPage) do |page|
|
41
|
+
puts "There are #{page.app_bar.results_stats.strip} for #{query}"
|
42
|
+
result = page.search_results.first
|
43
|
+
puts "The first result is titled \"#{result.title}\" and points to #{result.result_link}"
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'erb'
|
2
|
+
module EDSL
|
3
|
+
module PageObject
|
4
|
+
DEFAULT_PAGE_READY_LIMIT = 30
|
5
|
+
|
6
|
+
# This class represents an entire page within the browser.
|
7
|
+
#
|
8
|
+
# Using this base class is not a requirement, however code in some modules may assume that
|
9
|
+
# methods in this class are available when they're dealing with pages
|
10
|
+
#
|
11
|
+
# This allows your object to serve as a proxy for the browser and mirror it's API.
|
12
|
+
#
|
13
|
+
class Page < ::EDSL::ElementContainer
|
14
|
+
include EDSL::PageObject::Population
|
15
|
+
extend EDSL::PageObject::Visitable
|
16
|
+
|
17
|
+
attr_accessor :page_ready_limit
|
18
|
+
alias_method :browser, :root_element
|
19
|
+
|
20
|
+
# Create a new page.
|
21
|
+
def initialize(web_browser, visit = false)
|
22
|
+
super(web_browser, nil)
|
23
|
+
@page_ready_limit = DEFAULT_PAGE_READY_LIMIT
|
24
|
+
goto if visit
|
25
|
+
end
|
26
|
+
|
27
|
+
# An always safe to call ready function. Subclasses should implement the _ready? method
|
28
|
+
# to provide an actual implementation.
|
29
|
+
def ready?
|
30
|
+
return _ready?
|
31
|
+
rescue
|
32
|
+
return false
|
33
|
+
end
|
34
|
+
|
35
|
+
# Block until the page is ready then yield / return self.
|
36
|
+
#
|
37
|
+
# If a block is given the page will be yielded to it.
|
38
|
+
#
|
39
|
+
def when_ready(limit = nil, &block)
|
40
|
+
begin
|
41
|
+
Watir::Wait.until(limit || page_ready_limit) { _ready? }
|
42
|
+
rescue Timeout::Error
|
43
|
+
raise Timeout::Error, "Timeout limit #{limit} reached waiting for #{self.class} to be ready"
|
44
|
+
end
|
45
|
+
yield self if block_given?
|
46
|
+
self
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
# Subclasses should override this with something that checks the state of the page.
|
52
|
+
def _ready?
|
53
|
+
true
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'facets/string'
|
2
|
+
|
3
|
+
module EDSL
|
4
|
+
module PageObject
|
5
|
+
# This module serves as a mixin for element container to support populating their
|
6
|
+
# fields via a hash.
|
7
|
+
module Population
|
8
|
+
|
9
|
+
# This method allows you to specify a function to be used to fetch fixture data,
|
10
|
+
# given a key. The value passed should either be a proc, or a method name for send.
|
11
|
+
#
|
12
|
+
# Examples: EDSL::Population.fixture_fetch= :data_for
|
13
|
+
#
|
14
|
+
# EDSL::Population.fixture_fetch= lambda.new { |key| data_for key }
|
15
|
+
#
|
16
|
+
# Both of these examples would call data_for from DataMagic
|
17
|
+
#
|
18
|
+
# @param proc_or_name [Proc, String, Symbol] A Proc to call or the name of a method to send.
|
19
|
+
def self.fixture_fetcher=(proc_or_name)
|
20
|
+
@@fixture_fetcher = proc_or_name
|
21
|
+
end
|
22
|
+
|
23
|
+
# Returns the currently defined fixture fetch function or a lambda that returns nil
|
24
|
+
def self.fixture_fetcher
|
25
|
+
@@fixture_fetcher = lambda.new { |_key| nil }
|
26
|
+
end
|
27
|
+
|
28
|
+
# Fetch a value from our fixtures using a key.
|
29
|
+
#
|
30
|
+
# @param key [String, Symbol] What to fetch
|
31
|
+
def fixture_fetch(key)
|
32
|
+
ff = fixture_fetcher
|
33
|
+
return ff.call(key) if ff.is_a?(Proc)
|
34
|
+
send(ff, key)
|
35
|
+
end
|
36
|
+
|
37
|
+
# This method will populate the various elements within a container, using a hash.
|
38
|
+
#
|
39
|
+
# If the hash contains a key that matches the #populate_key of the container, the
|
40
|
+
# value contained there will be used instead of the passed hash. Otherwise, the
|
41
|
+
# data will be used directly.
|
42
|
+
#
|
43
|
+
# For each key in the hash, this method will call send("#{key}=") passing it the value
|
44
|
+
# from the hash (if we respond to that message).
|
45
|
+
#
|
46
|
+
# This function makes no attempt to determine the type of element being set,
|
47
|
+
# it assumes that what ever you put in the value can be consumed by the assignment function.
|
48
|
+
#
|
49
|
+
# Values are populated in the order they appear in the hash.
|
50
|
+
#
|
51
|
+
#
|
52
|
+
# @param data [Hash] the data to use to populate this container. The key
|
53
|
+
# can be either a string or a symbol.
|
54
|
+
def populate_with(data)
|
55
|
+
data = data.fetch(populate_key, data)
|
56
|
+
data = data.fetch(populate_key.to_sym, data)
|
57
|
+
data.each do |k, v|
|
58
|
+
send("#{k}=", v) if respond_to?("#{k}=")
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
# This method will provide a value that can be used as a key for selecting data out of a hash
|
63
|
+
# for a specific container. It uses the class name of the object and converts it into snake case
|
64
|
+
# so LoginPage would have a populate key of login_page.
|
65
|
+
def populate_key
|
66
|
+
self.class.to_s.snakecase
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module EDSL
|
2
|
+
module PageObject
|
3
|
+
# This class represents a section of the dom contained within a root element.
|
4
|
+
#
|
5
|
+
# Using this base class is not a requirement, however code in some modules may assume that
|
6
|
+
# methods in this class are available when they're dealing with sections
|
7
|
+
#
|
8
|
+
# This allows your object to serve as a proxy for the element and mirror it's API.
|
9
|
+
#
|
10
|
+
class Section < ElementContainer
|
11
|
+
include EDSL::PageObject::Population
|
12
|
+
# Create a new section
|
13
|
+
def initialize(element, parent)
|
14
|
+
super(element, parent)
|
15
|
+
end
|
16
|
+
|
17
|
+
def browser
|
18
|
+
@browser ||= _find_browser_via(parent_container)
|
19
|
+
end
|
20
|
+
|
21
|
+
def _find_browser_via(container)
|
22
|
+
raise ScriptError, "Could not locate a browser in #{self.class}." if container.nil?
|
23
|
+
return container.browser if container.respond_to?(:browser)
|
24
|
+
_find_browser_via(container.parent_container)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
EDSL.extend_dsl {
|
29
|
+
def section(name, section_class, opts)
|
30
|
+
element(name, { how: :div, assign_method: :populate_with,
|
31
|
+
wrapper_fn: lambda { |element, _container| section_class.new(element, self) } }.merge(opts))
|
32
|
+
end
|
33
|
+
|
34
|
+
alias_method :page_section, :section
|
35
|
+
|
36
|
+
def sections(name, section_class, opts)
|
37
|
+
i_sel = opts.delete(:item)
|
38
|
+
item_how = i_sel.delete(:how)
|
39
|
+
default_method = lambda { |_name, container| container.send(item_how, i_sel).map { |i| section_class.new(i, self) } }
|
40
|
+
element(name, { how: :div,
|
41
|
+
default_method: default_method }.merge(opts))
|
42
|
+
end
|
43
|
+
}
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,109 @@
|
|
1
|
+
module EDSL
|
2
|
+
module PageObject
|
3
|
+
module Visitable
|
4
|
+
#
|
5
|
+
# Set some values that can be used within the class. This is
|
6
|
+
# typically used to provide values that help build dynamic urls in
|
7
|
+
# the page_url method
|
8
|
+
#
|
9
|
+
# @param [Hash] the value to set the params
|
10
|
+
#
|
11
|
+
def params=(the_params)
|
12
|
+
@params = the_params
|
13
|
+
end
|
14
|
+
|
15
|
+
#
|
16
|
+
# Return the params that exist on this page class
|
17
|
+
#
|
18
|
+
def params
|
19
|
+
@params ||= {}
|
20
|
+
end
|
21
|
+
|
22
|
+
def page_url(url)
|
23
|
+
define_method("goto") do
|
24
|
+
browser.goto page_url_value
|
25
|
+
end
|
26
|
+
|
27
|
+
define_method('page_url_value') do
|
28
|
+
lookup = url.kind_of?(Symbol) ? self.send(url) : url
|
29
|
+
erb = ::ERB.new(%Q{#{lookup}})
|
30
|
+
merged_params = self.class.instance_variable_get("@merged_params")
|
31
|
+
params = merged_params ? merged_params : self.class.params
|
32
|
+
binding.pry
|
33
|
+
erb.result(binding)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# Most of this is a semi-direct copy from PageObject::PageFactory
|
39
|
+
module Visitation
|
40
|
+
#
|
41
|
+
# Create and navigate to a page object. The navigation will only work if the
|
42
|
+
# 'page_url' method was call on the page object.
|
43
|
+
#
|
44
|
+
# @param page_class [Page, String] the page class to create
|
45
|
+
#
|
46
|
+
# @param params[Hash] values that is passed through to page class available in
|
47
|
+
# the @params instance variable.
|
48
|
+
#
|
49
|
+
# @return [Page] the newly created page
|
50
|
+
#
|
51
|
+
def visit_page(page_class, params={:using_params => {}}, &block)
|
52
|
+
on_page page_class, params, true, &block
|
53
|
+
end
|
54
|
+
|
55
|
+
# Support 'visit' for readability of usage
|
56
|
+
alias_method :visit, :visit_page
|
57
|
+
|
58
|
+
#
|
59
|
+
# Create a page object.
|
60
|
+
#
|
61
|
+
# @param page_class [Page, String] the page class to create
|
62
|
+
#
|
63
|
+
# @param params[Hash] values that is passed through to page class available in
|
64
|
+
# the @params instance variable.
|
65
|
+
# @param visit[Boolean] a boolean indicating if the page should be visited? default is false.
|
66
|
+
#
|
67
|
+
# @return [Page] the newly created page
|
68
|
+
#
|
69
|
+
def on_page(page_class, params={:using_params => {}}, visit=false, &block)
|
70
|
+
page_class = class_from_string(page_class) if page_class.is_a? String
|
71
|
+
return super(page_class, params, visit, &block) unless page_class.ancestors.include? Page
|
72
|
+
merged = page_class.params.merge(params[:using_params])
|
73
|
+
page_class.instance_variable_set("@merged_params", merged) unless merged.empty?
|
74
|
+
@current_page = page_class.new(@browser, visit)
|
75
|
+
block.call @current_page if block
|
76
|
+
@current_page
|
77
|
+
end
|
78
|
+
|
79
|
+
# Support 'on' for readability of usage
|
80
|
+
alias_method :on, :on_page
|
81
|
+
|
82
|
+
#
|
83
|
+
# Create a page object if and only if the current page is the same page to be created
|
84
|
+
#
|
85
|
+
# @param [PageObject, String] a class that has included the PageObject module or a string containing the name of the class
|
86
|
+
# @param Hash values that is pass through to page class a
|
87
|
+
# available in the @params instance variable.
|
88
|
+
# @param [block] an optional block to be called
|
89
|
+
# @return [PageObject] the newly created page object
|
90
|
+
#
|
91
|
+
def if_page(page_class, params={:using_params => {}},&block)
|
92
|
+
page_class = class_from_string(page_class) if page_class.is_a? String
|
93
|
+
return @current_page unless @current_page.class == page_class
|
94
|
+
on_page(page_class, params, false, &block)
|
95
|
+
end
|
96
|
+
|
97
|
+
# Support 'if' for readability of usage
|
98
|
+
alias_method :if, :if_page
|
99
|
+
|
100
|
+
private
|
101
|
+
|
102
|
+
def class_from_string(str)
|
103
|
+
str.split('::').inject(Object) do |mod, class_name|
|
104
|
+
mod.const_get(class_name)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
metadata
ADDED
@@ -0,0 +1,191 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: edsl-pageobject
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Donavan Stanley
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-11-13 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.16'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.16'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: pry
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: pry-byebug
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry-stack_explorer
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '10.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '10.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '3.0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '3.0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rubocop
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: simplecov
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: edsl
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :runtime
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
description:
|
140
|
+
email:
|
141
|
+
- donavan.stanley@gmail.com
|
142
|
+
executables: []
|
143
|
+
extensions: []
|
144
|
+
extra_rdoc_files: []
|
145
|
+
files:
|
146
|
+
- ".gitignore"
|
147
|
+
- ".rspec"
|
148
|
+
- ".rubocop.yml"
|
149
|
+
- ".travis.yml"
|
150
|
+
- CODE_OF_CONDUCT.md
|
151
|
+
- Gemfile
|
152
|
+
- LICENSE.txt
|
153
|
+
- README.md
|
154
|
+
- Rakefile
|
155
|
+
- bin/console
|
156
|
+
- bin/setup
|
157
|
+
- edsl-pageobject.gemspec
|
158
|
+
- examples/google_search
|
159
|
+
- lib/edsl/page_object.rb
|
160
|
+
- lib/edsl/page_object/page.rb
|
161
|
+
- lib/edsl/page_object/population.rb
|
162
|
+
- lib/edsl/page_object/section.rb
|
163
|
+
- lib/edsl/page_object/version.rb
|
164
|
+
- lib/edsl/page_object/visitation.rb
|
165
|
+
homepage: https://github.com/donavan/edsl-pageobject
|
166
|
+
licenses:
|
167
|
+
- MIT
|
168
|
+
metadata:
|
169
|
+
homepage_uri: https://github.com/donavan/edsl-pageobject
|
170
|
+
source_code_uri: https://github.com/donavan/edsl-pageobject
|
171
|
+
post_install_message:
|
172
|
+
rdoc_options: []
|
173
|
+
require_paths:
|
174
|
+
- lib
|
175
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
176
|
+
requirements:
|
177
|
+
- - ">="
|
178
|
+
- !ruby/object:Gem::Version
|
179
|
+
version: '0'
|
180
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
181
|
+
requirements:
|
182
|
+
- - ">="
|
183
|
+
- !ruby/object:Gem::Version
|
184
|
+
version: '0'
|
185
|
+
requirements: []
|
186
|
+
rubyforge_project:
|
187
|
+
rubygems_version: 2.7.7
|
188
|
+
signing_key:
|
189
|
+
specification_version: 4
|
190
|
+
summary: Page object pattern using EDSL
|
191
|
+
test_files: []
|