prickle 0.0.3 → 0.0.4
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/.gitignore +3 -0
- data/.rspec +1 -0
- data/README.md +6 -0
- data/lib/prickle/capybara/element.rb +29 -17
- data/lib/prickle/capybara.rb +11 -2
- data/lib/prickle/core_ext/symbol.rb +6 -0
- data/lib/prickle/exceptions/messages.rb +55 -0
- data/lib/prickle/exceptions.rb +26 -0
- data/lib/prickle/version.rb +1 -1
- data/prickle.gemspec +2 -2
- data/spec/element_spec.rb +8 -0
- data/spec/extended_wait_spec.rb +1 -1
- data/spec/stub/index.html +1 -0
- metadata +9 -6
- data/Gemfile.lock +0 -71
- data/lib/prickle/capybara/exceptions.rb +0 -46
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
-cfd
|
data/README.md
CHANGED
@@ -45,6 +45,12 @@ element(:id => "key")
|
|
45
45
|
element(:class => "key", :id => "button")
|
46
46
|
```
|
47
47
|
|
48
|
+
You can also find elements by a value contained in the identifier
|
49
|
+
|
50
|
+
```ruby
|
51
|
+
element(:name.like => "blue") # will match <button name="blue_12345">
|
52
|
+
```
|
53
|
+
|
48
54
|
### Find elements by type and html tag(s)
|
49
55
|
|
50
56
|
```ruby
|
@@ -1,6 +1,5 @@
|
|
1
1
|
require 'capybara/dsl'
|
2
2
|
require_relative 'actions'
|
3
|
-
require_relative 'exceptions'
|
4
3
|
|
5
4
|
module Prickle
|
6
5
|
module Capybara
|
@@ -21,11 +20,35 @@ module Prickle
|
|
21
20
|
self
|
22
21
|
end
|
23
22
|
|
23
|
+
def identifier
|
24
|
+
@identifier.each_pair.inject([]) do |xpath_str, (key, value)|
|
25
|
+
xpath_str << convert_to_xpath(key, value)
|
26
|
+
end.join " and "
|
27
|
+
end
|
28
|
+
|
29
|
+
def convert_to_xpath key, value
|
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
|
38
|
+
CONVERTED_TYPES[@type.to_sym] || @type
|
39
|
+
end
|
40
|
+
|
24
41
|
def find_element
|
25
|
-
handle_exception {
|
42
|
+
handle_exception { find_element_by_xpath }
|
26
43
|
end
|
27
44
|
|
28
|
-
def
|
45
|
+
def xpath
|
46
|
+
xpath = "//#{type}[#{identifier}"
|
47
|
+
xpath << " and contains(text(), '#{@text}')" if @text
|
48
|
+
xpath << "]"
|
49
|
+
end
|
50
|
+
|
51
|
+
def find_element_by_xpath
|
29
52
|
wait_until(Prickle::Capybara.wait_time) do
|
30
53
|
find(:xpath, xpath).visible?
|
31
54
|
end unless Prickle::Capybara.wait_time.nil?
|
@@ -37,24 +60,13 @@ module Prickle
|
|
37
60
|
begin
|
38
61
|
block.call
|
39
62
|
rescue Exception => e
|
40
|
-
|
41
|
-
raise ElementNotFound, error_message if e.class.to_s == "Capybara::ElementNotFound"
|
63
|
+
raise element_not_found(e) if e.class == ::Capybara::ElementNotFound
|
42
64
|
raise
|
43
65
|
end
|
44
66
|
end
|
45
67
|
|
46
|
-
def
|
47
|
-
|
48
|
-
end
|
49
|
-
|
50
|
-
def type
|
51
|
-
CONVERTED_TYPES[@type.to_sym] || @type
|
52
|
-
end
|
53
|
-
|
54
|
-
def xpath
|
55
|
-
xpath = "//#{type}[#{identifier}"
|
56
|
-
xpath << " and contains(text(), '#{@text}')" if @text
|
57
|
-
xpath << "]"
|
68
|
+
def element_not_found caught_exception
|
69
|
+
Exceptions::ElementNotFound.new(@type, identifier, @text, caught_exception)
|
58
70
|
end
|
59
71
|
|
60
72
|
public
|
data/lib/prickle/capybara.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
require_relative 'capybara/element'
|
2
|
+
require_relative 'exceptions'
|
3
|
+
require_relative 'core_ext/symbol'
|
2
4
|
|
3
5
|
module Prickle
|
4
6
|
module Capybara
|
@@ -8,7 +10,7 @@ module Prickle
|
|
8
10
|
|
9
11
|
end
|
10
12
|
|
11
|
-
def capture_screen name=
|
13
|
+
def capture_screen name=screenshot_name
|
12
14
|
page.driver.browser.save_screenshot Capybara.image_dir + name + ".jpg"
|
13
15
|
end
|
14
16
|
|
@@ -37,11 +39,13 @@ module Prickle
|
|
37
39
|
end
|
38
40
|
|
39
41
|
def popup_message_contains? message
|
40
|
-
raise
|
42
|
+
raise Exceptions::MessageNotContainedInPopup.new(message) unless popup_message.eql? message
|
41
43
|
end
|
42
44
|
|
43
45
|
private
|
44
46
|
|
47
|
+
TIME_FORMATTER = "%Y%m%d-%H.%M.%s"
|
48
|
+
|
45
49
|
def method_missing method, *args
|
46
50
|
if method =~ /(^.*)_contains_text\?$/
|
47
51
|
element($1, :name => args.first).contains_text? args[1]
|
@@ -54,5 +58,10 @@ module Prickle
|
|
54
58
|
end
|
55
59
|
end
|
56
60
|
|
61
|
+
def screenshot_name
|
62
|
+
Time.now.strftime(TIME_FORMATTER)
|
63
|
+
end
|
64
|
+
|
57
65
|
end
|
66
|
+
|
58
67
|
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
module Prickle
|
2
|
+
module Exceptions
|
3
|
+
module Message
|
4
|
+
|
5
|
+
private
|
6
|
+
def highlight text
|
7
|
+
"\e[1m#{text}\e[0m\e[31m"
|
8
|
+
end
|
9
|
+
|
10
|
+
class ElementNotFound
|
11
|
+
include Message
|
12
|
+
|
13
|
+
def initialize type=nil, identifier=nil, text=nil, caught_exception=nil
|
14
|
+
@element_type = type
|
15
|
+
@element_identifier = identifier
|
16
|
+
@element_text = text
|
17
|
+
@caught_exception = caught_exception
|
18
|
+
end
|
19
|
+
|
20
|
+
def to_s
|
21
|
+
"#{element_text} with identifier #{identifier}#{text_string} was not found.\n\tError: #{@caught_exception.message}"
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def element_text
|
27
|
+
return highlight(@element_type) unless @element_type == "*"
|
28
|
+
"Element"
|
29
|
+
end
|
30
|
+
|
31
|
+
def text_string
|
32
|
+
" and text #{highlight(@element_text)}" unless @element_text.nil?
|
33
|
+
end
|
34
|
+
|
35
|
+
def identifier
|
36
|
+
highlight(@element_identifier.to_s)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
class TextNotContainedInPopup
|
41
|
+
include Message
|
42
|
+
|
43
|
+
def initialize message
|
44
|
+
@message = message
|
45
|
+
end
|
46
|
+
|
47
|
+
def to_s
|
48
|
+
"Text #{highlight(@message)} is not contained in the popup."
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require_relative 'exceptions/messages'
|
2
|
+
|
3
|
+
module Prickle
|
4
|
+
module Exceptions
|
5
|
+
|
6
|
+
def message
|
7
|
+
@message
|
8
|
+
end
|
9
|
+
|
10
|
+
class ElementNotFound < Exception
|
11
|
+
include Prickle::Exceptions
|
12
|
+
|
13
|
+
def initialize(type, identifier, text, caught_exception)
|
14
|
+
@message = Message::ElementNotFound.new(type, identifier, text, caught_exception).to_s
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
class MessageNotContainedInPopup < Exception
|
19
|
+
include Prickle::Exceptions
|
20
|
+
|
21
|
+
def initialize message
|
22
|
+
@message = Message::TextNotContainedInPopup.new(message).to_s
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/prickle/version.rb
CHANGED
data/prickle.gemspec
CHANGED
@@ -8,8 +8,8 @@ Gem::Specification.new do |s|
|
|
8
8
|
s.author = "Despo Pentara"
|
9
9
|
s.email = "despo@extractmethod.com"
|
10
10
|
s.homepage = "https://github.com/ExtractMethod/prickle"
|
11
|
-
s.summary = "A simple DSL
|
12
|
-
s.description = "A simple DSL
|
11
|
+
s.summary = "A simple DSL extending Capybara."
|
12
|
+
s.description = "A simple DSL extending Capybara."
|
13
13
|
s.required_ruby_version = '>= 1.9.2'
|
14
14
|
|
15
15
|
s.licenses = ["MIT"]
|
data/spec/element_spec.rb
CHANGED
@@ -11,6 +11,14 @@ describe Prickle::Capybara::Element do
|
|
11
11
|
prickly.element(:name => 'blue').class.to_s.should == "Prickle::Capybara::Element"
|
12
12
|
end
|
13
13
|
|
14
|
+
it 'can find an element by a string contained in its identifier' do
|
15
|
+
prickly.element(:name.like => 'purpli').contains_text? "erm"
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'can find an element by a contained and an exact match in its identifier' do
|
19
|
+
prickly.element(:name.like => 'purpli', :id => 'one').contains_text? "erm"
|
20
|
+
end
|
21
|
+
|
14
22
|
it 'can match text in an element' do
|
15
23
|
prickly.element(:name => 'yellow').contains_text? "Hello!"
|
16
24
|
end
|
data/spec/extended_wait_spec.rb
CHANGED
@@ -22,7 +22,7 @@ describe Prickle::Capybara do
|
|
22
22
|
end
|
23
23
|
|
24
24
|
it "can fail if an element doesn't appear after the default wait time" do
|
25
|
-
Prickle::Capybara.wait_time =
|
25
|
+
Prickle::Capybara.wait_time = 1
|
26
26
|
expect { prickly.element(:name => 'lagged').contains_text? "I lag" }.to raise_error Capybara::TimeoutError
|
27
27
|
end
|
28
28
|
end
|
data/spec/stub/index.html
CHANGED
@@ -23,6 +23,7 @@
|
|
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" >erm</button>
|
26
27
|
|
27
28
|
<script>
|
28
29
|
$(document).ready(function() {
|
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.4
|
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-12 00:00:00 +00:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -79,7 +79,7 @@ dependencies:
|
|
79
79
|
version: "0"
|
80
80
|
type: :development
|
81
81
|
version_requirements: *id006
|
82
|
-
description: A simple DSL
|
82
|
+
description: A simple DSL extending Capybara.
|
83
83
|
email: despo@extractmethod.com
|
84
84
|
executables: []
|
85
85
|
|
@@ -88,16 +88,19 @@ extensions: []
|
|
88
88
|
extra_rdoc_files: []
|
89
89
|
|
90
90
|
files:
|
91
|
+
- .gitignore
|
92
|
+
- .rspec
|
91
93
|
- .rvmrc
|
92
94
|
- .travis.yml
|
93
95
|
- Gemfile
|
94
|
-
- Gemfile.lock
|
95
96
|
- README.md
|
96
97
|
- Rakefile
|
97
98
|
- lib/prickle/capybara.rb
|
98
99
|
- lib/prickle/capybara/actions.rb
|
99
100
|
- lib/prickle/capybara/element.rb
|
100
|
-
- lib/prickle/
|
101
|
+
- lib/prickle/core_ext/symbol.rb
|
102
|
+
- lib/prickle/exceptions.rb
|
103
|
+
- lib/prickle/exceptions/messages.rb
|
101
104
|
- lib/prickle/version.rb
|
102
105
|
- prickle.gemspec
|
103
106
|
- prickle.png
|
@@ -136,6 +139,6 @@ rubyforge_project:
|
|
136
139
|
rubygems_version: 1.5.2
|
137
140
|
signing_key:
|
138
141
|
specification_version: 3
|
139
|
-
summary: A simple DSL
|
142
|
+
summary: A simple DSL extending Capybara.
|
140
143
|
test_files: []
|
141
144
|
|
data/Gemfile.lock
DELETED
@@ -1,71 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
prickle (0.0.2)
|
5
|
-
capybara
|
6
|
-
|
7
|
-
GEM
|
8
|
-
remote: http://rubygems.org/
|
9
|
-
specs:
|
10
|
-
capybara (1.1.2)
|
11
|
-
mime-types (>= 1.16)
|
12
|
-
nokogiri (>= 1.3.3)
|
13
|
-
rack (>= 1.0.0)
|
14
|
-
rack-test (>= 0.5.4)
|
15
|
-
selenium-webdriver (~> 2.0)
|
16
|
-
xpath (~> 0.1.4)
|
17
|
-
childprocess (0.3.1)
|
18
|
-
ffi (~> 1.0.6)
|
19
|
-
diff-lcs (1.1.3)
|
20
|
-
ffi (1.0.11)
|
21
|
-
mime-types (1.17.2)
|
22
|
-
multi_json (1.0.4)
|
23
|
-
nokogiri (1.5.0)
|
24
|
-
rack (1.4.1)
|
25
|
-
rack-protection (1.2.0)
|
26
|
-
rack
|
27
|
-
rack-test (0.6.1)
|
28
|
-
rack (>= 1.0)
|
29
|
-
rake (0.9.2)
|
30
|
-
reek (1.2.8)
|
31
|
-
ruby2ruby (~> 1.2)
|
32
|
-
ruby_parser (~> 2.0)
|
33
|
-
sexp_processor (~> 3.0)
|
34
|
-
rspec (2.8.0)
|
35
|
-
rspec-core (~> 2.8.0)
|
36
|
-
rspec-expectations (~> 2.8.0)
|
37
|
-
rspec-mocks (~> 2.8.0)
|
38
|
-
rspec-core (2.8.0)
|
39
|
-
rspec-expectations (2.8.0)
|
40
|
-
diff-lcs (~> 1.1.2)
|
41
|
-
rspec-mocks (2.8.0)
|
42
|
-
ruby2ruby (1.3.1)
|
43
|
-
ruby_parser (~> 2.0)
|
44
|
-
sexp_processor (~> 3.0)
|
45
|
-
ruby_parser (2.3.1)
|
46
|
-
sexp_processor (~> 3.0)
|
47
|
-
rubyzip (0.9.6.1)
|
48
|
-
selenium-webdriver (2.19.0)
|
49
|
-
childprocess (>= 0.2.5)
|
50
|
-
ffi (~> 1.0.9)
|
51
|
-
multi_json (~> 1.0.4)
|
52
|
-
rubyzip
|
53
|
-
sexp_processor (3.0.10)
|
54
|
-
sinatra (1.3.2)
|
55
|
-
rack (~> 1.3, >= 1.3.6)
|
56
|
-
rack-protection (~> 1.2)
|
57
|
-
tilt (~> 1.3, >= 1.3.3)
|
58
|
-
tilt (1.3.3)
|
59
|
-
xpath (0.1.4)
|
60
|
-
nokogiri (~> 1.3)
|
61
|
-
|
62
|
-
PLATFORMS
|
63
|
-
ruby
|
64
|
-
|
65
|
-
DEPENDENCIES
|
66
|
-
capybara
|
67
|
-
prickle!
|
68
|
-
rake
|
69
|
-
reek
|
70
|
-
rspec (~> 2.8.0)
|
71
|
-
sinatra (~> 1.3.2)
|
@@ -1,46 +0,0 @@
|
|
1
|
-
module Prickle
|
2
|
-
module Capybara
|
3
|
-
|
4
|
-
class ElementNotFound < Exception; end;
|
5
|
-
|
6
|
-
class MessageNotContainedInPopup < Exception; end;
|
7
|
-
|
8
|
-
class Error
|
9
|
-
|
10
|
-
def initialize type=nil, identifier=nil, text=nil, caught_exception=nil
|
11
|
-
@element_type = type
|
12
|
-
@element_identifier = identifier
|
13
|
-
@element_text = text
|
14
|
-
@caught_exception = caught_exception
|
15
|
-
end
|
16
|
-
|
17
|
-
def message
|
18
|
-
"#{element_text} with properties #{identifier} #{text_string} was not found.\n\tError: #{@caught_exception.message}"
|
19
|
-
end
|
20
|
-
|
21
|
-
def not_contained_in_popup message
|
22
|
-
"Text #{highlight(message)} is not contained in the popup."
|
23
|
-
end
|
24
|
-
|
25
|
-
private
|
26
|
-
|
27
|
-
def element_text
|
28
|
-
return highlight(@element_type) unless @element_type == "*"
|
29
|
-
"Element"
|
30
|
-
end
|
31
|
-
|
32
|
-
def text_string
|
33
|
-
" and text #{highlight(@element_text)}" unless @element_text.nil?
|
34
|
-
end
|
35
|
-
|
36
|
-
def identifier
|
37
|
-
highlight(@element_identifier.to_s)
|
38
|
-
end
|
39
|
-
|
40
|
-
def highlight text
|
41
|
-
"\e[1m#{text}\e[0m\e[31m"
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
end
|
46
|
-
end
|