Skip to content

Commit f398041

Browse files
Use symbols for driver opts
Enable debug based on option Improve bridge debug messages Use --local install
1 parent cf09a0d commit f398041

File tree

3 files changed

+26
-15
lines changed

3 files changed

+26
-15
lines changed

Rakefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ end
9090

9191
desc 'Install gem'
9292
task :install => [ :gem, :uninstall ] do
93-
sh "gem install --no-rdoc --no-ri #{repo_name}-#{version}.gem"
93+
sh "gem install --no-rdoc --no-ri --local #{repo_name}-#{version}.gem"
9494
end
9595

9696
desc 'Update release notes'

lib/appium_lib/common/patch.rb

+9-5
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,11 @@ def location_rel
5252
# Show http calls to the Selenium server.
5353
#
5454
# Invaluable for debugging.
55-
module Selenium::WebDriver::Remote
56-
class Bridge
55+
def patch_webdriver_bridge
56+
Selenium::WebDriver::Remote::Bridge.class_eval do
5757
# Code from lib/selenium/webdriver/remote/bridge.rb
5858
def raw_execute(command, opts = {}, command_hash = nil)
59-
verb, path = COMMANDS[command] || raise(ArgumentError, "unknown command: #{command.inspect}")
59+
verb, path = Selenium::WebDriver::Remote::COMMANDS[command] || raise(ArgumentError, "unknown command: #{command.inspect}")
6060
path = path.dup
6161

6262
path[':session_id'] = @session_id if path.include?(':session_id')
@@ -75,12 +75,16 @@ def raw_execute(command, opts = {}, command_hash = nil)
7575
path_str = path.sub(path_match[0], '') unless path_match.nil?
7676

7777
puts "#{verb} #{path_str}"
78-
ap command_hash.to_json unless command_hash.to_json == 'null'
78+
unless command_hash.nil? || command_hash.length == 0
79+
print_command = command_hash.clone
80+
print_command.delete :args if print_command[:args] == []
81+
ap print_command
82+
end
7983
# puts "verb: #{verb}, path #{path}, command_hash #{command_hash.to_json}"
8084
http.call verb, path, command_hash
8185
end # def
8286
end # class
83-
end if defined? Pry # module Selenium::WebDriver::Remote
87+
end # def
8488

8589
# Print Appium's origValue error messages.
8690
class Selenium::WebDriver::Remote::Response

lib/appium_lib/driver.rb

+16-9
Original file line numberDiff line numberDiff line change
@@ -37,35 +37,39 @@ class Driver
3737
attr_reader :app_path, :app_name, :app_package, :app_activity,
3838
:app_wait_activity, :sauce_username, :sauce_access_key,
3939
:port, :os, :ios_js
40-
def initialize opts={}
40+
def initialize options={}
4141
# quit last driver
4242
$driver.driver_quit if $driver
4343

44+
opts = {}
45+
# convert to downcased symbols
46+
options.each_pair { |k,v| opts[k.to_s.downcase.strip.intern] = v }
47+
4448
opts = {} if opts.nil?
4549
# Path to the .apk, .app or .app.zip.
4650
# The path can be local or remote for Sauce.
47-
@app_path = opts.fetch 'APP_PATH', ENV['APP_PATH']
51+
@app_path = opts.fetch :app_path, ENV['APP_PATH']
4852
raise 'APP_PATH must be set.' if @app_path.nil?
4953

5054
# The name to use for the test run on Sauce.
51-
@app_name = opts.fetch 'APP_NAME', ENV['APP_NAME']
55+
@app_name = opts.fetch :app_name, ENV['APP_NAME']
5256

5357
# Android app package
54-
@app_package = opts.fetch 'APP_PACKAGE', ENV['APP_PACKAGE']
58+
@app_package = opts.fetch :app_package, ENV['APP_PACKAGE']
5559

5660
# Android app starting activity.
57-
@app_activity = opts.fetch 'APP_ACTIVITY', ENV['APP_ACTIVITY']
61+
@app_activity = opts.fetch :app_activity, ENV['APP_ACTIVITY']
5862

5963
# Android app waiting activity
60-
@app_wait_activity = opts.fetch 'APP_WAIT_ACTIVITY', ENV['APP_WAIT_ACTIVITY']
64+
@app_wait_activity = opts.fetch :app_wait_activity, ENV['APP_WAIT_ACTIVITY']
6165

6266
# Sauce Username
63-
@sauce_username = opts.fetch'SAUCE_USERNAME', ENV['SAUCE_USERNAME']
67+
@sauce_username = opts.fetch :sauce_username, ENV['SAUCE_USERNAME']
6468

6569
# Sauce Key
66-
@sauce_access_key = opts.fetch 'SAUCE_ACCESS_KEY', ENV['SAUCE_ACCESS_KEY']
70+
@sauce_access_key = opts.fetch :sauce_access_key, ENV['SAUCE_ACCESS_KEY']
6771

68-
@port = opts.fetch 'PORT', ENV['PORT'] || 4723
72+
@port = opts.fetch :port, ENV['PORT'] || 4723
6973

7074
@os = :ios
7175
@os = :android if @app_path.end_with?('.apk') || @app_path.end_with?('.apk.zip')
@@ -87,6 +91,9 @@ def initialize opts={}
8791
# apply os specific patches
8892
patch_webdriver_element
8993

94+
# enable debug patch
95+
patch_webdriver_bridge if opts.fetch :debug, defined?(Pry)
96+
9097
# Save global reference to last created Appium driver for top level methods.
9198
$driver = self
9299

0 commit comments

Comments
 (0)