henry-dummy 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +78 -0
- data/henry-context.yml +3 -0
- data/henry-dummy.gemspec +28 -0
- data/lib/henry.rb +4 -0
- data/lib/henry/dummy.rb +104 -0
- data/lib/henry/navigator.rb +45 -0
- data/lib/henry/task/dummy_task.rb +46 -0
- metadata +107 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 8f2f19c7501d5088e5b9fc17ce7a19b7327292d7
|
4
|
+
data.tar.gz: 376da1dff63fd957f386854c83274a0ecc31fd75
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0b34fcace3568f495a488ea77680ed875e1ffd0801ec46f09ea34152e86737b96df2581a5caff0257836820aa5703ceddf03f18f9091f34fa7ec7551fab0b0e2
|
7
|
+
data.tar.gz: 0c66b5f914e3a445ea3138f1c37d34dd90335b641daa1921b249ecc0a3dffaa0d1b5f05dc0c3882e5d6dbbd01dc9e2ff86d4d8a819e53cf4e873962aa012aa53
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
henry-dummy (0.0.1)
|
5
|
+
henry-container
|
6
|
+
watir-webdriver
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
ansi (1.4.3)
|
12
|
+
builder (3.2.1)
|
13
|
+
childprocess (0.3.9)
|
14
|
+
ffi (~> 1.0, >= 1.0.11)
|
15
|
+
colorize (0.5.8)
|
16
|
+
cucumber (1.3.2)
|
17
|
+
builder (>= 2.1.2)
|
18
|
+
diff-lcs (>= 1.1.3)
|
19
|
+
gherkin (~> 2.12.0)
|
20
|
+
multi_json (~> 1.3)
|
21
|
+
diff-lcs (1.2.4)
|
22
|
+
ffi (1.8.1)
|
23
|
+
gherkin (2.12.0)
|
24
|
+
multi_json (~> 1.3)
|
25
|
+
hashie (2.0.5)
|
26
|
+
henry-container (0.1.36)
|
27
|
+
colorize
|
28
|
+
cucumber
|
29
|
+
mail
|
30
|
+
minitest-reporters
|
31
|
+
rake
|
32
|
+
rspec (~> 2)
|
33
|
+
trollop
|
34
|
+
mail (2.5.4)
|
35
|
+
mime-types (~> 1.16)
|
36
|
+
treetop (~> 1.4.8)
|
37
|
+
mime-types (1.23)
|
38
|
+
minitest (4.7.4)
|
39
|
+
minitest-reporters (0.14.20)
|
40
|
+
ansi
|
41
|
+
builder
|
42
|
+
minitest (>= 2.12, < 5.0)
|
43
|
+
powerbar
|
44
|
+
multi_json (1.7.4)
|
45
|
+
polyglot (0.3.3)
|
46
|
+
powerbar (1.0.11)
|
47
|
+
ansi (~> 1.4.0)
|
48
|
+
hashie (>= 1.1.0)
|
49
|
+
rake (10.0.4)
|
50
|
+
rspec (2.13.0)
|
51
|
+
rspec-core (~> 2.13.0)
|
52
|
+
rspec-expectations (~> 2.13.0)
|
53
|
+
rspec-mocks (~> 2.13.0)
|
54
|
+
rspec-core (2.13.1)
|
55
|
+
rspec-expectations (2.13.0)
|
56
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
57
|
+
rspec-mocks (2.13.1)
|
58
|
+
rubyzip (0.9.9)
|
59
|
+
selenium-webdriver (2.33.0)
|
60
|
+
childprocess (>= 0.2.5)
|
61
|
+
multi_json (~> 1.0)
|
62
|
+
rubyzip
|
63
|
+
websocket (~> 1.0.4)
|
64
|
+
treetop (1.4.12)
|
65
|
+
polyglot
|
66
|
+
polyglot (>= 0.3.1)
|
67
|
+
trollop (2.0)
|
68
|
+
watir-webdriver (0.6.4)
|
69
|
+
selenium-webdriver (>= 2.18.0)
|
70
|
+
websocket (1.0.7)
|
71
|
+
|
72
|
+
PLATFORMS
|
73
|
+
ruby
|
74
|
+
|
75
|
+
DEPENDENCIES
|
76
|
+
henry-dummy!
|
77
|
+
rake
|
78
|
+
rspec
|
data/henry-context.yml
ADDED
data/henry-dummy.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.authors = ['Roberto Decurnex']
|
3
|
+
s.date = '2013-05-24'
|
4
|
+
s.email = 'decurnex.roberto@gmail.com'
|
5
|
+
s.homepage = 'http://gitorious.despegar.it/henry-self-test/ruby-crash-dummy'
|
6
|
+
s.name = 'henry-dummy'
|
7
|
+
s.summary = 'Henry library to recreate testing scenarios.'
|
8
|
+
s.version = '0.0.2'
|
9
|
+
|
10
|
+
s.require_paths = ['lib']
|
11
|
+
|
12
|
+
s.files = [
|
13
|
+
'Gemfile',
|
14
|
+
'Gemfile.lock',
|
15
|
+
'henry-context.yml',
|
16
|
+
'lib/henry.rb',
|
17
|
+
'lib/henry/dummy.rb',
|
18
|
+
'lib/henry/navigator.rb',
|
19
|
+
'lib/henry/task/dummy_task.rb',
|
20
|
+
'henry-dummy.gemspec'
|
21
|
+
]
|
22
|
+
|
23
|
+
s.add_dependency 'henry-container'
|
24
|
+
s.add_dependency 'watir-webdriver'
|
25
|
+
|
26
|
+
s.add_development_dependency 'rake'
|
27
|
+
s.add_development_dependency 'rspec'
|
28
|
+
end
|
data/lib/henry.rb
ADDED
data/lib/henry/dummy.rb
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
require 'bundler/setup'
|
2
|
+
require 'fileutils'
|
3
|
+
require 'henry/container'
|
4
|
+
|
5
|
+
require_relative 'navigator'
|
6
|
+
require_relative 'task/dummy_task'
|
7
|
+
|
8
|
+
module Henry
|
9
|
+
|
10
|
+
# Henry Dummy class holding methods to emulate testing behaviours.
|
11
|
+
class Dummy
|
12
|
+
|
13
|
+
# Collection of possibleexceptions to be thrown by the #browser method.
|
14
|
+
module BrowserException
|
15
|
+
# Exception thrown whenever the title comparison fails.
|
16
|
+
class TitleMismatch < Exception; end
|
17
|
+
end
|
18
|
+
|
19
|
+
# @param [Henry::Task] task the task to play with.
|
20
|
+
def initialize(task)
|
21
|
+
@task = task
|
22
|
+
end
|
23
|
+
|
24
|
+
# Opens a browser, navigate the given url and asserts the page title.
|
25
|
+
#
|
26
|
+
# @param [String,Symbol] driver the web driver name to be used.
|
27
|
+
# @param [String] url the url to navigate.
|
28
|
+
# @param [String] text the expected title name (or partial name).
|
29
|
+
def browser(driver, url, text)
|
30
|
+
navigator = Henry::Navigator.new(driver)
|
31
|
+
|
32
|
+
title = navigator.navigate(url).title
|
33
|
+
|
34
|
+
navigator.close
|
35
|
+
|
36
|
+
raise BrowserException::TitleMismatch if !title.include?(text)
|
37
|
+
end
|
38
|
+
|
39
|
+
# Produces CPU usage fot the given amount of time.
|
40
|
+
#
|
41
|
+
# @param [Integer] seconds how long the CPU will be used.
|
42
|
+
# @param [Integer] interval amount of CPU cycles before slowing down.
|
43
|
+
def cpu(seconds, interval=nil)
|
44
|
+
Timeout::timeout(seconds) do
|
45
|
+
loop do
|
46
|
+
slow_down(interval) if interval
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
rescue Timeout::Error
|
51
|
+
end
|
52
|
+
|
53
|
+
# Creates a file (and its path) adn writes the given content.
|
54
|
+
#
|
55
|
+
# @param [String] name the file name.
|
56
|
+
# @param [String] path the target file path.
|
57
|
+
# @param [String] content the content to be written in the file content the content to be written in the file.
|
58
|
+
def file(name, path, content)
|
59
|
+
FileUtils.mkpath(path)
|
60
|
+
|
61
|
+
File.open("#{path}/#{name}", 'w') do |file|
|
62
|
+
file.write(content)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
# Overwrites the execution message with the give value.
|
67
|
+
#
|
68
|
+
# @param [String] message the message to set into the execution.
|
69
|
+
def message(message)
|
70
|
+
@task.execution.message = message
|
71
|
+
end
|
72
|
+
|
73
|
+
# Overwrites the execution code with the given value.
|
74
|
+
#
|
75
|
+
# @param [String] code the code to set into the execution.
|
76
|
+
def return_code(code)
|
77
|
+
@task.execution.code = code
|
78
|
+
end
|
79
|
+
|
80
|
+
# Raises an exception
|
81
|
+
def runtime_error
|
82
|
+
raise Exception
|
83
|
+
end
|
84
|
+
|
85
|
+
# Sleeps the process for the given amount for seconds.
|
86
|
+
#
|
87
|
+
# @param [Integer] seconds how long the process will sleep.
|
88
|
+
def sleep(seconds)
|
89
|
+
Kernel.sleep(seconds)
|
90
|
+
end
|
91
|
+
|
92
|
+
private
|
93
|
+
|
94
|
+
# Sleeps the process every interva CPU cycles.
|
95
|
+
#
|
96
|
+
# @param [Integer] interval amount of CPU cycles before sleep should be called.
|
97
|
+
def slow_down(interval)
|
98
|
+
interval.times {}
|
99
|
+
Kernel.sleep(0.99)
|
100
|
+
end
|
101
|
+
|
102
|
+
end
|
103
|
+
|
104
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'watir-webdriver'
|
2
|
+
|
3
|
+
module Henry
|
4
|
+
|
5
|
+
# Defines a common interface for managing bowsers.
|
6
|
+
class Navigator
|
7
|
+
|
8
|
+
def initialize(driver)
|
9
|
+
@driver = driver
|
10
|
+
end
|
11
|
+
|
12
|
+
# Closes the curretn browser
|
13
|
+
def close
|
14
|
+
browser.close
|
15
|
+
end
|
16
|
+
|
17
|
+
# Navigates the given URL
|
18
|
+
#
|
19
|
+
# @param [String] ulr the target URL.
|
20
|
+
# @return [Henry::Navigator] enabling chaining methods.
|
21
|
+
def navigate(url)
|
22
|
+
browser.goto(url)
|
23
|
+
|
24
|
+
return self
|
25
|
+
end
|
26
|
+
|
27
|
+
# Returns the curretn browser title.
|
28
|
+
#
|
29
|
+
# @return [String] the browser title.
|
30
|
+
def title
|
31
|
+
browser.title
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
# Initialze and returns a browser instance.
|
37
|
+
#
|
38
|
+
# @return [Watir::Browser] the browser instance.
|
39
|
+
def browser
|
40
|
+
@browser ||= Watir::Browser.new(@driver)
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module Henry
|
2
|
+
|
3
|
+
class Task
|
4
|
+
|
5
|
+
class DummyTask < Task
|
6
|
+
|
7
|
+
# Configures the Task.
|
8
|
+
#
|
9
|
+
# @param [Hash] params the task params.
|
10
|
+
# @param [Hash] extended_context task extended context.
|
11
|
+
def configure(params, extended_context={})
|
12
|
+
@actions = (params['actions'] || []).collect do |action|
|
13
|
+
OpenStruct.new({
|
14
|
+
command: action['type'].downcase.to_sym,
|
15
|
+
params: action['arguments']
|
16
|
+
})
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
# Process the params and seets the execution params based on them.
|
21
|
+
def execute
|
22
|
+
abort 'You must configure the task before execution.' if @actions.nil?
|
23
|
+
|
24
|
+
dummy = Henry::Dummy.new(self)
|
25
|
+
|
26
|
+
@actions.each do |action|
|
27
|
+
dummy.send(action.command, *action.params)
|
28
|
+
end
|
29
|
+
|
30
|
+
self.execution.code ||= 'OK'
|
31
|
+
self.execution.message ||= 'OK'
|
32
|
+
self.execution.log ||= []
|
33
|
+
self.execution.output ||= 'OK'
|
34
|
+
rescue Exception => e
|
35
|
+
self.execution.code ||= 'ERROR'
|
36
|
+
self.execution.message ||= e.message
|
37
|
+
self.execution.log ||= []
|
38
|
+
self.execution.backtrace ||= e.backtrace
|
39
|
+
self.execution.output ||= 'ERROR'
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
metadata
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: henry-dummy
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Roberto Decurnex
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-05-24 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: henry-container
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: watir-webdriver
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description:
|
70
|
+
email: decurnex.roberto@gmail.com
|
71
|
+
executables: []
|
72
|
+
extensions: []
|
73
|
+
extra_rdoc_files: []
|
74
|
+
files:
|
75
|
+
- Gemfile
|
76
|
+
- Gemfile.lock
|
77
|
+
- henry-context.yml
|
78
|
+
- lib/henry.rb
|
79
|
+
- lib/henry/dummy.rb
|
80
|
+
- lib/henry/navigator.rb
|
81
|
+
- lib/henry/task/dummy_task.rb
|
82
|
+
- henry-dummy.gemspec
|
83
|
+
homepage: http://gitorious.despegar.it/henry-self-test/ruby-crash-dummy
|
84
|
+
licenses: []
|
85
|
+
metadata: {}
|
86
|
+
post_install_message:
|
87
|
+
rdoc_options: []
|
88
|
+
require_paths:
|
89
|
+
- lib
|
90
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - '>='
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - '>='
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
100
|
+
requirements: []
|
101
|
+
rubyforge_project:
|
102
|
+
rubygems_version: 2.0.3
|
103
|
+
signing_key:
|
104
|
+
specification_version: 4
|
105
|
+
summary: Henry library to recreate testing scenarios.
|
106
|
+
test_files: []
|
107
|
+
has_rdoc:
|