Giter Club home page Giter Club logo

send-keys's Introduction

Send Keys

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.

Installation

Check out the repo git clone [email protected]/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.

Why would you need this

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.

How to use it

First make sure you use the @javascript tag, to force capybara to use the webdriver driver.

Then in your features you can send characters or modifier keys to an element, or an array of modifier keys and keys. You'll need to use the css selectors to select an element.

For Example

# Send the 'a' character to the input who's id is search (#search)
And I send a to "input#search"

# Send the 'a', 'b' and 'c' characters to the input who's id is search (#search)
And I send abc to "input#search"

# You can put them in quotes if you feel more comfortable
And I send 'abc' to "input#search"

# You can also send modifier/special key strokes to an element
And I send arrow_left to "input#search"

# You can even send a combination of modifier and characters
# This will result in a the character 'A' being sent to the input
And I send [shift, a] to "input#search"

# Or maybe you just want to press enter
And I send enter to "input#search"

# How cool would it be to test the counter in a text area (say for a twitter app)
And I send hello to "#message"
And I should see "135" in "characters_left"
And I send backspace to "#message"
And I should see "136" in "characters_left"

# We used it to test completion suggestions
# The first suggested name was highlighted and responded to an enter keypress
And I send "bo" to "input#username"
And I should see "bob" within "username_suggestions"
And I send enter to "input#username"

List of modifiers/special keys

There are a list of modifier and special keys which can be sent to an element

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

Please note

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.

send-keys's People

Contributors

danielbeardsley avatar markgandolfo avatar niklas avatar radar avatar zloy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

send-keys's Issues

Simulating shift+click with send-keys?

Hey,

is it possible to do a shift + click using this library? I have something like so:

When I send shift to ".element"
And I click on ".element"

it doesn't work. It seems to do them separately. Any ideas?

Thanks,
Pat

use return instead of clearreturn on OsX/webdriver

Hi Mark,

thank you for your plugin!
"clearreturn" throws an error with OsX10.64/webdriver, but using "return" instead works.

btw. do you see any option to make this work for culerity? When I write
class Capybara::Driver::Celerity < Capybara::Driver::Base
I get this error:

NoMethodError: undefined method `send_keys' for #Celerity::TextField:0x2fb24628 (Culerity::CulerityException)

which probably means, that celerities api is different, right?

-- Frank

Untitled

superclass must be a Class (Module given)
on line
class Node < Capybara::Node

Key* events not triggered

Hi Mark, great work with this plugin!

We've been trying this out (we used the following change to get things running with Capybara 0.4.0 : http://qastuffs.blogspot.com/2010/11/how-to-send-keystrokes-to-element-in.html) with a fairly complex interface which depends on watching keyup events with JQuery. While an input field is content can be sent it seems the keyup event is not triggered and our test fails. Are we missing a trick here or have you any experience with that?

Documentation/code needs updating for capybara 1.0

The instruction point to the wrong git repository

With Capybara 1.0 I found that I need to do this instead of what is in send_keys.rb to make it work

module Capybara
module Node
class Element < Base
include SendKeys
end
end
end

Thanks, Harry

Doesn't work with Rails 4.2

josh@Macbuech:~/Documents/Work/MuheimWebdesign/base/src (features/accessibility *)$ rake
/Users/josh/.rvm/gems/ruby-2.1.0@base/gems/send-keys-0.1.0/lib/send-keys/step_definitions/send_keys_steps.rb:10:in `<top (required)>': undefined method `And' for main:Object (NoMethodError)
    from /Users/josh/.rvm/gems/ruby-2.1.0@base/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:274:in `require'
    from /Users/josh/.rvm/gems/ruby-2.1.0@base/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:274:in `block in require'
    from /Users/josh/.rvm/gems/ruby-2.1.0@base/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:240:in `load_dependency'
    from /Users/josh/.rvm/gems/ruby-2.1.0@base/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:274:in `require'

Can't use send-keys without Cucumber

Since the steps are loaded when the library is loaded, if you don't have the cucumber gem installed, you get an error (And doesn't exist), which makes it impossible to use the library without Cucumber.

Capybara 0.4 compatibility

Hi Mark,

you have a really nice add-on here. But I was using it with Capybara 0.4.0 and got this warning:

Capybara #node is deprecated, please use #native instead

For what I've seen the change is rather simple, so don't even think a patch is necessary:
=> old
node.send_keys(send_key)
=> new
native.send_keys(send_key)

this removes the warning, as far as I can tell. =)

Tks for the add-on! =)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.