appium_lib_core 5.0.2 → 5.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/script/commands.rb DELETED
@@ -1,166 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
6
- #
7
- # http://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
14
-
15
- require 'net/http'
16
- require './lib/appium_lib_core'
17
-
18
- module Script
19
- class CommandsChecker
20
- attr_reader :spec_commands,
21
- :implemented_w3c_commands, :implemented_core_commands,
22
- :webdriver_w3c_commands
23
-
24
- # Set commands implemented in this core library.
25
- #
26
- # - implemented_w3c_commands: All commands include ::Selenium::WebDriver::Remote::Bridge::COMMANDS
27
- # - implemented_core_commands: All commands except for selenium-webdriver's commands
28
- #
29
- def initialize
30
- @spec_commands = nil
31
-
32
- @implemented_core_commands = convert_driver_commands Appium::Core::Commands::COMMANDS
33
- end
34
-
35
- # Get the bellow url's file.
36
- # https://raw.githubusercontent.com/appium/appium-base-driver/master/lib/mjsonwp/routes.js?raw=1
37
- #
38
- # @param [String] to_path: A file path to routes.js
39
- # @return [String] The file path in which has saved `routes.js`.
40
- #
41
- def get_mjsonwp_routes(to_path = './mjsonwp_routes.js')
42
- uri = URI 'https://raw.githubusercontent.com/appium/appium-base-driver/master/lib/protocol/routes.js?raw=1'
43
- result = Net::HTTP.get uri
44
-
45
- File.delete to_path if File.exist? to_path
46
- File.write to_path, result
47
- to_path
48
- end
49
-
50
- # @private
51
- HTTP_METHOD_MATCH = /GET:|POST:|DELETE:|PUT:|PATCH:/.freeze
52
- # @private
53
- WD_HUB_PREFIX_MATCH = "'/wd/hub/"
54
-
55
- # Read routes.js and set the values in @spec_commands
56
- #
57
- # @param [String] path: A file path to routes.js
58
- # @return [Hash] @spec_commands
59
- #
60
- def get_all_command_path(path = './mjsonwp_routes.js')
61
- raise "No file in #{path}" unless File.exist? path
62
-
63
- current_command = ''
64
- @spec_commands = File.read(path).lines.each_with_object({}) do |line, memo|
65
- if line =~ /#{WD_HUB_PREFIX_MATCH}.+'/
66
- current_command = gsub_set(line.slice(/#{WD_HUB_PREFIX_MATCH}.+'/))
67
- memo[current_command] = []
68
- elsif line =~ HTTP_METHOD_MATCH
69
- memo[current_command] << line.slice(HTTP_METHOD_MATCH).chop.downcase.to_sym
70
- end
71
- memo
72
- end
73
- end
74
-
75
- # All commands which haven't been implemented in ruby core library yet.
76
- # @return [Hash]
77
- #
78
- def all_diff_commands_w3c
79
- result = compare_commands(@spec_commands, @implemented_w3c_commands)
80
- white_list.each { |v| result.delete v }
81
- mjsonwp_spec.each { |v| result.delete v }
82
- result
83
- end
84
-
85
- # Commands, only this core library, which haven't been implemented in ruby core library yet.
86
- # @return [Hash]
87
- #
88
- def diff_except_for_webdriver
89
- result = compare_commands(@spec_commands, @implemented_core_commands)
90
- white_list.each { |v| result.delete v }
91
- result
92
- end
93
-
94
- def compare_commands(command1, with_command2)
95
- return {} if command1.nil?
96
- return command1 if with_command2.nil?
97
-
98
- result = {}
99
- command1.each_key do |key|
100
- if with_command2.key? key
101
- diff = command1[key] - with_command2[key]
102
- result[key] = diff unless diff.empty?
103
- else
104
- result[key] = command1[key]
105
- end
106
- end
107
- result
108
- end
109
-
110
- private
111
-
112
- # rubocop:disable Lint/PercentStringArray
113
- def white_list
114
- %w(
115
- '/wd/hub/session'
116
- '/wd/hub/sessions'
117
- ).map { |v| gsub_set(v) }
118
- end
119
-
120
- # https://raw.githubusercontent.com/appium/appium-base-driver/master/lib/mjsonwp/routes.js
121
- def mjsonwp_spec
122
- %w(
123
- '/wd/hub/session/:sessionId/alert_text'
124
- '/wd/hub/session/:sessionId/accept_alert'
125
- '/wd/hub/session/:sessionId/dismiss_alert'
126
- ).map { |v| gsub_set(v) }
127
- end
128
-
129
- def w3c_spec
130
- %w(
131
- '/wd/hub/session/:sessionId/alert/text'
132
- '/wd/hub/session/:sessionId/alert/accept'
133
- '/wd/hub/session/:sessionId/alert/dismiss'
134
- '/wd/hub/session/:sessionId/element/:elementId/rect'
135
- ).map { |v| gsub_set(v) }
136
- end
137
- # rubocop:enable Lint/PercentStringArray
138
-
139
- def gsub_set(line)
140
- return nil if line.gsub(/(\A#{WD_HUB_PREFIX_MATCH}|'\z)/, '').nil?
141
-
142
- line.gsub(/(\A#{WD_HUB_PREFIX_MATCH}|'\z)/, '')
143
- .sub(':sessionId', ':session_id')
144
- .sub('element/:elementId', 'element/:id')
145
- .sub(':windowhandle', ':window_handle')
146
- .sub('equals/:otherId', 'equals/:other')
147
- .sub('css/:propertyName', 'css/:property_name')
148
- .sub('element/:id/pageIndex', 'element/:id/page_index')
149
- end
150
-
151
- def convert_driver_commands(from)
152
- from.each_with_object({}) do |command, memo|
153
- method = command[1][0]
154
- key = command[1][1]
155
-
156
- if memo[key]
157
- memo[key] << method
158
- else
159
- memo[key] = [method]
160
- end
161
-
162
- memo
163
- end
164
- end
165
- end
166
- end