prickle 0.0.1 → 0.0.2
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.
- data/Gemfile.lock +20 -2
- data/README.md +33 -23
- data/lib/prickle/capybara.rb +18 -33
- data/lib/prickle/capybara/click.rb +1 -16
- data/lib/prickle/capybara/element.rb +53 -0
- data/lib/prickle/capybara/exceptions.rb +30 -7
- data/lib/prickle/capybara/find.rb +1 -26
- data/lib/prickle/capybara/match.rb +14 -12
- data/lib/prickle/version.rb +3 -0
- data/prickle.gemspec +29 -0
- data/spec/extended_wait_spec.rb +1 -0
- data/spec/finders_spec.rb +2 -1
- data/spec/spec_helper.rb +0 -3
- metadata +16 -2
data/Gemfile.lock
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
prickle (0.0.1)
|
5
|
+
capybara
|
6
|
+
|
1
7
|
GEM
|
2
8
|
remote: http://rubygems.org/
|
3
9
|
specs:
|
@@ -20,6 +26,10 @@ GEM
|
|
20
26
|
rack
|
21
27
|
rack-test (0.6.1)
|
22
28
|
rack (>= 1.0)
|
29
|
+
reek (1.2.8)
|
30
|
+
ruby2ruby (~> 1.2)
|
31
|
+
ruby_parser (~> 2.0)
|
32
|
+
sexp_processor (~> 3.0)
|
23
33
|
rspec (2.8.0)
|
24
34
|
rspec-core (~> 2.8.0)
|
25
35
|
rspec-expectations (~> 2.8.0)
|
@@ -28,12 +38,18 @@ GEM
|
|
28
38
|
rspec-expectations (2.8.0)
|
29
39
|
diff-lcs (~> 1.1.2)
|
30
40
|
rspec-mocks (2.8.0)
|
41
|
+
ruby2ruby (1.3.1)
|
42
|
+
ruby_parser (~> 2.0)
|
43
|
+
sexp_processor (~> 3.0)
|
44
|
+
ruby_parser (2.3.1)
|
45
|
+
sexp_processor (~> 3.0)
|
31
46
|
rubyzip (0.9.6.1)
|
32
47
|
selenium-webdriver (2.19.0)
|
33
48
|
childprocess (>= 0.2.5)
|
34
49
|
ffi (~> 1.0.9)
|
35
50
|
multi_json (~> 1.0.4)
|
36
51
|
rubyzip
|
52
|
+
sexp_processor (3.0.10)
|
37
53
|
sinatra (1.3.2)
|
38
54
|
rack (~> 1.3, >= 1.3.6)
|
39
55
|
rack-protection (~> 1.2)
|
@@ -47,5 +63,7 @@ PLATFORMS
|
|
47
63
|
|
48
64
|
DEPENDENCIES
|
49
65
|
capybara
|
50
|
-
|
51
|
-
|
66
|
+
prickle!
|
67
|
+
reek
|
68
|
+
rspec (~> 2.8.0)
|
69
|
+
sinatra (~> 1.3.2)
|
data/README.md
CHANGED
@@ -8,42 +8,53 @@ To install prickle execute
|
|
8
8
|
gem install prickle
|
9
9
|
```
|
10
10
|
|
11
|
-
and to configure
|
11
|
+
and to configure update your *features/support/env.rb* to include the following:
|
12
12
|
|
13
13
|
```ruby
|
14
|
-
require 'prickle/capybara'
|
14
|
+
require 'prickle/capybara' # require
|
15
|
+
|
15
16
|
|
16
17
|
World do
|
17
|
-
|
18
|
-
|
18
|
+
include Capybara::DSL
|
19
|
+
include Prickle::Capybara # include Prickle
|
19
20
|
end
|
20
21
|
```
|
21
22
|
|
23
|
+
## Waiting for elements to become visible
|
24
|
+
|
25
|
+
To enable this feature you need to set the *Prickle::Capybara.wait_time* property.
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
Prickle::Capybara.wait_time = 5
|
29
|
+
```
|
30
|
+
|
31
|
+
If you only want to extend the wait time for a particular feature, then you need to reset the wait time using *Prickle::Capybara = nil*.
|
32
|
+
|
22
33
|
## Usage
|
23
34
|
|
24
35
|
### Find elements by any html tag(s)
|
25
36
|
|
26
37
|
```ruby
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
38
|
+
element(:href => "http://google.com")
|
39
|
+
element(:name => "blue")
|
40
|
+
element(:id => "key")
|
41
|
+
element(:class => "key", :id => "button")
|
31
42
|
```
|
32
43
|
|
33
44
|
### Find elements by type and html tag(s)
|
34
45
|
|
35
46
|
```ruby
|
36
|
-
|
37
|
-
|
38
|
-
|
47
|
+
element(:link, :href => "http://google.com") # you can also use link and paragraph (instead of a and p)
|
48
|
+
element(:input, :name => "blue")
|
49
|
+
```
|
39
50
|
|
40
51
|
### Apply a search, a click or a text matcher
|
41
52
|
|
42
|
-
|
53
|
+
```ruby
|
43
54
|
|
44
|
-
element(:name => "flower")
|
45
|
-
element(:name => "flower")
|
46
|
-
element(:name => "flower")
|
55
|
+
element(:name => "flower").exists?
|
56
|
+
element(:name => "flower").click
|
57
|
+
element(:name => "flower").contains_text? "Roses"
|
47
58
|
```
|
48
59
|
|
49
60
|
## Alternative syntax
|
@@ -51,20 +62,19 @@ element(:name => "flower")*.contains_text? "Roses"*
|
|
51
62
|
### Find
|
52
63
|
|
53
64
|
```ruby
|
54
|
-
|
55
|
-
|
56
|
-
find_button_by_name "green" #find_<element_tag>_by_name "<name>"
|
65
|
+
find_by_name "green"
|
66
|
+
find_button_by_name "green" #find_<element_tag>_by_name "<name>"
|
57
67
|
```
|
58
68
|
|
59
|
-
|
69
|
+
### Click
|
60
70
|
|
61
71
|
```ruby
|
62
|
-
|
63
|
-
|
64
|
-
|
72
|
+
click_by_name "blue"
|
73
|
+
click_input_by_name "blue" #click_<element_tag>_by_name "<name>"
|
74
|
+
```
|
65
75
|
|
66
76
|
### Match text
|
67
77
|
|
68
78
|
```ruby
|
69
|
-
|
79
|
+
div_contains_text? "text" #<element_tag>_contains_text? "text"
|
70
80
|
```
|
data/lib/prickle/capybara.rb
CHANGED
@@ -1,11 +1,8 @@
|
|
1
|
-
require_relative 'capybara/
|
2
|
-
require_relative 'capybara/click'
|
3
|
-
require_relative 'capybara/match'
|
4
|
-
require_relative 'capybara/exceptions'
|
1
|
+
require_relative 'capybara/element'
|
5
2
|
|
6
3
|
module Prickle
|
7
4
|
TAGS = { :link => 'a',
|
8
|
-
|
5
|
+
:paragraph => 'p'
|
9
6
|
}
|
10
7
|
|
11
8
|
module Capybara
|
@@ -15,43 +12,31 @@ module Prickle
|
|
15
12
|
|
16
13
|
end
|
17
14
|
|
18
|
-
include Prickle::Actions::Find
|
19
|
-
include Prickle::Actions::Click
|
20
|
-
include Prickle::Actions::Match
|
21
|
-
|
22
15
|
def element type='*', identifier
|
23
|
-
|
24
|
-
@type = type
|
25
|
-
self
|
16
|
+
Element.new type, identifier
|
26
17
|
end
|
27
18
|
|
28
|
-
|
29
|
-
|
30
|
-
def xpath_for identifier
|
31
|
-
return identifier.each_pair.to_a.map do |key, value|
|
32
|
-
"@#{key}='#{value}'"
|
33
|
-
end.join ' and '
|
19
|
+
def find_by_name type='*', name
|
20
|
+
element(type, :name => name).exists?
|
34
21
|
end
|
35
22
|
|
36
|
-
def
|
37
|
-
|
38
|
-
find(:xpath, xpath).visible?
|
39
|
-
end unless Prickle::Capybara.wait_time.nil?
|
40
|
-
|
41
|
-
find(:xpath, xpath)
|
23
|
+
def click_by_name name
|
24
|
+
find_by_name(name).click
|
42
25
|
end
|
43
26
|
|
44
|
-
|
45
|
-
Prickle::TAGS[element.to_sym] || element
|
46
|
-
end
|
27
|
+
private
|
47
28
|
|
48
|
-
def
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
29
|
+
def method_missing method, *args
|
30
|
+
if method =~ /(^.*)_contains_text\?$/
|
31
|
+
element($1, :name => args.first).contains_text? args[1]
|
32
|
+
elsif method =~ /^click_(.*)_by_name$/
|
33
|
+
element($1, :name => args.first).click
|
34
|
+
elsif method =~ /^find_(.*)_by_name$/
|
35
|
+
element($1, :name => args.first).exists?
|
36
|
+
else
|
37
|
+
super
|
54
38
|
end
|
55
39
|
end
|
40
|
+
|
56
41
|
end
|
57
42
|
end
|
@@ -2,24 +2,9 @@ module Prickle
|
|
2
2
|
module Actions
|
3
3
|
module Click
|
4
4
|
|
5
|
-
def click_by_name name
|
6
|
-
find_by_name(name).click
|
7
|
-
end
|
8
|
-
|
9
5
|
def click
|
10
|
-
find_element_by_identifier
|
11
|
-
end
|
12
|
-
|
13
|
-
private
|
14
|
-
|
15
|
-
def method_missing method, *args
|
16
|
-
if method =~ /^click_(.*)_by_name$/
|
17
|
-
find_by_name($1, args.first).click
|
18
|
-
else
|
19
|
-
super
|
20
|
-
end
|
6
|
+
find_element_by_identifier.click
|
21
7
|
end
|
22
|
-
|
23
8
|
end
|
24
9
|
end
|
25
10
|
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require_relative 'find'
|
2
|
+
require_relative 'click'
|
3
|
+
require_relative 'match'
|
4
|
+
require_relative 'exceptions'
|
5
|
+
|
6
|
+
module Prickle
|
7
|
+
module Capybara
|
8
|
+
class Element
|
9
|
+
|
10
|
+
require 'capybara/dsl'
|
11
|
+
include ::Capybara::DSL
|
12
|
+
|
13
|
+
def initialize type="*", identifier
|
14
|
+
@identifier = identifier
|
15
|
+
@type = type
|
16
|
+
self
|
17
|
+
end
|
18
|
+
|
19
|
+
def handle_exception &block
|
20
|
+
begin
|
21
|
+
block.call
|
22
|
+
rescue Exception => e
|
23
|
+
raise ElementNotFound, Error.new(@type, @identifier, @text, e).message if e.class.to_s == "Capybara::ElementNotFound"
|
24
|
+
raise
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def identifier
|
29
|
+
return @identifier.each_pair.to_a.map do |key, value|
|
30
|
+
"@#{key}='#{value}'"
|
31
|
+
end.join ' and '
|
32
|
+
end
|
33
|
+
|
34
|
+
def find_element_by xpath
|
35
|
+
wait_until(Prickle::Capybara.wait_time) do
|
36
|
+
find(:xpath, xpath).visible?
|
37
|
+
end unless Prickle::Capybara.wait_time.nil?
|
38
|
+
|
39
|
+
find(:xpath, xpath)
|
40
|
+
end
|
41
|
+
|
42
|
+
def type_of element
|
43
|
+
Prickle::TAGS[element.to_sym] || element
|
44
|
+
end
|
45
|
+
|
46
|
+
include Prickle::Actions::Find
|
47
|
+
include Prickle::Actions::Match
|
48
|
+
include Prickle::Actions::Click
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
end
|
@@ -1,16 +1,39 @@
|
|
1
1
|
module Prickle
|
2
2
|
module Capybara
|
3
|
-
class ElementNotFound < Exception
|
4
3
|
|
5
|
-
|
6
|
-
element_text = "Element"
|
7
|
-
element_text = "\e[1m#{type}\e[0m\e[31m" unless type == "*"
|
8
|
-
text_string = " and text \e[1m#{text}\e[0m\e[31m" unless text.nil?
|
4
|
+
class ElementNotFound < Exception; end;
|
9
5
|
|
10
|
-
|
6
|
+
class Error
|
7
|
+
|
8
|
+
def initialize type, identifier, text, caught_exception
|
9
|
+
@element_type = type
|
10
|
+
@element_identifier = identifier
|
11
|
+
@element_text = text
|
12
|
+
@caught_exception = caught_exception
|
11
13
|
end
|
12
14
|
|
13
|
-
|
15
|
+
def message
|
16
|
+
"#{element_text} with properties #{identifier} #{text_string} was not found.\n\tError: #{@caught_exception.message}"
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def element_text
|
22
|
+
return highlight(@element_type) unless @element_type == "*"
|
23
|
+
"Element"
|
24
|
+
end
|
14
25
|
|
26
|
+
def text_string
|
27
|
+
" and text #{highlight(@element_text)}" unless @element_text.nil?
|
28
|
+
end
|
29
|
+
|
30
|
+
def identifier
|
31
|
+
highlight(@element_identifier.to_s)
|
32
|
+
end
|
33
|
+
|
34
|
+
def highlight text
|
35
|
+
"\e[1m#{text}\e[0m\e[31m"
|
36
|
+
end
|
37
|
+
end
|
15
38
|
end
|
16
39
|
end
|
@@ -2,33 +2,8 @@ module Prickle
|
|
2
2
|
module Actions
|
3
3
|
module Find
|
4
4
|
|
5
|
-
def find_by_name type='*', name
|
6
|
-
find_element_by_identifier type, { :name => name }
|
7
|
-
end
|
8
|
-
|
9
5
|
def exists?
|
10
|
-
find_element_by_identifier
|
11
|
-
end
|
12
|
-
|
13
|
-
private
|
14
|
-
|
15
|
-
def method_missing method, *args
|
16
|
-
if method =~ /^find_(.*)_by_name$/
|
17
|
-
find_by_name $1, args.first
|
18
|
-
else
|
19
|
-
super
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
def find_by_identifier_xpath element, identifier
|
24
|
-
"//#{type_of(element)}[#{xpath_for(identifier)}]"
|
25
|
-
end
|
26
|
-
|
27
|
-
def find_element_by_identifier element, identifier
|
28
|
-
@type = element; @identifier = identifier
|
29
|
-
handle_exception do
|
30
|
-
find_element_by(find_by_identifier_xpath(element, identifier ))
|
31
|
-
end
|
6
|
+
find_element_by_identifier
|
32
7
|
end
|
33
8
|
|
34
9
|
end
|
@@ -4,27 +4,29 @@ module Prickle
|
|
4
4
|
|
5
5
|
def contains_text? text
|
6
6
|
handle_exception do
|
7
|
-
|
7
|
+
find_element_by_identifier_and_text
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
super
|
16
|
-
end
|
11
|
+
private
|
12
|
+
|
13
|
+
def xpath_for_identifier
|
14
|
+
"//#{type_of(@type)}[#{identifier}]"
|
17
15
|
end
|
18
16
|
|
19
|
-
|
17
|
+
def xpath_for_identifier_and_text
|
18
|
+
"//#{type_of(@type)}[#{identifier} and contains(text(), '#{@text}')]"
|
20
19
|
|
21
|
-
|
22
|
-
|
20
|
+
end
|
21
|
+
def find_element_by_identifier
|
22
|
+
handle_exception do
|
23
|
+
find_element_by xpath_for_identifier
|
24
|
+
end
|
23
25
|
end
|
24
26
|
|
25
|
-
def
|
27
|
+
def find_element_by_identifier_and_text
|
26
28
|
handle_exception do
|
27
|
-
find_element_by
|
29
|
+
find_element_by xpath_for_identifier_and_text
|
28
30
|
end
|
29
31
|
end
|
30
32
|
|
data/prickle.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
$:.push File.expand_path("../lib", __FILE__)
|
2
|
+
require "prickle/version"
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = "prickle"
|
6
|
+
s.version = Prickle::VERSION
|
7
|
+
s.platform = Gem::Platform::RUBY
|
8
|
+
s.author = "Despo Pentara"
|
9
|
+
s.email = "despo@extractmethod.com"
|
10
|
+
s.homepage = "https://github.com/ExtractMethod/prickle"
|
11
|
+
s.summary = "A simple DSL wrapped around Capybara for matching elements using html tags."
|
12
|
+
s.description = "A simple DSL wrapped around Capybara for matching elements using html tags."
|
13
|
+
s.required_ruby_version = '>= 1.9.2'
|
14
|
+
|
15
|
+
s.licenses = ["MIT"]
|
16
|
+
|
17
|
+
s.files = `git ls-files`.split("\n")
|
18
|
+
s.test_files = `git ls-files -- {spec}/*`.split("\n")
|
19
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
|
+
s.require_paths = ["lib"]
|
21
|
+
|
22
|
+
s.add_dependency "capybara"
|
23
|
+
|
24
|
+
s.add_development_dependency "capybara"
|
25
|
+
s.add_development_dependency "rspec", "~> 2.8.0"
|
26
|
+
s.add_development_dependency "sinatra", "~> 1.3.2"
|
27
|
+
s.add_development_dependency "reek"
|
28
|
+
end
|
29
|
+
|
data/spec/extended_wait_spec.rb
CHANGED
data/spec/finders_spec.rb
CHANGED
@@ -4,6 +4,7 @@ describe Prickle::Capybara do
|
|
4
4
|
let(:prickly) { Prickly.new }
|
5
5
|
|
6
6
|
before do
|
7
|
+
Capybara.default_driver = :rack_test
|
7
8
|
prickly.extend Prickle::Capybara
|
8
9
|
prickly.visit '/'
|
9
10
|
end
|
@@ -60,7 +61,7 @@ describe Prickle::Capybara do
|
|
60
61
|
|
61
62
|
context 'DSL' do
|
62
63
|
it 'can find an element' do
|
63
|
-
prickly.element(:name => 'blue').should ==
|
64
|
+
prickly.element(:name => 'blue').class.to_s.should == "Prickle::Capybara::Element"
|
64
65
|
end
|
65
66
|
|
66
67
|
it 'can match text in an element' do
|
data/spec/spec_helper.rb
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), "..", "lib", "prickle", "capybara")
|
2
2
|
|
3
3
|
require 'rspec'
|
4
|
-
require 'capybara'
|
5
|
-
require 'capybara/dsl'
|
6
4
|
require 'prickle/capybara'
|
7
5
|
|
8
6
|
class Prickly
|
@@ -12,5 +10,4 @@ end
|
|
12
10
|
|
13
11
|
require_relative 'stub/app'
|
14
12
|
Capybara.app = Sinatra::Application
|
15
|
-
Capybara.default_driver = :selenium
|
16
13
|
Capybara.default_wait_time = 0
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: prickle
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.2
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Despo Pentara
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2012-02-
|
13
|
+
date: 2012-02-11 00:00:00 +00:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -57,6 +57,17 @@ dependencies:
|
|
57
57
|
version: 1.3.2
|
58
58
|
type: :development
|
59
59
|
version_requirements: *id004
|
60
|
+
- !ruby/object:Gem::Dependency
|
61
|
+
name: reek
|
62
|
+
prerelease: false
|
63
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
64
|
+
none: false
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: "0"
|
69
|
+
type: :development
|
70
|
+
version_requirements: *id005
|
60
71
|
description: A simple DSL wrapped around Capybara for matching elements using html tags.
|
61
72
|
email: despo@extractmethod.com
|
62
73
|
executables: []
|
@@ -72,9 +83,12 @@ files:
|
|
72
83
|
- README.md
|
73
84
|
- lib/prickle/capybara.rb
|
74
85
|
- lib/prickle/capybara/click.rb
|
86
|
+
- lib/prickle/capybara/element.rb
|
75
87
|
- lib/prickle/capybara/exceptions.rb
|
76
88
|
- lib/prickle/capybara/find.rb
|
77
89
|
- lib/prickle/capybara/match.rb
|
90
|
+
- lib/prickle/version.rb
|
91
|
+
- prickle.gemspec
|
78
92
|
- prickle.png
|
79
93
|
- spec/extended_wait_spec.rb
|
80
94
|
- spec/finders_spec.rb
|