touch_action 1.1.1 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 077f7c6670440d15c9b7ad71bcc803aea8d37a8a
4
+ data.tar.gz: 457853a034bcdb87a3bb100135fec0eb0fdeb8d0
5
+ SHA512:
6
+ metadata.gz: d6f47ff42c9f1cefd26b047d2413a4d2eb4db5919dbb42b11b30bfd56129e22f8fb58cfcf9e73977fbef65f3a14f5dc8e86fc835bb6541e7001d455819b2b520
7
+ data.tar.gz: 1ae8e9abb5da2a00bc3fa55683918de1f18bf4295812b1269e10a78b17afc89cdd4f4b92c2246502047bfc48454ce95cef2532cd7092f9c7dca8578f34f965c6
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## v1.2.0
2
+
3
+ * added execution block until YUI is loaded and gesture is performed
4
+ * added readyState checking in order to wait for pages to load when using tap on links for example
5
+
1
6
  ## v1.1.0
2
7
 
3
8
  * fully refactored
@@ -6,8 +6,20 @@ module TouchAction
6
6
  module RspecHelper
7
7
 
8
8
  def touch_action locator, *args
9
+ page.driver.browser.manage.timeouts.script_timeout = 30
10
+ page.driver.browser.execute_async_script( TouchAction::ScriptGenerator.yui_loader )
9
11
  final_script = TouchAction::ScriptGenerator.generate_javascript(*args)
10
- page.driver.browser.execute_script( final_script, locator )
12
+ page.driver.browser.execute_async_script( final_script, locator )
13
+ wait_for_page_ready_state
14
+ end
15
+
16
+ private
17
+ def wait_for_page_ready_state
18
+ sleep(0.5) # mobile browsers wait around 300ms when tapping to check if it isn's a double tap before triggering the link
19
+ end_time = Time.now + 30
20
+ while (page.driver.browser.execute_script('return document.readyState' != 'complete') || Time.now > end_time)
21
+ sleep(0.1)
22
+ end
11
23
  end
12
24
 
13
25
  end
@@ -1,38 +1,15 @@
1
1
  (function( touch_action, $, undefined ) {
2
2
 
3
- // private property
4
- var execute_gesture = function() {
3
+ touch_action.perform_gesture = function(selenium_finalized_callback) {
4
+
5
5
  YUI().use('node-event-simulate', function(Y) {
6
6
 
7
7
  var node = Y.one(touch_action.element);
8
8
  node.simulateGesture(touch_action.gesture, touch_action.options);
9
9
 
10
- });
11
- };
12
-
13
- // private method
14
- function loadYui() {
15
-
16
- var head = document.getElementsByTagName('head')[0];
17
- var script = document.createElement('script');
18
- script.type = 'text/javascript';
19
- script.src = "//yui.yahooapis.com/3.18.1/build/yui/yui-min.js";
20
-
21
- script.onreadystatechange = execute_gesture;
22
- script.onload = execute_gesture;
23
-
24
- head.appendChild(script);
25
-
26
- };
27
- // public method
28
- touch_action.perform = function() {
29
-
30
- if (typeof YUI == 'undefined') {
31
- loadYui();
32
- } else {
33
- execute_gesture();
34
- };
10
+ });
35
11
 
12
+ selenium_finalized_callback();
36
13
  };
37
14
 
38
15
 
@@ -44,4 +21,4 @@ touch_action.gesture = "<%=gesture%>";
44
21
 
45
22
  touch_action.options = <%=options.to_json%>;
46
23
 
47
- touch_action.perform();
24
+ touch_action.perform_gesture(arguments[arguments.length - 1]);
@@ -0,0 +1,22 @@
1
+ (function(callback) {
2
+ if (typeof YUI == 'undefined') {
3
+ var script = document.createElement('script');
4
+ var head = document.getElementsByTagName('head')[0];
5
+ var done = false;
6
+ script.onload = script.onreadystatechange = (function() {
7
+ if (!done && (!this.readyState || this.readyState == 'loaded'
8
+ || this.readyState == 'complete')) {
9
+ done = true;
10
+ script.onload = script.onreadystatechange = null;
11
+ head.removeChild(script);
12
+ callback();
13
+ }
14
+ });
15
+ script.type = 'text/javascript';
16
+ script.src = "//yui.yahooapis.com/3.18.1/build/yui/yui-min.js";
17
+ head.appendChild(script);
18
+ }
19
+ else {
20
+ callback();
21
+ }
22
+ })(arguments[arguments.length - 1]);
@@ -13,6 +13,10 @@ module TouchAction
13
13
  rotate: {rotation: -75}
14
14
  }
15
15
 
16
+ def self.yui_loader
17
+ yui_loader_script = File.read(File.expand_path("../javascripts/yui_loader.js", __FILE__))
18
+ end
19
+
16
20
  def self.generate_javascript action, options = {}
17
21
  action = :flick if action == :swipe
18
22
  raise ArgumentError, "The touch action #{action} doesn't exist" unless ACTIONS_WITH_DEFAULT_OPTIONS[action]
@@ -5,8 +5,21 @@ module TouchAction
5
5
  module SeleniumWebdriver
6
6
 
7
7
  def touch_action *args
8
+ Selenium::WebDriver::Timeouts.new(bridge).script_timeout= 30
9
+ bridge.executeAsyncScript( TouchAction::ScriptGenerator.yui_loader )
8
10
  final_script = TouchAction::ScriptGenerator.generate_javascript(*args)
9
- bridge.executeScript( final_script, self )
11
+ bridge.executeAsyncScript( final_script, self )
12
+ wait_for_page_ready_state
13
+ end
14
+
15
+ private
16
+
17
+ def wait_for_page_ready_state
18
+ sleep(0.5) # mobile browsers wait around 300ms when tapping to check if it isn's a double tap before triggering the link
19
+ end_time = Time.now + 30
20
+ while (bridge.executeScript('return document.readyState' != 'complete') || Time.now > end_time)
21
+ sleep(0.1)
22
+ end
10
23
  end
11
24
 
12
25
  end
@@ -1,3 +1,3 @@
1
1
  module TouchAction
2
- VERSION = "1.1.1"
2
+ VERSION = "1.2.0"
3
3
  end
@@ -3,9 +3,21 @@ require "touch_action/script_generator"
3
3
 
4
4
  module TouchAction
5
5
  module WatirWebdriver
6
+
6
7
  def touch_action *args
8
+ browser.driver.manage.timeouts.script_timeout = 30
9
+ browser.driver.execute_async_script( TouchAction::ScriptGenerator.yui_loader )
7
10
  final_script = TouchAction::ScriptGenerator.generate_javascript(*args)
8
- browser.execute_script( final_script, self )
11
+ browser.driver.execute_async_script( final_script, self.wd )
12
+ wait_for_page_ready_state
13
+ end
14
+
15
+
16
+ private
17
+
18
+ def wait_for_page_ready_state
19
+ sleep(0.5) # mobile browsers wait around 300ms when tapping to check if it isn's a double tap before triggering the link
20
+ browser.wait
9
21
  end
10
22
  end
11
23
 
@@ -6,23 +6,27 @@ RSpec.describe TouchAction do
6
6
  @browser.goto('http://localhost:9292/tap')
7
7
  element = @browser.div(id: 'myElement')
8
8
  element.touch_action :tap
9
- sleep(5)
10
9
  expect(element.text).to include('tap')
11
10
  end
12
11
 
13
12
  it 'should tap link bound by FastClick' do
14
13
  @browser.goto('http://localhost:9292/tap')
15
14
  @browser.a(id: 'fastclick').touch_action :tap
16
- sleep(5)
17
15
  expect(@browser.p(id: 'fast-click-test').text).to include('1 times')
18
16
  end
19
17
 
20
18
  it "should tap using webdriver capybara", js: true, use_webdriver: :capybara do
21
19
  visit('http://localhost:9292/tap')
22
20
  touch_action '#myElement', :tap
23
- sleep(5)
24
21
  expect(find("#myElement").text).to include('tap')
25
22
  end
26
23
 
24
+ it "should tap using selenium", js: true, use_webdriver: :selenium do
25
+ @browser.navigate.to('http://localhost:9292/tap')
26
+ element = @browser.find_element(:id, 'myElement')
27
+ element.touch_action :tap
28
+ expect(element.text).to include('tap')
29
+ end
30
+
27
31
  end
28
32
  end
data/spec/spec_helper.rb CHANGED
@@ -14,12 +14,12 @@ Dir["./spec/support/**/*.rb"].sort.each { |f| require f}
14
14
  end
15
15
 
16
16
 
17
- case ENV['PLATFORM']
17
+ case ENV['platform']
18
18
  when 'ios'
19
19
  capabilities = {
20
20
  :deviceName => 'iPhone 5s',
21
21
  :browserName => 'Safari',
22
- :platformVersion => '8.1',
22
+ :platformVersion => '7.1',
23
23
  :platformName => 'iOS',
24
24
  :app => 'safari',
25
25
  :newCommandTimeout => 9999
@@ -46,7 +46,7 @@ ENV['browser'] ||= 'firefox'
46
46
  RSpec.configure do |config|
47
47
 
48
48
  config.before(:each) do |example|
49
- if ENV['PLATFORM']
49
+ if ENV['platform']
50
50
  @browser = Watir::Browser.new(Selenium::WebDriver.for(:remote, :desired_capabilities => capabilities, :url => ENV['appium_url']))
51
51
  else
52
52
  case example.metadata[:use_webdriver]
metadata CHANGED
@@ -1,142 +1,125 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: touch_action
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
5
- prerelease:
4
+ version: 1.2.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Ricardo Nacif
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2015-04-10 00:00:00.000000000 Z
11
+ date: 2015-01-07 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: watir-webdriver
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - ">="
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
22
20
  type: :development
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - ">="
28
25
  - !ruby/object:Gem::Version
29
26
  version: '0'
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: capybara
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - ">="
36
32
  - !ruby/object:Gem::Version
37
33
  version: '0'
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - ">="
44
39
  - !ruby/object:Gem::Version
45
40
  version: '0'
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: bundler
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ~>
45
+ - - "~>"
52
46
  - !ruby/object:Gem::Version
53
47
  version: '1.7'
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ~>
52
+ - - "~>"
60
53
  - !ruby/object:Gem::Version
61
54
  version: '1.7'
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: rake
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
- - - ~>
59
+ - - "~>"
68
60
  - !ruby/object:Gem::Version
69
61
  version: '10.0'
70
62
  type: :development
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
- - - ~>
66
+ - - "~>"
76
67
  - !ruby/object:Gem::Version
77
68
  version: '10.0'
78
69
  - !ruby/object:Gem::Dependency
79
70
  name: pry
80
71
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
72
  requirements:
83
- - - ! '>='
73
+ - - ">="
84
74
  - !ruby/object:Gem::Version
85
75
  version: '0'
86
76
  type: :development
87
77
  prerelease: false
88
78
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
79
  requirements:
91
- - - ! '>='
80
+ - - ">="
92
81
  - !ruby/object:Gem::Version
93
82
  version: '0'
94
83
  - !ruby/object:Gem::Dependency
95
84
  name: rack
96
85
  requirement: !ruby/object:Gem::Requirement
97
- none: false
98
86
  requirements:
99
- - - ! '>='
87
+ - - ">="
100
88
  - !ruby/object:Gem::Version
101
89
  version: '0'
102
90
  type: :development
103
91
  prerelease: false
104
92
  version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
93
  requirements:
107
- - - ! '>='
94
+ - - ">="
108
95
  - !ruby/object:Gem::Version
109
96
  version: '0'
110
97
  - !ruby/object:Gem::Dependency
111
98
  name: rspec
112
99
  requirement: !ruby/object:Gem::Requirement
113
- none: false
114
100
  requirements:
115
- - - ~>
101
+ - - "~>"
116
102
  - !ruby/object:Gem::Version
117
103
  version: 3.1.0
118
104
  type: :development
119
105
  prerelease: false
120
106
  version_requirements: !ruby/object:Gem::Requirement
121
- none: false
122
107
  requirements:
123
- - - ~>
108
+ - - "~>"
124
109
  - !ruby/object:Gem::Version
125
110
  version: 3.1.0
126
111
  - !ruby/object:Gem::Dependency
127
112
  name: thin
128
113
  requirement: !ruby/object:Gem::Requirement
129
- none: false
130
114
  requirements:
131
- - - ! '>='
115
+ - - ">="
132
116
  - !ruby/object:Gem::Version
133
117
  version: '0'
134
118
  type: :development
135
119
  prerelease: false
136
120
  version_requirements: !ruby/object:Gem::Requirement
137
- none: false
138
121
  requirements:
139
- - - ! '>='
122
+ - - ">="
140
123
  - !ruby/object:Gem::Version
141
124
  version: '0'
142
125
  description: Adds touch gestures simulation to Watir, Selenium and Capybara using
@@ -147,9 +130,8 @@ executables: []
147
130
  extensions: []
148
131
  extra_rdoc_files: []
149
132
  files:
150
- - .gitignore
151
- - .ruby-version
152
- - .travis.yml
133
+ - ".gitignore"
134
+ - ".travis.yml"
153
135
  - CHANGELOG.md
154
136
  - Gemfile
155
137
  - LICENSE.txt
@@ -159,6 +141,7 @@ files:
159
141
  - lib/touch_action.rb
160
142
  - lib/touch_action/capybara_rspec_helper.rb
161
143
  - lib/touch_action/javascripts/touch_action.js.erb
144
+ - lib/touch_action/javascripts/yui_loader.js
162
145
  - lib/touch_action/script_generator.rb
163
146
  - lib/touch_action/selenium-webdriver.rb
164
147
  - lib/touch_action/version.rb
@@ -190,27 +173,26 @@ files:
190
173
  homepage: https://github.com/Ricardonacif/touch_action
191
174
  licenses:
192
175
  - MIT
176
+ metadata: {}
193
177
  post_install_message:
194
178
  rdoc_options: []
195
179
  require_paths:
196
180
  - lib
197
181
  required_ruby_version: !ruby/object:Gem::Requirement
198
- none: false
199
182
  requirements:
200
- - - ! '>='
183
+ - - ">="
201
184
  - !ruby/object:Gem::Version
202
185
  version: '0'
203
186
  required_rubygems_version: !ruby/object:Gem::Requirement
204
- none: false
205
187
  requirements:
206
- - - ! '>='
188
+ - - ">="
207
189
  - !ruby/object:Gem::Version
208
190
  version: '0'
209
191
  requirements: []
210
192
  rubyforge_project:
211
- rubygems_version: 1.8.23.2
193
+ rubygems_version: 2.2.2
212
194
  signing_key:
213
- specification_version: 3
195
+ specification_version: 4
214
196
  summary: Adds touch gestures simulation to Watir-WebDriver, Selenium-WebDriver and
215
197
  Capybara using YUI JS.
216
198
  test_files:
data/.ruby-version DELETED
@@ -1 +0,0 @@
1
- 1.9.3-p547