Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Touch API #1289

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -19,3 +19,4 @@ chromedriver.log
bundler_stubs
bin
gem-private_key.pem
sauce_connect.log
6 changes: 5 additions & 1 deletion .travis.yml
Expand Up @@ -6,7 +6,7 @@ rvm:
- jruby-19mode
- rbx
gemfile:
- Gemfile
- Gemfile
matrix:
include:
- gemfile: gemfiles/Gemfile.base-versions
Expand All @@ -29,3 +29,7 @@ before_script:
- sh -e /etc/init.d/xvfb start
- export DISPLAY=:99.0
script: "bundle exec rake travis"
env:
global:
- secure: nb9XP2Tq83Ricw2k40qhOe0RPoVHqurYY+J/s6YlVa//R1YabZN1QwfmhAyx60JQwgTZkSRID6uj5w3wzqbNIhOnyMHdQFb+NZV5k7/oRUaSIhbs62mYg/Xa44phaSkVZaxu73dGYFvktNy1TLEuAyd8WYxnoE4WFWja5EMykUI=
- secure: SzUkplVQ+f7/G/2KsG9tUvP33b85t44DAaK7EXU9MKlQ2UYxcVI5avciD9aRyXR0s2UIgvd+x0AHdeXGCN++1FgF75oH4Yd4t8jLIiOJP1b/Tof4mRP6UYXvLVhaiVX22QRKKwwfO5tG8OHaN9RB8GbeCMFBIaiGJlVZ9LJkDd8=
16 changes: 15 additions & 1 deletion Rakefile
Expand Up @@ -15,6 +15,20 @@ RSpec::Core::RakeTask.new(:spec_with_chrome) do |t|
t.pattern = './spec{,/*/**}/*{_spec.rb,_spec_chrome.rb}'
end

RSpec::Core::RakeTask.new(:spec_with_chrome_and_android) do |t|
t.rspec_opts = %w[--color]
# jruby buffers the progress formatter so travis doesn't see output often enough
t.rspec_opts << '--format documentation' if RUBY_PLATFORM=='java'
t.pattern = './spec{,/*/**}/*{_spec.rb,_spec_chrome.rb,_spec_android.rb}'
end

RSpec::Core::RakeTask.new(:spec_android) do |t|
t.rspec_opts = %w[--color]
# jruby buffers the progress formatter so travis doesn't see output often enough
t.rspec_opts << '--format documentation' if RUBY_PLATFORM=='java'
t.pattern = './spec{,/*/**}/*{_spec_android.rb}'
end

YARD::Rake::YardocTask.new do |t|
t.files = ['lib/**/*.rb']
t.options = %w(--markup=markdown)
Expand All @@ -24,6 +38,6 @@ Cucumber::Rake::Task.new(:cucumber) do |task|
task.cucumber_opts = ['--format=progress', 'features']
end

task :travis => [:spec_with_chrome, :cucumber]
task :travis => [:spec_with_chrome, :spec_android, :cucumber]

task :default => [:spec, :cucumber]
2 changes: 2 additions & 0 deletions capybara.gemspec
Expand Up @@ -37,6 +37,8 @@ Gem::Specification.new do |s|
s.add_development_dependency("cucumber", [">= 0.10.5"])
s.add_development_dependency("rake")
s.add_development_dependency("pry")
s.add_development_dependency("sauce")
s.add_development_dependency("sauce-connect")

if RUBY_ENGINE == 'rbx' then
s.add_development_dependency("racc")
Expand Down
20 changes: 20 additions & 0 deletions lib/capybara/driver/node.rb
Expand Up @@ -84,6 +84,26 @@ def path
def trigger(event)
raise NotSupportedByDriverError, 'Capybara::Driver::Node#trigger'
end

def single_tap
raise NotSupportedByDriverError, 'Capybara::Driver::Node#single_tap'
end

def double_tap
raise NotSupportedByDriverError, 'Capybara::Driver::Node#double_tap'
end

def long_press
raise NotSupportedByDriverError, 'Capybara::Driver::Node#long_press'
end

def flick(*args)
raise NotSupportedByDriverError, 'Capybara::Driver::Node#flick'
end

def swipe(*args)
raise NotSupportedByDriverError, 'Capybara::Driver::Node#swipe'
end

def inspect
%(#<#{self.class} tag="#{tag_name}" path="#{path}">)
Expand Down
40 changes: 40 additions & 0 deletions lib/capybara/node/element.rb
Expand Up @@ -141,6 +141,46 @@ def double_click
def hover
synchronize { base.hover }
end

##
#
# Sinlge tap on the Element
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo

#
def single_tap
synchronize { base.single_tap }
end

##
#
# Double tap on the Element
#
def double_tap
synchronize { base.double_tap }
end

##
#
# Long press on the Element
#
def long_press
synchronize { base.long_press }
end

##
#
# Flick the Element
#
def flick(*args)
synchronize { base.flick(args) }
end

##
#
# Swipe the Element
#
def swipe(*args)
synchronize { base.swipe(*args) }
end

##
#
Expand Down
32 changes: 32 additions & 0 deletions lib/capybara/selenium/node.rb
Expand Up @@ -82,7 +82,31 @@ def double_click
def hover
driver.browser.action.move_to(native).perform
end

def single_tap
driver.browser.touch.single_tap(native).perform
end

def double_tap
driver.browser.touch.double_tap(native).perform
end

def long_press
#driver.browser.touch.long_press(native).perform
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be uncommented. I think you commented it because Android driver doesn't support long_press currenly (https://github.com/appium/appium/blob/463e692c7bb7c38dc1a95319aaa6c95ba986bed7/lib/devices/android/android-controller.js#L1042)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it's commented because it didn't work, so I manually did the long press with a delay

loc = native.location
driver.browser.touch.down(loc.x, loc.y).perform
sleep(0.8)
driver.browser.touch.up(loc.x, loc.y).perform
end

def flick(*args)
driver.browser.touch.flick(native, *extract_directions(*args), :fast).perform
end

def swipe(*args)
driver.browser.touch.flick(native, *extract_directions(*args), :normal).perform
end

def drag_to(element)
driver.browser.action.drag_and_drop(native, element.native).perform
end
Expand Down Expand Up @@ -121,6 +145,14 @@ def ==(other)

private

def extract_directions(*args)
directions = if args.last.is_a?(Hash) then args.pop else {} end
directions.default = 0
args.each { |arg| directions[arg] = 200 }
x = directions[:right] - directions[:left]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean by :left, :right, :down, :up?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

its the direction of swipe

y = directions[:down] - directions[:up]
[x,y]
end
# a reference to the select node if this is an option node
def select_node
find_xpath('./ancestor::select').first
Expand Down
31 changes: 31 additions & 0 deletions lib/capybara/spec/public/test_touch.js
@@ -0,0 +1,31 @@
$(function() {
$('#touchable').on({
longTap: function() {
$(this).text('Long pressed');
$(this).after('<div>Long pressed</div>');
return false;
},
swipe: function() {
$(this).text('Flicked');
return false;
},
singleTap: function() {
$(this).text('Tapped');
return false;
},
doubleTap: function() {
$(this).text('Double tapped');
return false;
}
});
$('#swipeable').on({
swipeDown: function() {
$(this).text('Swiped down');
return false;
},
swipeRight: function() {
$(this).text('Swiped right');
return false;
}
});
});