prickle 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +9 -0
- data/Gemfile.lock +3 -1
- data/README.md +21 -0
- data/Rakefile +8 -0
- data/lib/prickle/capybara/actions.rb +20 -0
- data/lib/prickle/capybara/element.rb +34 -21
- data/lib/prickle/capybara/exceptions.rb +8 -1
- data/lib/prickle/capybara.rb +25 -9
- data/lib/prickle/version.rb +1 -1
- data/prickle.gemspec +1 -0
- data/spec/capybara_spec.rb +55 -0
- data/spec/element_spec.rb +42 -0
- data/spec/extended_wait_spec.rb +1 -2
- data/spec/finders_spec.rb +0 -36
- data/spec/spec_helper.rb +2 -0
- data/spec/stub/index.html +5 -0
- data/spec/tmp/.keep_me +0 -0
- metadata +19 -5
- data/lib/prickle/capybara/click.rb +0 -10
- data/lib/prickle/capybara/find.rb +0 -11
- data/lib/prickle/capybara/match.rb +0 -35
data/.travis.yml
ADDED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
prickle (0.0.
|
4
|
+
prickle (0.0.2)
|
5
5
|
capybara
|
6
6
|
|
7
7
|
GEM
|
@@ -26,6 +26,7 @@ GEM
|
|
26
26
|
rack
|
27
27
|
rack-test (0.6.1)
|
28
28
|
rack (>= 1.0)
|
29
|
+
rake (0.9.2)
|
29
30
|
reek (1.2.8)
|
30
31
|
ruby2ruby (~> 1.2)
|
31
32
|
ruby_parser (~> 2.0)
|
@@ -64,6 +65,7 @@ PLATFORMS
|
|
64
65
|
DEPENDENCIES
|
65
66
|
capybara
|
66
67
|
prickle!
|
68
|
+
rake
|
67
69
|
reek
|
68
70
|
rspec (~> 2.8.0)
|
69
71
|
sinatra (~> 1.3.2)
|
data/README.md
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
# Prickle
|
2
|
+
|
3
|
+
[![Build Status](https://secure.travis-ci.org/ExtractMethod/prickle.png)](http://travis-ci.org/ExtractMethod/prickle)
|
4
|
+
|
1
5
|
![](http://github.com/despo/prickle/raw/master/prickle.png)
|
2
6
|
|
3
7
|
## Configuration
|
@@ -78,3 +82,20 @@ click_input_by_name "blue" #click_<element_tag>_by_name "<name>"
|
|
78
82
|
```ruby
|
79
83
|
div_contains_text? "text" #<element_tag>_contains_text? "text"
|
80
84
|
```
|
85
|
+
|
86
|
+
## Popup actions
|
87
|
+
|
88
|
+
```ruby
|
89
|
+
confirm_popup # can be used for both confirmation boxed and alert boxes
|
90
|
+
dismiss_popup
|
91
|
+
popup_message
|
92
|
+
|
93
|
+
popup_message_contains? "<text>"
|
94
|
+
```
|
95
|
+
|
96
|
+
## Capturing screenshots
|
97
|
+
|
98
|
+
```ruby
|
99
|
+
capture_screen
|
100
|
+
capture_screen "<file>"
|
101
|
+
```
|
data/Rakefile
ADDED
@@ -1,53 +1,66 @@
|
|
1
|
-
|
2
|
-
require_relative '
|
3
|
-
require_relative 'match'
|
1
|
+
require 'capybara/dsl'
|
2
|
+
require_relative 'actions'
|
4
3
|
require_relative 'exceptions'
|
5
4
|
|
6
5
|
module Prickle
|
7
6
|
module Capybara
|
8
7
|
class Element
|
9
8
|
|
10
|
-
require 'capybara/dsl'
|
11
9
|
include ::Capybara::DSL
|
12
10
|
|
13
|
-
|
11
|
+
OF_ANY_TYPE = "*"
|
12
|
+
CONVERTED_TYPES = { :link => 'a',
|
13
|
+
:paragraph => 'p'
|
14
|
+
}
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def initialize type=OF_ANY_TYPE, identifier
|
14
19
|
@identifier = identifier
|
15
20
|
@type = type
|
16
21
|
self
|
17
22
|
end
|
18
23
|
|
24
|
+
def find_element
|
25
|
+
handle_exception { find_element_by xpath }
|
26
|
+
end
|
27
|
+
|
28
|
+
def find_element_by xpath
|
29
|
+
wait_until(Prickle::Capybara.wait_time) do
|
30
|
+
find(:xpath, xpath).visible?
|
31
|
+
end unless Prickle::Capybara.wait_time.nil?
|
32
|
+
|
33
|
+
find(:xpath, xpath)
|
34
|
+
end
|
35
|
+
|
19
36
|
def handle_exception &block
|
20
37
|
begin
|
21
38
|
block.call
|
22
39
|
rescue Exception => e
|
23
|
-
|
40
|
+
error_message = Error.new(@type, @identifier, @text, e).message
|
41
|
+
raise ElementNotFound, error_message if e.class.to_s == "Capybara::ElementNotFound"
|
24
42
|
raise
|
25
43
|
end
|
26
44
|
end
|
27
45
|
|
28
46
|
def identifier
|
29
|
-
return @identifier.each_pair.to_a.map
|
30
|
-
"@#{key}='#{value}'"
|
31
|
-
end.join ' and '
|
47
|
+
return @identifier.each_pair.to_a.map { |k, v| "@#{k}='#{v}'" }.join " and "
|
32
48
|
end
|
33
49
|
|
34
|
-
def
|
35
|
-
|
36
|
-
find(:xpath, xpath).visible?
|
37
|
-
end unless Prickle::Capybara.wait_time.nil?
|
38
|
-
|
39
|
-
find(:xpath, xpath)
|
50
|
+
def type
|
51
|
+
CONVERTED_TYPES[@type.to_sym] || @type
|
40
52
|
end
|
41
53
|
|
42
|
-
def
|
43
|
-
|
54
|
+
def xpath
|
55
|
+
xpath = "//#{type}[#{identifier}"
|
56
|
+
xpath << " and contains(text(), '#{@text}')" if @text
|
57
|
+
xpath << "]"
|
44
58
|
end
|
45
59
|
|
46
|
-
|
47
|
-
include Prickle::Actions::Match
|
48
|
-
include Prickle::Actions::Click
|
60
|
+
public
|
49
61
|
|
50
|
-
|
62
|
+
include Prickle::Capybara::Actions
|
51
63
|
|
64
|
+
end
|
52
65
|
end
|
53
66
|
end
|
@@ -3,9 +3,11 @@ module Prickle
|
|
3
3
|
|
4
4
|
class ElementNotFound < Exception; end;
|
5
5
|
|
6
|
+
class MessageNotContainedInPopup < Exception; end;
|
7
|
+
|
6
8
|
class Error
|
7
9
|
|
8
|
-
def initialize type, identifier, text, caught_exception
|
10
|
+
def initialize type=nil, identifier=nil, text=nil, caught_exception=nil
|
9
11
|
@element_type = type
|
10
12
|
@element_identifier = identifier
|
11
13
|
@element_text = text
|
@@ -16,6 +18,10 @@ module Prickle
|
|
16
18
|
"#{element_text} with properties #{identifier} #{text_string} was not found.\n\tError: #{@caught_exception.message}"
|
17
19
|
end
|
18
20
|
|
21
|
+
def not_contained_in_popup message
|
22
|
+
"Text #{highlight(message)} is not contained in the popup."
|
23
|
+
end
|
24
|
+
|
19
25
|
private
|
20
26
|
|
21
27
|
def element_text
|
@@ -35,5 +41,6 @@ module Prickle
|
|
35
41
|
"\e[1m#{text}\e[0m\e[31m"
|
36
42
|
end
|
37
43
|
end
|
44
|
+
|
38
45
|
end
|
39
46
|
end
|
data/lib/prickle/capybara.rb
CHANGED
@@ -1,27 +1,43 @@
|
|
1
1
|
require_relative 'capybara/element'
|
2
2
|
|
3
3
|
module Prickle
|
4
|
-
TAGS = { :link => 'a',
|
5
|
-
:paragraph => 'p'
|
6
|
-
}
|
7
|
-
|
8
4
|
module Capybara
|
9
5
|
|
10
6
|
class << self
|
11
|
-
attr_accessor :wait_time
|
7
|
+
attr_accessor :wait_time, :image_dir
|
8
|
+
|
9
|
+
end
|
10
|
+
|
11
|
+
def capture_screen name=Time.now.strftime("%Y%m%d-%H.%M.%s")
|
12
|
+
page.driver.browser.save_screenshot Capybara.image_dir + name + ".jpg"
|
13
|
+
end
|
12
14
|
|
15
|
+
def click_by_name name
|
16
|
+
find_by_name(name).click
|
13
17
|
end
|
14
18
|
|
15
|
-
def
|
19
|
+
def confirm_popup
|
20
|
+
page.driver.browser.switch_to.alert.accept
|
21
|
+
end
|
22
|
+
|
23
|
+
def dismiss_popup
|
24
|
+
page.driver.browser.switch_to.alert.dismiss
|
25
|
+
end
|
26
|
+
|
27
|
+
def element type=Element::OF_ANY_TYPE, identifier
|
16
28
|
Element.new type, identifier
|
17
29
|
end
|
18
30
|
|
19
|
-
def find_by_name type=
|
31
|
+
def find_by_name type=Element::OF_ANY_TYPE, name
|
20
32
|
element(type, :name => name).exists?
|
21
33
|
end
|
22
34
|
|
23
|
-
def
|
24
|
-
|
35
|
+
def popup_message
|
36
|
+
page.driver.browser.switch_to.alert.text
|
37
|
+
end
|
38
|
+
|
39
|
+
def popup_message_contains? message
|
40
|
+
raise Capybara::MessageNotContainedInPopup, Error.new.not_contained_in_popup(message) unless popup_message.eql? message
|
25
41
|
end
|
26
42
|
|
27
43
|
private
|
data/lib/prickle/version.rb
CHANGED
data/prickle.gemspec
CHANGED
@@ -24,6 +24,7 @@ Gem::Specification.new do |s|
|
|
24
24
|
s.add_development_dependency "capybara"
|
25
25
|
s.add_development_dependency "rspec", "~> 2.8.0"
|
26
26
|
s.add_development_dependency "sinatra", "~> 1.3.2"
|
27
|
+
s.add_development_dependency "rake"
|
27
28
|
s.add_development_dependency "reek"
|
28
29
|
end
|
29
30
|
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Prickle::Capybara do
|
4
|
+
let(:prickly) { Prickly.new }
|
5
|
+
|
6
|
+
before do
|
7
|
+
Capybara.default_driver = :selenium
|
8
|
+
Prickle::Capybara.wait_time = nil
|
9
|
+
end
|
10
|
+
|
11
|
+
before(:each) do
|
12
|
+
prickly.visit '/'
|
13
|
+
end
|
14
|
+
|
15
|
+
context 'Managing popups', :javascript => true do
|
16
|
+
|
17
|
+
it 'can confirm an alert box' do
|
18
|
+
prickly.click_by_name 'popups'
|
19
|
+
prickly.confirm_popup
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'can confirm a popup' do
|
23
|
+
prickly.click_by_name 'confirm_box'
|
24
|
+
prickly.confirm_popup
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'can dismiss a popup' do
|
28
|
+
prickly.click_by_name 'confirm_box'
|
29
|
+
prickly.dismiss_popup
|
30
|
+
prickly.popup_message.should eq "Aborting."
|
31
|
+
prickly.confirm_popup
|
32
|
+
end
|
33
|
+
|
34
|
+
context "matching text" do
|
35
|
+
it "can verify the content of a popup" do
|
36
|
+
prickly.click_by_name "popups"
|
37
|
+
prickly.popup_message_contains? "Hello"
|
38
|
+
prickly.dismiss_popup
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
context 'Screenshots', :javascript => true do
|
44
|
+
|
45
|
+
it 'can capture the screen' do
|
46
|
+
screenshot_name = Time.now.strftime("%Y%m%d-%H.%M.%s")
|
47
|
+
prickly.capture_screen screenshot_name
|
48
|
+
`ls #{Prickle::Capybara.image_dir}`.should include "#{screenshot_name}"
|
49
|
+
end
|
50
|
+
|
51
|
+
after do
|
52
|
+
`rm -f #{Prickle::Capybara.image_dir}/*.jpg`
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Prickle::Capybara::Element do
|
4
|
+
let(:prickly) { Prickly.new }
|
5
|
+
|
6
|
+
before do
|
7
|
+
prickly.visit '/'
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'can find an element' do
|
11
|
+
prickly.element(:name => 'blue').class.to_s.should == "Prickle::Capybara::Element"
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'can match text in an element' do
|
15
|
+
prickly.element(:name => 'yellow').contains_text? "Hello!"
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'can match text in specific elements' do
|
19
|
+
prickly.element(:li, :name => 'purple').contains_text? "Im not purple!"
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'can match on link type elements' do
|
23
|
+
prickly.element(:link, :name => 'orangey').contains_text? "Me too!"
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'can click specific element types by name' do
|
27
|
+
prickly.element(:paragraph, :name => 'yellow').click
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'can find an element by type and identifier' do
|
31
|
+
prickly.element(:paragraph, :id => 'coffee').exists?
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'can find and click on element by type and identifier' do
|
35
|
+
prickly.element(:link, :href => 'http://google.com').click
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'can find an element by multiple identifiers' do
|
39
|
+
prickly.element(:name => 'orangey', :class => 'pink').contains_text? "Blue hippos"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
data/spec/extended_wait_spec.rb
CHANGED
@@ -5,11 +5,10 @@ describe Prickle::Capybara do
|
|
5
5
|
|
6
6
|
before do
|
7
7
|
Capybara.default_driver = :selenium
|
8
|
-
prickly.extend Prickle::Capybara
|
9
8
|
prickly.visit '/'
|
10
9
|
end
|
11
10
|
|
12
|
-
context 'Extended waits' do
|
11
|
+
context 'Extended waits', :javascript => true do
|
13
12
|
|
14
13
|
before(:each) do
|
15
14
|
Prickle::Capybara.wait_time = nil
|
data/spec/finders_spec.rb
CHANGED
@@ -4,8 +4,6 @@ describe Prickle::Capybara do
|
|
4
4
|
let(:prickly) { Prickly.new }
|
5
5
|
|
6
6
|
before do
|
7
|
-
Capybara.default_driver = :rack_test
|
8
|
-
prickly.extend Prickle::Capybara
|
9
7
|
prickly.visit '/'
|
10
8
|
end
|
11
9
|
|
@@ -58,38 +56,4 @@ describe Prickle::Capybara do
|
|
58
56
|
prickly.paragraph_contains_text? "yellow", "Hello!"
|
59
57
|
end
|
60
58
|
end
|
61
|
-
|
62
|
-
context 'DSL' do
|
63
|
-
it 'can find an element' do
|
64
|
-
prickly.element(:name => 'blue').class.to_s.should == "Prickle::Capybara::Element"
|
65
|
-
end
|
66
|
-
|
67
|
-
it 'can match text in an element' do
|
68
|
-
prickly.element(:name => 'yellow').contains_text? "Hello!"
|
69
|
-
end
|
70
|
-
|
71
|
-
it 'can match text in specific elements' do
|
72
|
-
prickly.element(:li, :name => 'purple').contains_text? "Im not purple!"
|
73
|
-
end
|
74
|
-
|
75
|
-
it 'can match on link type elements' do
|
76
|
-
prickly.element(:link, :name => 'orangey').contains_text? "Me too!"
|
77
|
-
end
|
78
|
-
|
79
|
-
it 'can click specific element types by name' do
|
80
|
-
prickly.element(:paragraph, :name => 'yellow').click
|
81
|
-
end
|
82
|
-
|
83
|
-
it 'can find an element by type and identifier' do
|
84
|
-
prickly.element(:paragraph, :id => 'coffee').exists?
|
85
|
-
end
|
86
|
-
|
87
|
-
it 'can find and click on element by type and identifier' do
|
88
|
-
prickly.element(:link, :href => 'http://google.com').click
|
89
|
-
end
|
90
|
-
|
91
|
-
it 'can find an element by multiple identifiers' do
|
92
|
-
prickly.element(:name => 'orangey', :class => 'pink').contains_text? "Blue hippos"
|
93
|
-
end
|
94
|
-
end
|
95
59
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -5,9 +5,11 @@ require 'prickle/capybara'
|
|
5
5
|
|
6
6
|
class Prickly
|
7
7
|
include Capybara::DSL
|
8
|
+
include Prickle::Capybara
|
8
9
|
|
9
10
|
end
|
10
11
|
|
11
12
|
require_relative 'stub/app'
|
12
13
|
Capybara.app = Sinatra::Application
|
13
14
|
Capybara.default_wait_time = 0
|
15
|
+
Prickle::Capybara.image_dir = File.dirname(__FILE__) + "/tmp/"
|
data/spec/stub/index.html
CHANGED
@@ -19,6 +19,11 @@
|
|
19
19
|
<p id='coffee'>Capuccino</p>
|
20
20
|
|
21
21
|
<a href="http://google.com">google</a>
|
22
|
+
|
23
|
+
<button name="popups" onclick="alert('Hello');">erm</button>
|
24
|
+
|
25
|
+
<button name="confirm_box" onclick="if(!confirm('Click yes to continue'))alert('Aborting.');">erm</button>
|
26
|
+
|
22
27
|
<script>
|
23
28
|
$(document).ready(function() {
|
24
29
|
$('.hidden').hide();
|
data/spec/tmp/.keep_me
ADDED
File without changes
|
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.3
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Despo Pentara
|
@@ -58,7 +58,7 @@ dependencies:
|
|
58
58
|
type: :development
|
59
59
|
version_requirements: *id004
|
60
60
|
- !ruby/object:Gem::Dependency
|
61
|
-
name:
|
61
|
+
name: rake
|
62
62
|
prerelease: false
|
63
63
|
requirement: &id005 !ruby/object:Gem::Requirement
|
64
64
|
none: false
|
@@ -68,6 +68,17 @@ dependencies:
|
|
68
68
|
version: "0"
|
69
69
|
type: :development
|
70
70
|
version_requirements: *id005
|
71
|
+
- !ruby/object:Gem::Dependency
|
72
|
+
name: reek
|
73
|
+
prerelease: false
|
74
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
75
|
+
none: false
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: "0"
|
80
|
+
type: :development
|
81
|
+
version_requirements: *id006
|
71
82
|
description: A simple DSL wrapped around Capybara for matching elements using html tags.
|
72
83
|
email: despo@extractmethod.com
|
73
84
|
executables: []
|
@@ -78,23 +89,26 @@ extra_rdoc_files: []
|
|
78
89
|
|
79
90
|
files:
|
80
91
|
- .rvmrc
|
92
|
+
- .travis.yml
|
81
93
|
- Gemfile
|
82
94
|
- Gemfile.lock
|
83
95
|
- README.md
|
96
|
+
- Rakefile
|
84
97
|
- lib/prickle/capybara.rb
|
85
|
-
- lib/prickle/capybara/
|
98
|
+
- lib/prickle/capybara/actions.rb
|
86
99
|
- lib/prickle/capybara/element.rb
|
87
100
|
- lib/prickle/capybara/exceptions.rb
|
88
|
-
- lib/prickle/capybara/find.rb
|
89
|
-
- lib/prickle/capybara/match.rb
|
90
101
|
- lib/prickle/version.rb
|
91
102
|
- prickle.gemspec
|
92
103
|
- prickle.png
|
104
|
+
- spec/capybara_spec.rb
|
105
|
+
- spec/element_spec.rb
|
93
106
|
- spec/extended_wait_spec.rb
|
94
107
|
- spec/finders_spec.rb
|
95
108
|
- spec/spec_helper.rb
|
96
109
|
- spec/stub/app.rb
|
97
110
|
- spec/stub/index.html
|
111
|
+
- spec/tmp/.keep_me
|
98
112
|
has_rdoc: true
|
99
113
|
homepage: https://github.com/ExtractMethod/prickle
|
100
114
|
licenses:
|
@@ -1,35 +0,0 @@
|
|
1
|
-
module Prickle
|
2
|
-
module Actions
|
3
|
-
module Match
|
4
|
-
|
5
|
-
def contains_text? text
|
6
|
-
handle_exception do
|
7
|
-
find_element_by_identifier_and_text
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
private
|
12
|
-
|
13
|
-
def xpath_for_identifier
|
14
|
-
"//#{type_of(@type)}[#{identifier}]"
|
15
|
-
end
|
16
|
-
|
17
|
-
def xpath_for_identifier_and_text
|
18
|
-
"//#{type_of(@type)}[#{identifier} and contains(text(), '#{@text}')]"
|
19
|
-
|
20
|
-
end
|
21
|
-
def find_element_by_identifier
|
22
|
-
handle_exception do
|
23
|
-
find_element_by xpath_for_identifier
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
def find_element_by_identifier_and_text
|
28
|
-
handle_exception do
|
29
|
-
find_element_by xpath_for_identifier_and_text
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|