capypage 0.1.0

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: 46363dd20d43fc03a8ba0e523e70cb84a5af21a3
4
+ data.tar.gz: 51b6937aa10d76cd748e81ff7b08d8c8f7746d3a
5
+ SHA512:
6
+ metadata.gz: 79af6bae101b39e3e1abe840876be9eafd12d4215b7869a49a6210614da15f51c75b4ce64a979978853519236ff95f8a50b4c23307465fd2e53b69395c8d87b1
7
+ data.tar.gz: 2e359a3a42e090a0b40b0f5a0dd6415468a380a533a5c682c0b773d851e086060ae633f826650cd1daf13a11d2746452ed89664f85695080b3112545dcf33764
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ .idea
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in capypage.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Selva
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Capypage
2
+
3
+ Page Object Model for Capybara
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'capypage'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install capypage
18
+
19
+ ## Usage
20
+
21
+ See examples
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/capypage.gemspec ADDED
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'capypage/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'capypage'
8
+ spec.version = Capypage::VERSION
9
+ spec.authors = ['Selvakumar Natesan', 'Simonroy', 'Arvind']
10
+ spec.email = %w(k.n.selvakumar@gmail.com)
11
+ spec.description = 'Page Object Model for Capybara'
12
+ spec.summary = 'Page Object Model for Capybara'
13
+ spec.homepage = 'http://github.com/TWChennai/capypage'
14
+ spec.license = 'MIT'
15
+ spec.files = `git ls-files`.split($/)
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = %w(lib)
19
+
20
+ spec.add_dependency 'capybara', '~> 2.1.0'
21
+ spec.add_dependency 'activesupport', '~> 3.0.0'
22
+
23
+ spec.add_development_dependency 'bundler', '~> 1.3'
24
+ spec.add_development_dependency 'rake'
25
+ end
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'capypage', :path => '../../'
4
+ gem 'rspec'
5
+ gem 'capybara-webkit'
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Simple example', :type => :feature do
4
+ let(:search_page) { DuckDuckGo::HomePage.new }
5
+ let(:search_results_page) { DuckDuckGo::ResultsPage.new }
6
+
7
+ it 'should show capybara results' do
8
+ search_page.load
9
+ search_page.search "Capybara"
10
+
11
+ capybara_result = search_results_page.results.find_by_text "jnicklas"
12
+ capybara_result.link[:href].should == 'https://github.com/jnicklas/capybara'
13
+ capybara_result.snippet.should have_text "Capybara helps you test web applications"
14
+ end
15
+ end
@@ -0,0 +1,28 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ Bundler.require
4
+
5
+ require 'capybara/rspec'
6
+
7
+ Capybara.default_driver = :webkit
8
+
9
+ module DuckDuckGo
10
+ class HomePage < Capypage::Page
11
+ self.url = 'https://duckduckgo.com/'
12
+
13
+ element :search_input, 'input[name=q]'
14
+ element :search_button, 'input#search_button_homepage'
15
+
16
+ def search(term)
17
+ search_input.set term
18
+ search_button.click
19
+ end
20
+ end
21
+
22
+ class ResultsPage < Capypage::Page
23
+ elements :results, '#links .results_links_deep' do |result|
24
+ result.element :link, '.links_main a'
25
+ result.element :snippet, '.snippet'
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,47 @@
1
+ require 'active_support/core_ext/module/delegation'
2
+ require 'active_support/core_ext/object/blank'
3
+
4
+ module Capypage
5
+ class Element
6
+ attr_accessor :selector, :prefix, :finder_options, :base_element
7
+
8
+ delegate :click, :set, :text, :all, :find, :[], :native, :disabled?, :selected?, :has_text?, :has_no_text?, :checked?, :has_selector?,
9
+ :to => :capybara_element
10
+
11
+ def initialize(selector, prefix = nil, options = {}, &block)
12
+ options.reverse_merge! :match => :smart
13
+ @selector = selector
14
+ @prefix = prefix
15
+ @finder_options = options
16
+ @base_element = options.delete(:base_element) || Capybara.current_session
17
+ block.call(self) if block.present?
18
+ end
19
+
20
+ def element(name, selector, options = {})
21
+ base = self
22
+ define_singleton_method(name) { Element.new(selector, prefix, options.reverse_merge!(:match => :first, :base_element => base)) }
23
+ end
24
+
25
+ def elements(name, selector, options = {}, &block)
26
+ base = self
27
+ define_singleton_method(name) { Elements.new(selector, prefix, options.reverse_merge!(:base_element => base), &block) }
28
+ end
29
+
30
+ def visible?(options = {})
31
+ options.reverse_merge! finder_options
32
+ options.reverse_merge! :wait => 2
33
+ return capybara_element(options).visible?
34
+ rescue Capybara::ElementNotFound
35
+ false
36
+ end
37
+
38
+ protected
39
+ def capybara_element(options = {})
40
+ base_element.find(element_selector, options.reverse_merge(finder_options))
41
+ end
42
+
43
+ def element_selector
44
+ [prefix, selector].compact.join(" ")
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,39 @@
1
+ module Capypage
2
+ class Elements < Element
3
+ include Enumerable
4
+ attr_accessor :child_dsl_block
5
+
6
+ delegate :each, :size, :[],
7
+ :to => :all
8
+
9
+ def initialize(selector, prefix = nil, options = {}, &block)
10
+ super(selector, prefix, options)
11
+ @child_dsl_block = block
12
+ end
13
+
14
+ def all(options = {})
15
+ base_element.has_selector? element_selector
16
+ base_element.all(element_selector, options.reverse_merge(finder_options))
17
+ end
18
+
19
+ def find(text, options = {})
20
+ capybara_element options.merge(:text => text)
21
+ end
22
+
23
+ def find_by_text(text, options = {})
24
+ Element.new(selector, prefix, finder_options.merge(options).merge(:text => text), &child_dsl_block)
25
+ end
26
+
27
+ def find_first(index = 1)
28
+ Elements.new("#{element_selector}:nth-child(-n+#{index})", prefix, finder_options)
29
+ end
30
+
31
+ def find_last(index = 1)
32
+ Elements.new("#{element_selector}:nth-last-child(-n+#{index})", prefix, finder_options)
33
+ end
34
+
35
+ def find_by_index(index)
36
+ Element.new("#{element_selector}:nth-child(#{index + 1})", prefix, finder_options, &child_dsl_block)
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,40 @@
1
+ require 'active_support/core_ext/class/attribute'
2
+ require 'active_support/core_ext/hash/reverse_merge'
3
+
4
+ module Capypage
5
+ class Page
6
+ include Capybara::DSL
7
+ class_attribute :url
8
+ attr_accessor :prefix, :finder_options
9
+
10
+ def initialize(prefix = nil, options = {})
11
+ @prefix = prefix
12
+ @finder_options = options
13
+ end
14
+
15
+ class <<self
16
+ def set_url(url)
17
+ self.url = url
18
+ end
19
+
20
+ def element(name, selector, options = {})
21
+ options.reverse_merge! :match => :first
22
+ define_method(name) { Element.new(selector, prefix, options) }
23
+ end
24
+
25
+ def elements(name, selector, options = {}, &block)
26
+ define_method(name) { Elements.new(selector, prefix, options, &block) }
27
+ end
28
+
29
+ def section(name, section, selector, options = {})
30
+ define_method name do
31
+ section.new(selector, options)
32
+ end
33
+ end
34
+ end
35
+
36
+ def load
37
+ visit self.class.url
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,5 @@
1
+ module Capypage
2
+ class Section < Page
3
+ alias_method :selector, :prefix
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ module Capypage
2
+ VERSION = '0.1.0'
3
+ end
data/lib/capypage.rb ADDED
@@ -0,0 +1,12 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ Bundler.require
4
+
5
+ require 'capybara'
6
+
7
+ require "capypage/version"
8
+
9
+ require "capypage/page"
10
+ require "capypage/element"
11
+ require "capypage/elements"
12
+ require "capypage/section"
metadata ADDED
@@ -0,0 +1,117 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capypage
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Selvakumar Natesan
8
+ - Simonroy
9
+ - Arvind
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2013-09-17 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: capybara
17
+ requirement: !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 2.1.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - ~>
27
+ - !ruby/object:Gem::Version
28
+ version: 2.1.0
29
+ - !ruby/object:Gem::Dependency
30
+ name: activesupport
31
+ requirement: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - ~>
34
+ - !ruby/object:Gem::Version
35
+ version: 3.0.0
36
+ type: :runtime
37
+ prerelease: false
38
+ version_requirements: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ~>
41
+ - !ruby/object:Gem::Version
42
+ version: 3.0.0
43
+ - !ruby/object:Gem::Dependency
44
+ name: bundler
45
+ requirement: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ~>
48
+ - !ruby/object:Gem::Version
49
+ version: '1.3'
50
+ type: :development
51
+ prerelease: false
52
+ version_requirements: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ~>
55
+ - !ruby/object:Gem::Version
56
+ version: '1.3'
57
+ - !ruby/object:Gem::Dependency
58
+ name: rake
59
+ requirement: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - '>='
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ type: :development
65
+ prerelease: false
66
+ version_requirements: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - '>='
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ description: Page Object Model for Capybara
72
+ email:
73
+ - k.n.selvakumar@gmail.com
74
+ executables: []
75
+ extensions: []
76
+ extra_rdoc_files: []
77
+ files:
78
+ - .gitignore
79
+ - Gemfile
80
+ - LICENSE.txt
81
+ - README.md
82
+ - Rakefile
83
+ - capypage.gemspec
84
+ - examples/simple/Gemfile
85
+ - examples/simple/spec/simple_spec.rb
86
+ - examples/simple/spec/spec_helper.rb
87
+ - lib/capypage.rb
88
+ - lib/capypage/element.rb
89
+ - lib/capypage/elements.rb
90
+ - lib/capypage/page.rb
91
+ - lib/capypage/section.rb
92
+ - lib/capypage/version.rb
93
+ homepage: http://github.com/TWChennai/capypage
94
+ licenses:
95
+ - MIT
96
+ metadata: {}
97
+ post_install_message:
98
+ rdoc_options: []
99
+ require_paths:
100
+ - lib
101
+ required_ruby_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - '>='
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ requirements: []
112
+ rubyforge_project:
113
+ rubygems_version: 2.0.3
114
+ signing_key:
115
+ specification_version: 4
116
+ summary: Page Object Model for Capybara
117
+ test_files: []