Class: WDA

Inherits:
Object
  • Object
show all
Includes:
HTTParty, Alert, Custome, Debug, Error, FindElement, Orientation, Screenshot, Session, TouchID, Type
Defined in:
lib/wda_lib/type.rb,
lib/wda_lib.rb,
lib/wda_lib/wait.rb,
lib/wda_lib/alert.rb,
lib/wda_lib/debug.rb,
lib/wda_lib/error.rb,
lib/wda_lib/custom.rb,
lib/wda_lib/element.rb,
lib/wda_lib/session.rb,
lib/wda_lib/version.rb,
lib/wda_lib/touch_id.rb,
lib/wda_lib/screenshot.rb,
lib/wda_lib/orientation.rb,
lib/wda_lib/find_element.rb

Overview

Created by Yi MIN<[email protected]> Copyright © 2016 Zenly. All rights reserved.

Defined Under Namespace

Modules: Alert, Custome, Debug, Error, FindElement, Orientation, Screenshot, Session, TouchID, Type Classes: Dimension, Element, Point, Wait

Constant Summary collapse

BASE_URL =

Get base_url from XCTRunner logs: ServerURLHere->x.x.x.x:8100<-ServerURLHere Default base_url ‘localhost:8100’ for running XCTRunner on simulator

'http://localhost:8100'
VERSION =
'0.2.3'

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Type

#match

Methods included from TouchID

#match_touchid, #unmatch_touchid

Methods included from Session

#healthcheck, #launch_app, #quit, #restart, #session, #status, #update_status, #x

Methods included from Screenshot

#screenshot

Methods included from Orientation

#get_rotation, #orientation, #set_orientation, #set_rotation

Methods included from FindElement

#accessibility_id, #accessibility_ids, #button, #buttons, #class_name, #class_names, #find, #find_element, #find_elements, #find_subl_element, #find_subl_elements, #finds, #first_button, #first_textfield, #icon, #icons, #id, #ids, #last_button, #last_textfield, #name, #names, #partial_text, #partial_texts, #predicate_text, #predicate_texts, #searchfield, #searchfields, #secure_textfield, #secure_textfields, #set_timeout, #statictext, #statictexts, #stringlize, #text, #textfield, #textfields, #texts, #visible_cell, #xpath, #xpath_search

Methods included from Debug

#exists, #find_app, #get_source, #get_window, #get_window_statusbar, #source

Methods included from Custome

#double_tap_homebutton, #homescreen, #kill_app, #pause, #springboard, #timeout_in_session

Methods included from Alert

#accept_alert, #alert_text, #dismiss_alert

Constructor Details

#initialize(opt) ⇒ WDA

Create a new client

“‘ruby require ’rubygems’ require ‘wda_lib’

Start wda client opts = { caps: { bundleId: @bundle_id }, device_url: ‘x.x.x.x:8100’ } WDA.new(opts).start_session



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/wda_lib.rb', line 49

def initialize(opt)
  # fail 'opts should be a hash' unless opts.is_a? Hash
  # fail 'bundleId should be provided' if opts[:bundle_id].nil?
  if opt.is_a? String
    url = opt
    opts = {:device_url => url}
  else
    opts = opt
  end
  url = opts[:device_url] || BASE_URL
  parsed_url = URI.parse(url)
  @base_url = parsed_url.scheme + '://' + parsed_url.host + ':' + parsed_url.port.to_s
  @url = @base_url
  @server_host = parsed_url.host
  @server_port = parsed_url.port
  @default_timeout = opts.fetch :default_timeout, 10
  @timeout = @default_timeout
  @listener = opts.fetch :listener, nil
  status
  window_size
  capabilities(opts)
  @http_client ||= Selenium::WebDriver::Remote::Http::Default.new(open_timeout: 999_999, read_timeout: 999_999)
  @driver = Selenium::WebDriver.for(:remote, 
                                    http_client: @http_client,
                                    :url => @base_url,  
                                    :desired_capabilities => @caps[:desired_capabilities],
                                    :listener => @listener)
end

Instance Attribute Details

#base_urlObject (readonly)

Returns the value of attribute base_url.



34
35
36
# File 'lib/wda_lib.rb', line 34

def base_url
  @base_url
end

#bundle_idObject

Returns the value of attribute bundle_id.



33
34
35
# File 'lib/wda_lib.rb', line 33

def bundle_id
  @bundle_id
end

#capsObject

Returns the value of attribute caps.



33
34
35
# File 'lib/wda_lib.rb', line 33

def caps
  @caps
end

#deviceObject

Returns the value of attribute device.



33
34
35
# File 'lib/wda_lib.rb', line 33

def device
  @device
end

#driverObject

Returns the value of attribute driver.



33
34
35
# File 'lib/wda_lib.rb', line 33

def driver
  @driver
end

#httpObject

Returns the value of attribute http.



33
34
35
# File 'lib/wda_lib.rb', line 33

def http
  @http
end

#server_hostObject (readonly)

Returns the value of attribute server_host.



34
35
36
# File 'lib/wda_lib.rb', line 34

def server_host
  @server_host
end

#server_portObject (readonly)

Returns the value of attribute server_port.



34
35
36
# File 'lib/wda_lib.rb', line 34

def server_port
  @server_port
end

#session_idObject

Returns the value of attribute session_id.



33
34
35
# File 'lib/wda_lib.rb', line 33

def session_id
  @session_id
end

#timeoutObject

Returns the value of attribute timeout.



33
34
35
# File 'lib/wda_lib.rb', line 33

def timeout
  @timeout
end

#urlObject (readonly)

Returns the value of attribute url.



34
35
36
# File 'lib/wda_lib.rb', line 34

def url
  @url
end

#win_xObject (readonly)

Returns the value of attribute win_x.



34
35
36
# File 'lib/wda_lib.rb', line 34

def win_x
  @win_x
end

#win_yObject (readonly)

Returns the value of attribute win_y.



34
35
36
# File 'lib/wda_lib.rb', line 34

def win_y
  @win_y
end

#window_hObject (readonly)

Returns the value of attribute window_h.



34
35
36
# File 'lib/wda_lib.rb', line 34

def window_h
  @window_h
end

#window_wObject (readonly)

Returns the value of attribute window_w.



34
35
36
# File 'lib/wda_lib.rb', line 34

def window_w
  @window_w
end

Instance Method Details

#capabilities(opts = {}) ⇒ Object

Build desired_capabilities with options

Parameters:

  • opts (Hash) (defaults to: {})

Returns:

  • attribute caps [Hash]



81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/wda_lib.rb', line 81

def capabilities(opts = {}) 
  @bundle_id = opts[:bundle_id] if !opts[:bundle_id].nil?
  selenium_capabilities = Selenium::WebDriver::Remote::Capabilities.new( 
                            platform_name: @platform_name, 
                            platform_version: @platform_version,
                            session_id: @session_id,
                            session_valid: @session_valid,
                            bundleId: @bundle_id,
                            javascript_enabled: true,
                            takes_screenshot: true,
                            css_selectors_enabled: true
                          )
  @caps = { desired_capabilities: selenium_capabilities }
end

#delete(path) ⇒ Object



115
116
117
# File 'lib/wda_lib.rb', line 115

def delete(path)
  WDA.delete(path)
end

#get(path, timeout = 60) ⇒ Object

HTTP methods for dealing with all supported motheds in FB WDA I don’t like to write such pieces of code, it removes all query params and headers, But as FB WDA is doing like this, this can simplify codes



99
100
101
102
103
104
105
# File 'lib/wda_lib.rb', line 99

def get(path, timeout = 60)
  if URI.parse(path).absolute?
    WDA.get(path, timeout: timeout)
  else
    WDA.get(@url + path, timeout: timeout)
  end
end

#keys(value) ⇒ Object

Type text to textfield

Parameters:

  • value (String)


164
165
166
# File 'lib/wda_lib/element.rb', line 164

def keys(value)
  post '/keys', { value: value.chars }
end

#post(path, body = nil, timeout = 60) ⇒ Object



107
108
109
110
111
112
113
# File 'lib/wda_lib.rb', line 107

def post(path, body = nil, timeout = 60)
  if URI.parse(path).absolute?
    WDA.post(path, body: body.to_json, timeout: timeout)
  else
    WDA.post(@url + path, body: body.to_json, timeout: timeout)
  end
end

#set_wait(timeout = nil) ⇒ Object



119
120
121
122
123
124
125
126
127
128
# File 'lib/wda_lib.rb', line 119

def set_wait(timeout = nil)
  if timeout.nil?
    @timeout = @default_timeout
  elsif timeout < 1
    @timeout = 1
  else
    @timeout = timeout.to_i
  end
  return @timeout
end

#swipe(fromX, toX, fromY, toY) ⇒ Object

Swipe on an element with its id and position

Parameters:

  • fromX (Integer)

    , toX [Integer], fromY [Integer], toY [Integer]



152
153
154
# File 'lib/wda_lib/element.rb', line 152

def swipe(fromX, toX, fromY, toY)
  post '/uiaTarget/0/dragfromtoforduration', { fromX: fromX, toX: toX, fromY: fromY, toY: toY, duration: 0 }
end

#tap_on(x, y) ⇒ Object

Tap on a given positon

Parameters:

  • x (Integer)

    , y [Integer]



158
159
160
# File 'lib/wda_lib/element.rb', line 158

def tap_on(x, y)
  post '/tap/0', { x: x, y: y }
end

#window_sizeObject

Returns width, height.

Returns:

  • width, height



169
170
171
172
173
174
# File 'lib/wda_lib/element.rb', line 169

def window_size
  win_size = get('/window/size')['value']
  @win_x = win_size['width']
  @win_y = win_size['height']
  Dimension.new(win_size['width'], win_size['height'])
end