send-keys 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +17 -0
- data/VERSION +1 -0
- data/lib/send-keys.rb +2 -0
- data/lib/send-keys/step_definitions/send_keys_steps.rb +12 -0
- data/lib/send-keys/support/send_keys.rb +69 -0
- data/readme.mdown +61 -0
- data/send-keys.gemspec +46 -0
- metadata +86 -0
data/Rakefile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
begin
|
2
|
+
require 'jeweler'
|
3
|
+
Jeweler::Tasks.new do |s|
|
4
|
+
s.name = "send-keys"
|
5
|
+
s.summary = "Simulate key presses in your capybara tests"
|
6
|
+
s.email = "mark@aussiev8.com.au"
|
7
|
+
s.homepage = "http://github.com/markgandolfo/send-keys"
|
8
|
+
s.description = "Provides cucumber steps and methods to send key presses to DOM Elements with your Capybara tests."
|
9
|
+
s.authors = ["Mark Gandolfo"]
|
10
|
+
s.files = FileList["[A-Z]*", "{lib}/**/*"]
|
11
|
+
s.files.exclude('*.komodoproject')
|
12
|
+
|
13
|
+
s.add_dependency 'capybara'
|
14
|
+
end
|
15
|
+
rescue LoadError
|
16
|
+
puts "Jeweler, or one of its dependencies, is not available. Install it with: sudo gem install jeweler"
|
17
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/lib/send-keys.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
## Possible Keys
|
2
|
+
# :null, :cancel, :help, :backspace, :tab, :clear, :return, :enter, :shift, :left_shift, :control, :left_control :alt, :left_alt, :pause,
|
3
|
+
# :escape, :space:page_up, :page_down, :end, :home, :left, :arrow_left, :up:arrow_up, :right, :arrow_right:down, :arrow_down, :insert,
|
4
|
+
# :delete, :semicolon, :equals, :numpad0, :numpad1, :numpad2, :numpad3, :numpad4, :numpad5, :numpad6, :numpad7, :numpad8, :numpad9,
|
5
|
+
# :multiply, :add, :separator, :subtract, :decimal, :divide
|
6
|
+
#
|
7
|
+
|
8
|
+
# And I send "hello" to "#element"
|
9
|
+
# And /^I send (#{allowed_keys.join('|')}) to "([^\"]*)"$/ do |key, element|
|
10
|
+
And /^I send (.*) to "(.*)"$/ do |key, element|
|
11
|
+
find(element).send_string_of_keys(key)
|
12
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
module SendKeys
|
2
|
+
def allowed_keys
|
3
|
+
@allowed_keys ||= %w(
|
4
|
+
option
|
5
|
+
null
|
6
|
+
cancel
|
7
|
+
help
|
8
|
+
backspace
|
9
|
+
tab
|
10
|
+
clear
|
11
|
+
return
|
12
|
+
enter
|
13
|
+
shift
|
14
|
+
left_shift
|
15
|
+
control
|
16
|
+
left_control
|
17
|
+
alt
|
18
|
+
left_alt
|
19
|
+
pause
|
20
|
+
escape
|
21
|
+
space
|
22
|
+
page_up
|
23
|
+
page_down
|
24
|
+
end
|
25
|
+
home
|
26
|
+
left
|
27
|
+
arrow_left
|
28
|
+
uparrow_up
|
29
|
+
right
|
30
|
+
arrow_rightdown
|
31
|
+
arrow_down
|
32
|
+
insert
|
33
|
+
delete
|
34
|
+
semicolon
|
35
|
+
equals
|
36
|
+
numpad0 numpad1 numpad2 numpad3 numpad4 numpad5 numpad6 numpad7 numpad8 numpad9
|
37
|
+
multiplyadd
|
38
|
+
separator
|
39
|
+
subtract
|
40
|
+
decimal
|
41
|
+
divide
|
42
|
+
f1 f2 f3 f4 f5 f6 f7 f8 f9 f10 f11 f12
|
43
|
+
).index_by {|k|k}
|
44
|
+
end
|
45
|
+
|
46
|
+
def send_string_of_keys(key)
|
47
|
+
send_key = []
|
48
|
+
|
49
|
+
if matches = key.match(%r{^\[(.*)\]$})
|
50
|
+
key = matches[1].split(',').map(&:strip)
|
51
|
+
else
|
52
|
+
key = [key]
|
53
|
+
end
|
54
|
+
|
55
|
+
key.each do |k|
|
56
|
+
if matches = k.match(%r{^['"](.*)['"]$})
|
57
|
+
send_key << matches[1]
|
58
|
+
elsif allowed_keys.has_key?(k)
|
59
|
+
send_key << k.to_sym
|
60
|
+
else
|
61
|
+
send_key << k.to_s
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
node.send_keys(send_key)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
Capybara::Node.send :include, SendKeys
|
data/readme.mdown
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
## Send Keys ##
|
2
|
+
|
3
|
+
Send keys is a capybara extension that lets you send keystrokes to an element in the browser. It uses webdriver so must be used using the `@javascript` tag in your features.
|
4
|
+
|
5
|
+
### Installation ###
|
6
|
+
|
7
|
+
Check out the repo `git clone git@github.commarkgandolfo/send-keys.git` and put the step_definitions/send_keys_steps.rb into your step_definitions directory and copy support/send_keys.rb to your support directory.
|
8
|
+
|
9
|
+
### Why would you need this ###
|
10
|
+
|
11
|
+
Some javascript events only respond to key presses, and at the moment capybara doesn't support the functionality required to pull this off. For example, we wanted to test a text-completion form, where a user was able to start typing a word, and our application would show a list of possible options. With the generic fill_in method this didn't work. This is just one of the many use cases.
|
12
|
+
|
13
|
+
### How to use it ###
|
14
|
+
|
15
|
+
First make sure you use the @javascript tag, to force capybara to use the webdriver driver.
|
16
|
+
|
17
|
+
Then in your features you can send characters or modifier keys to an element, or an array of modifier keys and keys.
|
18
|
+
You'll need to use the css selectors to select an element.
|
19
|
+
|
20
|
+
For Example
|
21
|
+
|
22
|
+
# Send the 'a' character to the input who's id is search (#search)
|
23
|
+
And I send a to "input#search"
|
24
|
+
|
25
|
+
# Send the 'a', 'b' and 'c' characters to the input who's id is search (#search)
|
26
|
+
And I send abc to "input#search"
|
27
|
+
|
28
|
+
# You can put them in quotes if you feel more comfortable
|
29
|
+
And I send 'abc' to "input#search"
|
30
|
+
|
31
|
+
# You can also send modifier/special key strokes to an element
|
32
|
+
And I send arrow_left to "input#search"
|
33
|
+
|
34
|
+
# You can even send a combination of modifier and characters
|
35
|
+
# This will result in a the character 'A' being sent to the input
|
36
|
+
And I send [shift, a] to "input#search"
|
37
|
+
|
38
|
+
# Or maybe you just want to press enter
|
39
|
+
And I send enter to "input#search"
|
40
|
+
|
41
|
+
# How cool would it be to test the counter in a text area (say for a twitter app)
|
42
|
+
And I send hello to "#message"
|
43
|
+
And I should see "135" in "characters_left"
|
44
|
+
And I send backspace to "#message"
|
45
|
+
And I should see "136" in "characters_left"
|
46
|
+
|
47
|
+
# We used it to test completion suggestions
|
48
|
+
# The first suggested name was highlighted and responded to an enter keypress
|
49
|
+
And I send "bo" to "input#username"
|
50
|
+
And I should see "bob" within "username_suggestions"
|
51
|
+
And I send enter to "input#username"
|
52
|
+
|
53
|
+
#### List of modifiers/special keys ####
|
54
|
+
|
55
|
+
There are a list of modifier and special keys which can be sent to an element
|
56
|
+
|
57
|
+
`null, cancel, help, backspace, tab, clear, return, enter, shift, left_shift, control, left_control alt, left_alt, pause, escape, space, page_up, page_down, end, home, left, arrow_left, uparrow_up, right, arrow_rightdown, arrow_down, insert, delete, semicolon, equals, numpad0, numpad1, numpad2, numpad3, numpad4, numpad5, numpad6, numpad7, numpad8, numpad9, multiply, add, separator, subtract, decimal, divide, f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12`
|
58
|
+
|
59
|
+
##### Please note #####
|
60
|
+
|
61
|
+
Different OS' have different ways of simulating modifier keys, as a result not all will work on MacOSX, for example tab will not work. When I have some time I'll patch webdriver to support these keys.
|
data/send-keys.gemspec
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{send-keys}
|
8
|
+
s.version = "0.1.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Mark Gandolfo"]
|
12
|
+
s.date = %q{2010-10-30}
|
13
|
+
s.description = %q{Provides cucumber steps and methods to send key presses to DOM Elements with your Capybara tests.}
|
14
|
+
s.email = %q{mark@aussiev8.com.au}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"readme.mdown"
|
17
|
+
]
|
18
|
+
s.files = [
|
19
|
+
"Rakefile",
|
20
|
+
"VERSION",
|
21
|
+
"lib/send-keys.rb",
|
22
|
+
"lib/send-keys/step_definitions/send_keys_steps.rb",
|
23
|
+
"lib/send-keys/support/send_keys.rb",
|
24
|
+
"readme.mdown",
|
25
|
+
"send-keys.gemspec"
|
26
|
+
]
|
27
|
+
s.homepage = %q{http://github.com/markgandolfo/send-keys}
|
28
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
29
|
+
s.require_paths = ["lib"]
|
30
|
+
s.rubygems_version = %q{1.3.6}
|
31
|
+
s.summary = %q{Simulate key presses in your capybara tests}
|
32
|
+
|
33
|
+
if s.respond_to? :specification_version then
|
34
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
35
|
+
s.specification_version = 3
|
36
|
+
|
37
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
38
|
+
s.add_runtime_dependency(%q<capybara>, [">= 0"])
|
39
|
+
else
|
40
|
+
s.add_dependency(%q<capybara>, [">= 0"])
|
41
|
+
end
|
42
|
+
else
|
43
|
+
s.add_dependency(%q<capybara>, [">= 0"])
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
metadata
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: send-keys
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Mark Gandolfo
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-10-30 00:00:00 +10:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: capybara
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
version: "0"
|
33
|
+
type: :runtime
|
34
|
+
version_requirements: *id001
|
35
|
+
description: Provides cucumber steps and methods to send key presses to DOM Elements with your Capybara tests.
|
36
|
+
email: mark@aussiev8.com.au
|
37
|
+
executables: []
|
38
|
+
|
39
|
+
extensions: []
|
40
|
+
|
41
|
+
extra_rdoc_files:
|
42
|
+
- readme.mdown
|
43
|
+
files:
|
44
|
+
- Rakefile
|
45
|
+
- VERSION
|
46
|
+
- lib/send-keys.rb
|
47
|
+
- lib/send-keys/step_definitions/send_keys_steps.rb
|
48
|
+
- lib/send-keys/support/send_keys.rb
|
49
|
+
- readme.mdown
|
50
|
+
- send-keys.gemspec
|
51
|
+
has_rdoc: true
|
52
|
+
homepage: http://github.com/markgandolfo/send-keys
|
53
|
+
licenses: []
|
54
|
+
|
55
|
+
post_install_message:
|
56
|
+
rdoc_options:
|
57
|
+
- --charset=UTF-8
|
58
|
+
require_paths:
|
59
|
+
- lib
|
60
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ">="
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
hash: 3
|
66
|
+
segments:
|
67
|
+
- 0
|
68
|
+
version: "0"
|
69
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
|
+
none: false
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
hash: 3
|
75
|
+
segments:
|
76
|
+
- 0
|
77
|
+
version: "0"
|
78
|
+
requirements: []
|
79
|
+
|
80
|
+
rubyforge_project:
|
81
|
+
rubygems_version: 1.3.7
|
82
|
+
signing_key:
|
83
|
+
specification_version: 3
|
84
|
+
summary: Simulate key presses in your capybara tests
|
85
|
+
test_files: []
|
86
|
+
|