prickle 0.0.4 → 0.0.5
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/.rvmrc +1 -1
- data/README.md +8 -1
- data/lib/prickle/capybara/actions.rb +7 -0
- data/lib/prickle/capybara/element.rb +10 -21
- data/lib/prickle/capybara/xpath/expression.rb +61 -0
- data/lib/prickle/capybara/xpath.rb +33 -0
- data/lib/prickle/capybara.rb +4 -6
- data/lib/prickle/core_ext/symbol.rb +1 -1
- data/lib/prickle/version.rb +1 -1
- data/spec/element_spec.rb +42 -23
- data/spec/stub/index.html +2 -1
- metadata +65 -72
data/.rvmrc
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
# development environment upon cd'ing into the directory
|
5
5
|
|
6
6
|
# First we specify our desired <ruby>[@<gemset>], the @gemset name is optional.
|
7
|
-
environment_id="ruby-1.9.
|
7
|
+
environment_id="ruby-1.9.3-p0@prickle"
|
8
8
|
|
9
9
|
#
|
10
10
|
# Uncomment following line if you want options to be set only for given project.
|
data/README.md
CHANGED
@@ -12,7 +12,7 @@ To install prickle execute
|
|
12
12
|
gem install prickle
|
13
13
|
```
|
14
14
|
|
15
|
-
|
15
|
+
Configure by updating the *features/support/env.rb* to include the following:
|
16
16
|
|
17
17
|
```ruby
|
18
18
|
require 'prickle/capybara' # require
|
@@ -65,6 +65,7 @@ element(:input, :name => "blue")
|
|
65
65
|
element(:name => "flower").exists?
|
66
66
|
element(:name => "flower").click
|
67
67
|
element(:name => "flower").contains_text? "Roses"
|
68
|
+
element(:name => "flower").has_text? "Anemone" # exact match
|
68
69
|
```
|
69
70
|
|
70
71
|
## Alternative syntax
|
@@ -101,6 +102,12 @@ popup_message_contains? "<text>"
|
|
101
102
|
|
102
103
|
## Capturing screenshots
|
103
104
|
|
105
|
+
Configure the directory where you want the screenshots to be saved
|
106
|
+
|
107
|
+
```ruby
|
108
|
+
Prickle::Capybara.image_dir = File.dirname(__FILE__) + "/screenshots/"
|
109
|
+
```
|
110
|
+
|
104
111
|
```ruby
|
105
112
|
capture_screen
|
106
113
|
capture_screen "<file>"
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'capybara/dsl'
|
2
|
+
require_relative 'xpath'
|
2
3
|
require_relative 'actions'
|
3
4
|
|
4
5
|
module Prickle
|
@@ -21,20 +22,10 @@ module Prickle
|
|
21
22
|
end
|
22
23
|
|
23
24
|
def identifier
|
24
|
-
@identifier
|
25
|
-
xpath_str << convert_to_xpath(key, value)
|
26
|
-
end.join " and "
|
25
|
+
@identifier
|
27
26
|
end
|
28
27
|
|
29
|
-
def
|
30
|
-
if key.to_s.include? "<value>"
|
31
|
-
key.sub "<value>", value
|
32
|
-
else
|
33
|
-
"@#{key}='#{value}'"
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
def type
|
28
|
+
def type_as_tag
|
38
29
|
CONVERTED_TYPES[@type.to_sym] || @type
|
39
30
|
end
|
40
31
|
|
@@ -42,18 +33,16 @@ module Prickle
|
|
42
33
|
handle_exception { find_element_by_xpath }
|
43
34
|
end
|
44
35
|
|
45
|
-
def xpath
|
46
|
-
xpath = "//#{type}[#{identifier}"
|
47
|
-
xpath << " and contains(text(), '#{@text}')" if @text
|
48
|
-
xpath << "]"
|
49
|
-
end
|
50
|
-
|
51
36
|
def find_element_by_xpath
|
52
|
-
wait_until(
|
37
|
+
wait_until(Capybara.wait_time) do
|
53
38
|
find(:xpath, xpath).visible?
|
54
|
-
end unless
|
39
|
+
end unless Capybara.wait_time.nil?
|
40
|
+
|
41
|
+
find :xpath, xpath
|
42
|
+
end
|
55
43
|
|
56
|
-
|
44
|
+
def xpath
|
45
|
+
XPath::for_element_with type_as_tag, identifier
|
57
46
|
end
|
58
47
|
|
59
48
|
def handle_exception &block
|
@@ -0,0 +1,61 @@
|
|
1
|
+
module Prickle
|
2
|
+
module Capybara
|
3
|
+
module XPath
|
4
|
+
|
5
|
+
class Expression
|
6
|
+
CONTAINS = ".like"
|
7
|
+
TEXT_IDENTIFIER = "text()"
|
8
|
+
SEPARATOR = " and "
|
9
|
+
|
10
|
+
def initialize identifier, value
|
11
|
+
@identifier = identifier
|
12
|
+
@value = value
|
13
|
+
end
|
14
|
+
|
15
|
+
def to_s
|
16
|
+
find_exact_match? ? MatchesValue.new(@identifier, @value).to_s : ContainsValue.new(@identifier, @value).to_s
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def find_exact_match?
|
22
|
+
!identifier.include? CONTAINS
|
23
|
+
end
|
24
|
+
|
25
|
+
def identifier
|
26
|
+
@identifier.to_s
|
27
|
+
end
|
28
|
+
|
29
|
+
def attribute
|
30
|
+
return identifier if identifier.eql? TEXT_IDENTIFIER
|
31
|
+
"@#{identifier}"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
class ContainsValue < XPath::Expression
|
37
|
+
|
38
|
+
def to_s
|
39
|
+
"contains(#{attribute}, '#{@value}')"
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def identifier
|
45
|
+
@identifier.chomp CONTAINS
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
|
50
|
+
class MatchesValue < XPath::Expression
|
51
|
+
|
52
|
+
def to_s
|
53
|
+
"#{attribute}='#{@value}'"
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require_relative 'xpath/expression'
|
2
|
+
module Prickle
|
3
|
+
module Capybara
|
4
|
+
module XPath
|
5
|
+
|
6
|
+
def self.for_element_with type, identifier
|
7
|
+
XPath::Element.new(type,identifier).to_s
|
8
|
+
end
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
class Element
|
13
|
+
|
14
|
+
def initialize type, identifier
|
15
|
+
@type = type
|
16
|
+
@identifier = identifier
|
17
|
+
end
|
18
|
+
|
19
|
+
def to_s
|
20
|
+
"//#{@type}[#{identifier}]"
|
21
|
+
end
|
22
|
+
|
23
|
+
def identifier
|
24
|
+
return @identifier.each_pair.inject([]) do | xpath, (identifier, value) |
|
25
|
+
xpath << XPath::Expression.new(identifier, value).to_s
|
26
|
+
end.join Expression::SEPARATOR
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
data/lib/prickle/capybara.rb
CHANGED
@@ -10,10 +10,6 @@ module Prickle
|
|
10
10
|
|
11
11
|
end
|
12
12
|
|
13
|
-
def capture_screen name=screenshot_name
|
14
|
-
page.driver.browser.save_screenshot Capybara.image_dir + name + ".jpg"
|
15
|
-
end
|
16
|
-
|
17
13
|
def click_by_name name
|
18
14
|
find_by_name(name).click
|
19
15
|
end
|
@@ -42,6 +38,10 @@ module Prickle
|
|
42
38
|
raise Exceptions::MessageNotContainedInPopup.new(message) unless popup_message.eql? message
|
43
39
|
end
|
44
40
|
|
41
|
+
def capture_screen name=screenshot_name
|
42
|
+
page.driver.browser.save_screenshot Capybara.image_dir + name + ".jpg"
|
43
|
+
end
|
44
|
+
|
45
45
|
private
|
46
46
|
|
47
47
|
TIME_FORMATTER = "%Y%m%d-%H.%M.%s"
|
@@ -61,7 +61,5 @@ module Prickle
|
|
61
61
|
def screenshot_name
|
62
62
|
Time.now.strftime(TIME_FORMATTER)
|
63
63
|
end
|
64
|
-
|
65
64
|
end
|
66
|
-
|
67
65
|
end
|
data/lib/prickle/version.rb
CHANGED
data/spec/element_spec.rb
CHANGED
@@ -11,40 +11,59 @@ describe Prickle::Capybara::Element do
|
|
11
11
|
prickly.element(:name => 'blue').class.to_s.should == "Prickle::Capybara::Element"
|
12
12
|
end
|
13
13
|
|
14
|
-
|
15
|
-
prickly.element(:name.like => 'purpli').contains_text? "erm"
|
16
|
-
end
|
14
|
+
context "Matchers" do
|
17
15
|
|
18
|
-
|
19
|
-
|
20
|
-
|
16
|
+
it 'can match text in an element' do
|
17
|
+
prickly.element(:name => 'yellow').contains_text? "Hello!"
|
18
|
+
end
|
21
19
|
|
22
|
-
|
23
|
-
|
24
|
-
|
20
|
+
it 'can match on link type elements' do
|
21
|
+
prickly.element(:link, :name => 'orangey').contains_text? "Me too!"
|
22
|
+
end
|
25
23
|
|
26
|
-
|
27
|
-
|
28
|
-
|
24
|
+
it 'can find and click on element by type and identifier' do
|
25
|
+
prickly.element(:link, :href => 'http://google.com').exists?
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'can find an element by multiple identifiers' do
|
29
|
+
prickly.element(:name => 'orangey', :class => 'pink').contains_text? "Blue hippos"
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'can find an element by a string contained in its identifier' do
|
33
|
+
prickly.element(:name.like => 'purpli').contains_text? "erm"
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'can find an element by a contained and an exact match in its identifier' do
|
37
|
+
prickly.element(:name.like => 'purpli', :id => 'one').contains_text? "erm"
|
38
|
+
end
|
29
39
|
|
30
|
-
it 'can match on link type elements' do
|
31
|
-
prickly.element(:link, :name => 'orangey').contains_text? "Me too!"
|
32
40
|
end
|
33
41
|
|
34
|
-
|
35
|
-
|
42
|
+
context "#click" do
|
43
|
+
|
44
|
+
it 'can click specific element types by name' do
|
45
|
+
prickly.element(:paragraph, :name => 'yellow').click
|
46
|
+
end
|
36
47
|
end
|
37
48
|
|
38
|
-
|
39
|
-
|
49
|
+
context "#contains_text" do
|
50
|
+
|
51
|
+
it 'can check if text is included in an element' do
|
52
|
+
prickly.element(:li, :name => 'purple').contains_text? "Im not purple!"
|
53
|
+
end
|
40
54
|
end
|
41
55
|
|
42
|
-
|
43
|
-
|
56
|
+
context "#has_text?" do
|
57
|
+
|
58
|
+
it "can match the text in an element" do
|
59
|
+
prickly.element(:name => 'gum').has_text? "bubblegum"
|
60
|
+
end
|
44
61
|
end
|
45
62
|
|
46
|
-
|
47
|
-
|
63
|
+
context "#exists?" do
|
64
|
+
|
65
|
+
it 'can find an element by type and identifier' do
|
66
|
+
prickly.element(:paragraph, :id => 'coffee').exists?
|
67
|
+
end
|
48
68
|
end
|
49
69
|
end
|
50
|
-
|
data/spec/stub/index.html
CHANGED
@@ -23,7 +23,8 @@
|
|
23
23
|
<button name="popups" onclick="alert('Hello');">erm</button>
|
24
24
|
|
25
25
|
<button name="confirm_box" onclick="if(!confirm('Click yes to continue'))alert('Aborting.');">erm</button>
|
26
|
-
<button name="purplish" id="one"
|
26
|
+
<button name="purplish" id="one">erms</button>
|
27
|
+
<p name="gum">bubblegum</p>
|
27
28
|
|
28
29
|
<script>
|
29
30
|
$(document).ready(function() {
|
metadata
CHANGED
@@ -1,93 +1,88 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: prickle
|
3
|
-
version: !ruby/object:Gem::Version
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.5
|
4
5
|
prerelease:
|
5
|
-
version: 0.0.4
|
6
6
|
platform: ruby
|
7
|
-
authors:
|
7
|
+
authors:
|
8
8
|
- Despo Pentara
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
dependencies:
|
16
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2012-02-12 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
17
15
|
name: capybara
|
18
|
-
|
19
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
16
|
+
requirement: &70174028443700 !ruby/object:Gem::Requirement
|
20
17
|
none: false
|
21
|
-
requirements:
|
22
|
-
- -
|
23
|
-
- !ruby/object:Gem::Version
|
24
|
-
version:
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
25
22
|
type: :runtime
|
26
|
-
version_requirements: *id001
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: capybara
|
29
23
|
prerelease: false
|
30
|
-
|
24
|
+
version_requirements: *70174028443700
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: capybara
|
27
|
+
requirement: &70174028443100 !ruby/object:Gem::Requirement
|
31
28
|
none: false
|
32
|
-
requirements:
|
33
|
-
- -
|
34
|
-
- !ruby/object:Gem::Version
|
35
|
-
version:
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
36
33
|
type: :development
|
37
|
-
version_requirements: *id002
|
38
|
-
- !ruby/object:Gem::Dependency
|
39
|
-
name: rspec
|
40
34
|
prerelease: false
|
41
|
-
|
35
|
+
version_requirements: *70174028443100
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: rspec
|
38
|
+
requirement: &70174028442480 !ruby/object:Gem::Requirement
|
42
39
|
none: false
|
43
|
-
requirements:
|
40
|
+
requirements:
|
44
41
|
- - ~>
|
45
|
-
- !ruby/object:Gem::Version
|
42
|
+
- !ruby/object:Gem::Version
|
46
43
|
version: 2.8.0
|
47
44
|
type: :development
|
48
|
-
version_requirements: *id003
|
49
|
-
- !ruby/object:Gem::Dependency
|
50
|
-
name: sinatra
|
51
45
|
prerelease: false
|
52
|
-
|
46
|
+
version_requirements: *70174028442480
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: sinatra
|
49
|
+
requirement: &70174028441920 !ruby/object:Gem::Requirement
|
53
50
|
none: false
|
54
|
-
requirements:
|
51
|
+
requirements:
|
55
52
|
- - ~>
|
56
|
-
- !ruby/object:Gem::Version
|
53
|
+
- !ruby/object:Gem::Version
|
57
54
|
version: 1.3.2
|
58
55
|
type: :development
|
59
|
-
version_requirements: *id004
|
60
|
-
- !ruby/object:Gem::Dependency
|
61
|
-
name: rake
|
62
56
|
prerelease: false
|
63
|
-
|
57
|
+
version_requirements: *70174028441920
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: rake
|
60
|
+
requirement: &70174028441480 !ruby/object:Gem::Requirement
|
64
61
|
none: false
|
65
|
-
requirements:
|
66
|
-
- -
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version:
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
69
66
|
type: :development
|
70
|
-
version_requirements: *id005
|
71
|
-
- !ruby/object:Gem::Dependency
|
72
|
-
name: reek
|
73
67
|
prerelease: false
|
74
|
-
|
68
|
+
version_requirements: *70174028441480
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: reek
|
71
|
+
requirement: &70174028440740 !ruby/object:Gem::Requirement
|
75
72
|
none: false
|
76
|
-
requirements:
|
77
|
-
- -
|
78
|
-
- !ruby/object:Gem::Version
|
79
|
-
version:
|
73
|
+
requirements:
|
74
|
+
- - ! '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
80
77
|
type: :development
|
81
|
-
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: *70174028440740
|
82
80
|
description: A simple DSL extending Capybara.
|
83
81
|
email: despo@extractmethod.com
|
84
82
|
executables: []
|
85
|
-
|
86
83
|
extensions: []
|
87
|
-
|
88
84
|
extra_rdoc_files: []
|
89
|
-
|
90
|
-
files:
|
85
|
+
files:
|
91
86
|
- .gitignore
|
92
87
|
- .rspec
|
93
88
|
- .rvmrc
|
@@ -98,6 +93,8 @@ files:
|
|
98
93
|
- lib/prickle/capybara.rb
|
99
94
|
- lib/prickle/capybara/actions.rb
|
100
95
|
- lib/prickle/capybara/element.rb
|
96
|
+
- lib/prickle/capybara/xpath.rb
|
97
|
+
- lib/prickle/capybara/xpath/expression.rb
|
101
98
|
- lib/prickle/core_ext/symbol.rb
|
102
99
|
- lib/prickle/exceptions.rb
|
103
100
|
- lib/prickle/exceptions/messages.rb
|
@@ -112,33 +109,29 @@ files:
|
|
112
109
|
- spec/stub/app.rb
|
113
110
|
- spec/stub/index.html
|
114
111
|
- spec/tmp/.keep_me
|
115
|
-
has_rdoc: true
|
116
112
|
homepage: https://github.com/ExtractMethod/prickle
|
117
|
-
licenses:
|
113
|
+
licenses:
|
118
114
|
- MIT
|
119
115
|
post_install_message:
|
120
116
|
rdoc_options: []
|
121
|
-
|
122
|
-
require_paths:
|
117
|
+
require_paths:
|
123
118
|
- lib
|
124
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
119
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
125
120
|
none: false
|
126
|
-
requirements:
|
127
|
-
- -
|
128
|
-
- !ruby/object:Gem::Version
|
121
|
+
requirements:
|
122
|
+
- - ! '>='
|
123
|
+
- !ruby/object:Gem::Version
|
129
124
|
version: 1.9.2
|
130
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
125
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
131
126
|
none: false
|
132
|
-
requirements:
|
133
|
-
- -
|
134
|
-
- !ruby/object:Gem::Version
|
135
|
-
version:
|
127
|
+
requirements:
|
128
|
+
- - ! '>='
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: '0'
|
136
131
|
requirements: []
|
137
|
-
|
138
132
|
rubyforge_project:
|
139
|
-
rubygems_version: 1.
|
133
|
+
rubygems_version: 1.8.10
|
140
134
|
signing_key:
|
141
135
|
specification_version: 3
|
142
136
|
summary: A simple DSL extending Capybara.
|
143
137
|
test_files: []
|
144
|
-
|