capybara-pompom 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5b892e92e2d72e313c5b27b00a3473362441ef7d
4
+ data.tar.gz: 01a58659817db60ef5b3a858497ed2412ba26a38
5
+ SHA512:
6
+ metadata.gz: 14ae30da091a3c5d08e16af7c655446dd90d56d7706195bd4b3562f340765d25788ea131b11d8f880c097d69251a5403313f3638380d73e7f91033f67a5a245e
7
+ data.tar.gz: 75a6ffb99ab6c978c13a4a83d9f23063edaf1c8c83f925ad392b807ed7bda9a3349f6458e9da442963139c00e8e0238b7a23d6dd27d135b54164c26e995d46ac
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle
2
+ /.yardoc
3
+
4
+ /coverage
5
+ /doc
6
+ /Gemfile.lock
7
+ /pkg
8
+ /spec/reports
9
+ /tmp
10
+ /_yardoc
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.0
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in capybara-pompom.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Baylor Rae'
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,73 @@
1
+ # Capybara::PomPom
2
+
3
+ The goal of this gem is to create a DSL for the [Page Object
4
+ Model][page_object_model].
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'capybara-pompom'
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install capybara-pompom
21
+
22
+ ## Usage
23
+
24
+ **Given:** we have the following page defined.
25
+
26
+ ```ruby
27
+ class LoginPage < Capybara::PomPom::Page
28
+
29
+ # uses capybara's find_field(locator)
30
+ field :username, "Username"
31
+ field :password, "Password"
32
+
33
+ # uses capybara's find_button(locator)
34
+ button :login_button, "Log In"
35
+
36
+ # this page acts on the '/login' url
37
+ def initialize
38
+ visit '/login'
39
+ end
40
+
41
+ # Actions
42
+ # login as a user
43
+ def login_as(login, pass)
44
+ username.set(login)
45
+ password.set(password)
46
+ login_button.click
47
+ end
48
+
49
+ end
50
+ ```
51
+
52
+ **Then:** it can be used like this.
53
+
54
+ ```ruby
55
+ # login steps
56
+ LoginPage.login_as('bob', 'password123')
57
+ ```
58
+
59
+ ## Development
60
+
61
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
62
+
63
+ 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` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
64
+
65
+ ## Contributing
66
+
67
+ 1. Fork it ( https://github.com/[my-github-username]/capybara-pompom/fork )
68
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
69
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
70
+ 4. Push to the branch (`git push origin my-new-feature`)
71
+ 5. Create a new Pull Request
72
+
73
+ [page_object_model]: https://code.google.com/p/selenium/wiki/PageObjects
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "capybara/pompom"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'capybara/pompom/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "capybara-pompom"
8
+ spec.version = Capybara::PomPom::VERSION
9
+ spec.authors = ["Baylor Rae'"]
10
+ spec.email = ["baylor@fastmail.com"]
11
+
12
+ spec.summary = %q{A Capybara inspired DSL for page object models.}
13
+ spec.description = %q{A Capybara inspired DSL for page object models.}
14
+ spec.homepage = "https://github.com/baylorrae/capybara-pompom"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_dependency "capybara", "~> 2.5"
23
+ spec.add_dependency "activesupport", "~> 4.2"
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.9"
26
+ spec.add_development_dependency "rake", "~> 10.0"
27
+
28
+ spec.add_development_dependency "rspec", "~> 3.3"
29
+ spec.add_development_dependency "cucumber", "~> 2.0"
30
+ spec.add_development_dependency "selenium-webdriver", "~> 2.46"
31
+ end
data/cucumber.yml ADDED
@@ -0,0 +1,8 @@
1
+ <%
2
+ rerun = File.file?('rerun.txt') ? IO.read('rerun.txt') : ""
3
+ rerun_opts = rerun.to_s.strip.empty? ? "--format #{ENV['CUCUMBER_FORMAT'] || 'progress'} features" : "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} #{rerun}"
4
+ std_opts = "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} --strict --tags ~@wip"
5
+ %>
6
+ default: <%= std_opts %> features
7
+ wip: --tags @wip:3 --wip features
8
+ rerun: <%= rerun_opts %> --format rerun --out rerun.txt --strict --tags ~@wip
@@ -0,0 +1,31 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <title>Form Page</title>
5
+
6
+ </head>
7
+ <body>
8
+
9
+ <div class="container">
10
+ <h1>Form Page</h1>
11
+
12
+ <form method="post" action="./form.html">
13
+ <div>
14
+ <label for="username">Username</label>
15
+ <input type="text" id="username" name="username" />
16
+ </div>
17
+
18
+ <div>
19
+ <label for="password">Password</label>
20
+ <input type="password" id="password" name="password" />
21
+ </div>
22
+
23
+ <div>
24
+ <input type="submit" value="Log In" />
25
+ <input type="reset" value="Reset" />
26
+ </div>
27
+ </form>
28
+ </div>
29
+
30
+ </body>
31
+ </html>
@@ -0,0 +1,21 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <title>Links Page</title>
5
+
6
+ </head>
7
+ <body>
8
+
9
+ <div class="container">
10
+ <h1>Links Page</h1>
11
+
12
+ <ul>
13
+ <li>
14
+ <a href="./form.html">View Form</a>
15
+ </li>
16
+ </ul>
17
+ </div>
18
+
19
+ </body>
20
+ </html>
21
+
@@ -0,0 +1,11 @@
1
+ require "capybara"
2
+ require "capybara/pompom/version"
3
+ require "active_support/core_ext/class/attribute"
4
+
5
+ module Capybara
6
+ module PomPom
7
+ autoload :Page, "capybara/pompom/page"
8
+ autoload :Finder, "capybara/pompom/finder"
9
+ autoload :ElementFinder, "capybara/pompom/element_finder"
10
+ end
11
+ end
@@ -0,0 +1,35 @@
1
+ module Capybara::PomPom
2
+ # == Capybara::PomPom::ElementFinder
3
+ #
4
+ # ElementFinder is used as a lambda to find elements when invoked by the Page
5
+ # instance rather than when defined.
6
+ class ElementFinder
7
+ include Capybara::DSL
8
+
9
+ attr_reader :type, :locator, :wrapper
10
+
11
+ # Initializes a new ElementFinder
12
+ #
13
+ # === Parameters
14
+ # - +type+: the capybara finder. E.g. +find_css+, +find_link+, etc...
15
+ # - +locator+: the locator used by capybara to find element.
16
+ # - +wrapper+ (optional): an instance to wrap the found element in.
17
+ def initialize(type, locator, wrapper = nil)
18
+ @type = type
19
+ @locator = locator
20
+ @wrapper = wrapper
21
+ end
22
+
23
+ # Returns the Capybara::Element or +wrapper+ if defined.
24
+ def get
25
+ element = send(type, locator)
26
+
27
+ unless wrapper.nil?
28
+ element = wrapper.new(element)
29
+ end
30
+
31
+ element
32
+ end
33
+
34
+ end
35
+ end
@@ -0,0 +1,61 @@
1
+ module Capybara::PomPom
2
+ # == Capybara::PomPom::Finder
3
+ #
4
+ # Adds helper methods to Page for accessing Capybara elements in an instance.
5
+ #
6
+ # class CustomPage
7
+ # include Capybara::PomPom::Finder
8
+ #
9
+ # link :documentation_link, "View Documentation"
10
+ #
11
+ # def view_docs
12
+ # documentation_link.click
13
+ # end
14
+ # end
15
+ module Finder
16
+
17
+ def self.included(mod) # :nodoc:
18
+ mod.class_attribute :finders
19
+ mod.finders = {}
20
+
21
+ # Provides access to finders defined at the class level.
22
+ def method_missing(name, *args)
23
+ if self.finders.has_key?(name)
24
+ return self.finders[name].get
25
+ end
26
+
27
+ super
28
+ end
29
+
30
+ mod.extend Finder
31
+ end
32
+
33
+ # Finds a link through +find_link+
34
+ #
35
+ # link :login_link, "Log In"
36
+ #
37
+ # Returns a +Capybara::Node::Element+
38
+ def link(name, locator)
39
+ self.finders[name] = ElementFinder.new(:find_link, locator)
40
+ end
41
+
42
+ # Finds a field through +find_field+
43
+ #
44
+ # field :username, "user[username]"
45
+ #
46
+ # Returns a +Capybara::Node::Element+
47
+ def field(name, locator)
48
+ self.finders[name] = ElementFinder.new(:find_field, locator)
49
+ end
50
+
51
+ # Finds a button through +find_button+
52
+ #
53
+ # button :login_button, "Log In"
54
+ #
55
+ # Returns a +Capybara::Node::Element+
56
+ def button(name, locator)
57
+ self.finders[name] = ElementFinder.new(:find_button, locator)
58
+ end
59
+
60
+ end
61
+ end
@@ -0,0 +1,26 @@
1
+ module Capybara::PomPom
2
+ # == Capybara::PomPom::Pag
3
+ #
4
+ # class LoginPage < Capybara::PomPom::Page
5
+ # field :username_field, "Username"
6
+ # field :password_field, "user[password]"
7
+ # button :login_button, "Log In"
8
+ #
9
+ # def login_as(username, password)
10
+ # username_field.set(username)
11
+ # password_field.set(password)
12
+ # login_button.click
13
+ # end
14
+ # end
15
+ class Page
16
+ include Capybara::DSL
17
+ include Finder
18
+
19
+ def self.method_missing(name, *args) # :nodoc:
20
+ page = new
21
+ page.send(name, *args)
22
+ page
23
+ end
24
+
25
+ end
26
+ end
@@ -0,0 +1,5 @@
1
+ module Capybara
2
+ module PomPom
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,161 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capybara-pompom
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Baylor Rae'
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-08-31 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: capybara
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.5'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: activesupport
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '4.2'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '4.2'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.9'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.9'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.3'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.3'
83
+ - !ruby/object:Gem::Dependency
84
+ name: cucumber
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '2.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '2.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: selenium-webdriver
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '2.46'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '2.46'
111
+ description: A Capybara inspired DSL for page object models.
112
+ email:
113
+ - baylor@fastmail.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".gitignore"
119
+ - ".rspec"
120
+ - ".travis.yml"
121
+ - Gemfile
122
+ - LICENSE.txt
123
+ - README.md
124
+ - Rakefile
125
+ - bin/console
126
+ - bin/setup
127
+ - capybara-pompom.gemspec
128
+ - cucumber.yml
129
+ - fixtures/html/form.html
130
+ - fixtures/html/links.html
131
+ - lib/capybara/pompom.rb
132
+ - lib/capybara/pompom/element_finder.rb
133
+ - lib/capybara/pompom/finder.rb
134
+ - lib/capybara/pompom/page.rb
135
+ - lib/capybara/pompom/version.rb
136
+ homepage: https://github.com/baylorrae/capybara-pompom
137
+ licenses:
138
+ - MIT
139
+ metadata: {}
140
+ post_install_message:
141
+ rdoc_options: []
142
+ require_paths:
143
+ - lib
144
+ required_ruby_version: !ruby/object:Gem::Requirement
145
+ requirements:
146
+ - - ">="
147
+ - !ruby/object:Gem::Version
148
+ version: '0'
149
+ required_rubygems_version: !ruby/object:Gem::Requirement
150
+ requirements:
151
+ - - ">="
152
+ - !ruby/object:Gem::Version
153
+ version: '0'
154
+ requirements: []
155
+ rubyforge_project:
156
+ rubygems_version: 2.2.2
157
+ signing_key:
158
+ specification_version: 4
159
+ summary: A Capybara inspired DSL for page object models.
160
+ test_files: []
161
+ has_rdoc: