Module: WDA::Session
- Included in:
- WDA
- Defined in:
- lib/wda_lib/session.rb
Instance Method Summary collapse
-
#healthcheck ⇒ Object
Healthcheck This api does also get back to homescreen.
-
#launch_app(app_name_or_id) ⇒ self
Post desired_capabilities to wda server to create a session This is not realy needed since we can find and click app icon to start app.
-
#open_url(url) ⇒ self
Post url to wda server to open a url in browser and create a session.
-
#quit(session_id = nil) ⇒ Object
Exit current app by delete session with given session_id.
-
#restart(app_name_or_id = nil) ⇒ self
recreate a session.
-
#session ⇒ Session
Get current valid session.
-
#status(status_timeout = 5) ⇒ Obj
Get current status.
-
#update_status(status_response) ⇒ object
Update current running sessionId to @session_id.
-
#x ⇒ Object
Same as quit, but delete default @session_id.
Instance Method Details
#healthcheck ⇒ Object
Healthcheck This api does also get back to homescreen
105 106 107 108 |
# File 'lib/wda_lib/session.rb', line 105 def healthcheck response = get(@base_url + '/wda/healthcheck') update_status(response) end |
#launch_app(app_name_or_id) ⇒ self
Post desired_capabilities to wda server to create a session This is not realy needed since we can find and click app icon to start app
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/wda_lib/session.rb', line 61 def launch_app(app_name_or_id) fail 'Either app name or bundle id should be given for launch app' if app_name_or_id.nil? if app_name_or_id.include?('.') # Given value is app's bundle id @bundle_id = app_name_or_id @session_id = nil # Prepare to create new session @session_valid = false # Prepare to create new session #post(@base_url + '/session', { desiredCapabilities: { bundleId: app_name_or_id }}) # Temporarily disabled capabilities @driver = Selenium::WebDriver::Driver.for(:remote, :url => @base_url, :desired_capabilities => @caps[:desired_capabilities]) else app_name = app_name_or_id find_app(app_name).click end status self end |
#open_url(url) ⇒ self
Post url to wda server to open a url in browser and create a session
53 54 55 56 |
# File 'lib/wda_lib/session.rb', line 53 def open_url(url) post('/url', { url: url }) status end |
#quit(session_id = nil) ⇒ Object
Exit current app by delete session with given session_id
92 93 94 95 96 |
# File 'lib/wda_lib/session.rb', line 92 def quit(session_id = nil) (session_id.nil?)? sessionId = @session_id : sessionId = session_id delete(@base_url + '/session/' + sessionId) status end |
#restart(app_name_or_id = nil) ⇒ self
recreate a session
81 82 83 84 85 86 87 |
# File 'lib/wda_lib/session.rb', line 81 def restart(app_name_or_id = nil) quit sleep 0.5 status launch_app(app_name_or_id ||= @bundle_id ) sleep 0.5 end |
#session ⇒ Session
Get current valid session
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/wda_lib/session.rb', line 30 def session response = get(@url) if response['status'] != 0 if response['status'] == 10 response['value'] restart_session response = get(@url) elsif response['status'] == 1 || response['status'] == 6 @session_id = response['sessionId'] @url = @base_url + "/session/#{@session_id}" response = get(@url) end else @session_id = response['sessionId'] @caps[:desired_capabilities][:session_id] = @session_id @caps[:desired_capabilities][:session_valid] = true @url = @base_url + "/session/#{@session_id}" end response end |
#status(status_timeout = 5) ⇒ Obj
Get current status
10 11 12 13 14 15 |
# File 'lib/wda_lib/session.rb', line 10 def status(status_timeout = 5) @status = get(@base_url + '/status', status_timeout) @platform_name = @status['value']['os']['name'] @platform_version = @status['value']['os']['version'] update_status(@status) end |
#update_status(status_response) ⇒ object
Update current running sessionId to @session_id
20 21 22 23 24 25 26 |
# File 'lib/wda_lib/session.rb', line 20 def update_status(status_response) @session_valid = true @session_id = status_response['sessionId'] @url = @base_url + "/session/#{@session_id}" capabilities status_response end |
#x ⇒ Object
Same as quit, but delete default @session_id
99 100 101 |
# File 'lib/wda_lib/session.rb', line 99 def x quit end |