simple-send-keys 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Readme.md +46 -0
- data/lib/simple_send_keys.rb +73 -0
- data/simple-send-keys.gemspec +41 -0
- metadata +128 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 7c7b6b0f56bd1d7bb4eb7dfec155fea5829da32e
|
4
|
+
data.tar.gz: 61231d920567dc369b6a4b36b3fb3be937617f42
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b25b552fd434bddf5bf34fd666d2fee0698205d97523502fdbf35bdb55f381d95172ac5d8a57c46f75360a82d39378dbbb5bc60088b0aeccf86b0f00707d77da
|
7
|
+
data.tar.gz: 6d908be658f291bc5d42d07ac29bd9d15aa36aaeb7a9520deea1a88b6d0d9ed4824caa25cd05c193bfd8f63de73b48da7e45deaeae14df539f89f71a53d5c040
|
data/Readme.md
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
## Send Keys ##
|
2
|
+
|
3
|
+
[![Build Status](https://api.travis-ci.org/leriksen/simple-send-keys.png?branch=master)](http://travis-ci.org/leriksen/simple-send-keys)
|
4
|
+
|
5
|
+
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.
|
6
|
+
|
7
|
+
This gem is based heavily off send-keys, but with less assumptions. send-keys assumes you are using Cucumber and Rails, simple_send_keys does not, it only assumes you're using Capybara.
|
8
|
+
|
9
|
+
### Installation ###
|
10
|
+
|
11
|
+
In your Gemfile
|
12
|
+
```ruby
|
13
|
+
gem 'simple-send-keys'
|
14
|
+
```
|
15
|
+
|
16
|
+
Then in your test
|
17
|
+
```ruby
|
18
|
+
require 'simple_send_keys'
|
19
|
+
```
|
20
|
+
|
21
|
+
### Why would you need this ###
|
22
|
+
|
23
|
+
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.
|
24
|
+
|
25
|
+
### How to use it ###
|
26
|
+
|
27
|
+
First make sure you have capybara configured to use a javascript-capable driver.
|
28
|
+
|
29
|
+
Then in your test you can send characters or modifier keys to an element, or an array of modifier keys and keys.
|
30
|
+
|
31
|
+
For Example
|
32
|
+
```ruby
|
33
|
+
find("input#search").send_keys('gist')
|
34
|
+
find("input#search").send_keys('[backspace, "gist", f1 , 123]')
|
35
|
+
find("input#search").send_keys('[shift, a]')'
|
36
|
+
```
|
37
|
+
|
38
|
+
#### List of modifiers/special keys ####
|
39
|
+
|
40
|
+
There are a list of modifier and special keys which can be sent to an element
|
41
|
+
|
42
|
+
`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, up, arrow_up, right, arrow_right, down, 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`
|
43
|
+
|
44
|
+
##### Please note #####
|
45
|
+
|
46
|
+
Different OS' have different ways of simulating modifier keys, as a result not all will work on MacOSX, for example tab may not work. Patch your webdriver to support these keys.
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'capybara'
|
2
|
+
|
3
|
+
module SimpleSendKeys
|
4
|
+
def allowed_keys
|
5
|
+
@allowed_keys ||= %w(
|
6
|
+
option
|
7
|
+
null
|
8
|
+
cancel
|
9
|
+
help
|
10
|
+
backspace
|
11
|
+
tab
|
12
|
+
clear
|
13
|
+
return
|
14
|
+
enter
|
15
|
+
shift
|
16
|
+
left_shift
|
17
|
+
control
|
18
|
+
left_control
|
19
|
+
alt
|
20
|
+
left_alt
|
21
|
+
pause
|
22
|
+
escape
|
23
|
+
space
|
24
|
+
page_up
|
25
|
+
page_down
|
26
|
+
end
|
27
|
+
home
|
28
|
+
left
|
29
|
+
arrow_left
|
30
|
+
up
|
31
|
+
arrow_up
|
32
|
+
right
|
33
|
+
arrow_right
|
34
|
+
down
|
35
|
+
arrow_down
|
36
|
+
insert
|
37
|
+
delete
|
38
|
+
semicolon
|
39
|
+
equals
|
40
|
+
numpad0 numpad1 numpad2 numpad3 numpad4 numpad5 numpad6 numpad7 numpad8 numpad9
|
41
|
+
multiplyadd
|
42
|
+
separator
|
43
|
+
subtract
|
44
|
+
decimal
|
45
|
+
divide
|
46
|
+
f1 f2 f3 f4 f5 f6 f7 f8 f9 f10 f11 f12
|
47
|
+
).each_with_index.to_h
|
48
|
+
end
|
49
|
+
|
50
|
+
def send_keys(keys)
|
51
|
+
keys_to_send = []
|
52
|
+
|
53
|
+
if matches = keys.match(%r{^\[(.*)\]$})
|
54
|
+
keys = matches[1].split(',').map(&:strip)
|
55
|
+
else
|
56
|
+
keys = [keys]
|
57
|
+
end
|
58
|
+
|
59
|
+
keys.each do |k|
|
60
|
+
if matches = k.match(%r{^['"](.*)['"]$})
|
61
|
+
keys_to_send << matches[1]
|
62
|
+
elsif allowed_keys.has_key?(k)
|
63
|
+
keys_to_send << k.to_sym
|
64
|
+
else
|
65
|
+
keys_to_send << k.to_s
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
native.send_keys(keys_to_send)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
Capybara::Node::Base.send :include, SimpleSendKeys
|
@@ -0,0 +1,41 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
# info
|
3
|
+
s.platform = Gem::Platform::RUBY
|
4
|
+
s.name = 'simple-send-keys'
|
5
|
+
s.version = '0.0.1'
|
6
|
+
s.authors = ['Leif Eriksen']
|
7
|
+
s.date = '2015-07-12'
|
8
|
+
s.license = 'MIT'
|
9
|
+
s.description = 'fork of send-keys with less assumptions, while we wait for capybara-2.5.x.'
|
10
|
+
s.email = 'leif.eriksen.au@gmail.com'
|
11
|
+
s.homepage = 'http://github.com/leriksen/simple-send-keys'
|
12
|
+
s.summary = 'Simulate key presses in your capybara tests'
|
13
|
+
|
14
|
+
# rdoc
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
'Readme.md'
|
17
|
+
]
|
18
|
+
s.rdoc_options = ['--charset=UTF-8']
|
19
|
+
|
20
|
+
# contents
|
21
|
+
s.files = [
|
22
|
+
'lib/simple_send_keys.rb',
|
23
|
+
'Readme.md',
|
24
|
+
'simple-send-keys.gemspec'
|
25
|
+
]
|
26
|
+
|
27
|
+
# requires
|
28
|
+
s.require_paths = ['lib']
|
29
|
+
|
30
|
+
# dependencies
|
31
|
+
s.add_runtime_dependency('capybara', '>= 2.4.4', '<2.5.0')
|
32
|
+
|
33
|
+
s.add_development_dependency('rake' , '~> 10.4', '>=10.4.2')
|
34
|
+
s.add_development_dependency('rspec', '~> 3.3' , '>=3.3.0' )
|
35
|
+
|
36
|
+
s.add_dependency('bundler', '>= 1.3.0', '< 2.0')
|
37
|
+
|
38
|
+
# tools
|
39
|
+
s.required_ruby_version = '>= 1.9.3'
|
40
|
+
s.required_rubygems_version = '>= 1.8.11'
|
41
|
+
end
|
metadata
ADDED
@@ -0,0 +1,128 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: simple-send-keys
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Leif Eriksen
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-07-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: capybara
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 2.4.4
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 2.5.0
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 2.4.4
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 2.5.0
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: rake
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '10.4'
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: 10.4.2
|
43
|
+
type: :development
|
44
|
+
prerelease: false
|
45
|
+
version_requirements: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - "~>"
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '10.4'
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: 10.4.2
|
53
|
+
- !ruby/object:Gem::Dependency
|
54
|
+
name: rspec
|
55
|
+
requirement: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - "~>"
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '3.3'
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: 3.3.0
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - "~>"
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '3.3'
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: 3.3.0
|
73
|
+
- !ruby/object:Gem::Dependency
|
74
|
+
name: bundler
|
75
|
+
requirement: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: 1.3.0
|
80
|
+
- - "<"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '2.0'
|
83
|
+
type: :runtime
|
84
|
+
prerelease: false
|
85
|
+
version_requirements: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 1.3.0
|
90
|
+
- - "<"
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '2.0'
|
93
|
+
description: fork of send-keys with less assumptions, while we wait for capybara-2.5.x.
|
94
|
+
email: leif.eriksen.au@gmail.com
|
95
|
+
executables: []
|
96
|
+
extensions: []
|
97
|
+
extra_rdoc_files:
|
98
|
+
- Readme.md
|
99
|
+
files:
|
100
|
+
- Readme.md
|
101
|
+
- lib/simple_send_keys.rb
|
102
|
+
- simple-send-keys.gemspec
|
103
|
+
homepage: http://github.com/leriksen/simple-send-keys
|
104
|
+
licenses:
|
105
|
+
- MIT
|
106
|
+
metadata: {}
|
107
|
+
post_install_message:
|
108
|
+
rdoc_options:
|
109
|
+
- "--charset=UTF-8"
|
110
|
+
require_paths:
|
111
|
+
- lib
|
112
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - ">="
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: 1.9.3
|
117
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
118
|
+
requirements:
|
119
|
+
- - ">="
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: 1.8.11
|
122
|
+
requirements: []
|
123
|
+
rubyforge_project:
|
124
|
+
rubygems_version: 2.2.3
|
125
|
+
signing_key:
|
126
|
+
specification_version: 4
|
127
|
+
summary: Simulate key presses in your capybara tests
|
128
|
+
test_files: []
|