Class: Webdriver::Session

Inherits:
Object
  • Object
show all
Defined in:
lib/webdriver/session.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(json, connection) ⇒ Session

Returns a new instance of Session.



5
6
7
8
# File 'lib/webdriver/session.rb', line 5

def initialize(json, connection)
  @id = json.dig "id"
  @connection = Webdriver::PrefixConnection.new "session/#{@id}", connection
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



3
4
5
# File 'lib/webdriver/session.rb', line 3

def id
  @id
end

Instance Method Details

#accept_alert!Object



117
118
119
120
# File 'lib/webdriver/session.rb', line 117

def accept_alert!
  @connection.post "alert/accept"
  self
end

#active_elementObject

when moving with tab, or clicked



252
253
254
255
# File 'lib/webdriver/session.rb', line 252

def active_element
  el = @connection.get "element/active"
  Webdriver::Element.new el["ELEMENT"], @connection
end

#alert_textObject



122
123
124
# File 'lib/webdriver/session.rb', line 122

def alert_text
  @connection.get "alert/text"
end

#application_cache_statusObject



85
86
87
# File 'lib/webdriver/session.rb', line 85

def application_cache_status
  @connection.get "application_cache/status"
end

#back!Object



157
158
159
160
# File 'lib/webdriver/session.rb', line 157

def back!
  @connection.post "back"
  self
end

#chromium_heap_snapshotObject



94
95
96
# File 'lib/webdriver/session.rb', line 94

def chromium_heap_snapshot
  @connection.get "chromium/heap_snapshot"
end

#chromium_network_conditionsObject



98
99
100
# File 'lib/webdriver/session.rb', line 98

def chromium_network_conditions
  @connection.get "chromium/network_conditions"
end

#chromium_network_conditions!(conditions) ⇒ Object



102
103
104
105
# File 'lib/webdriver/session.rb', line 102

def chromium_network_conditions! conditions
  @connection.post "chromium/network_conditions", {}, conditions
  self
end

#chromium_network_conditions_delete!Object



107
108
109
110
# File 'lib/webdriver/session.rb', line 107

def chromium_network_conditions_delete!
  @connection.delete "chromium/network_conditions"
  self
end

#chromium_send_command_and_get_result!(opts) ⇒ Object



20
21
22
23
# File 'lib/webdriver/session.rb', line 20

def chromium_send_command_and_get_result! opts
  # cmd: "Browser.getVersion", params: {}
  @connection.post "chromium/send_command_and_get_result", {}, opts
end


187
188
189
190
# File 'lib/webdriver/session.rb', line 187

def cookie name
  resp = @connection.get File.join("cookie",name)
  Webdriver::Element.new resp["name"], @connection
end

#cookiesObject



176
177
178
179
180
# File 'lib/webdriver/session.rb', line 176

def cookies
  resp = @connection.get "cookie"

  resp.map { |el| Webdriver::Cookie.new el["name"], @connection }
end

#cookies_delete!Object



182
183
184
185
# File 'lib/webdriver/session.rb', line 182

def cookies_delete!
  @connection.delete "cookie"
  self
end

#delete!Object



10
11
12
13
# File 'lib/webdriver/session.rb', line 10

def delete!
  @connection.delete
  self
end

#dismiss_alert!Object



112
113
114
115
# File 'lib/webdriver/session.rb', line 112

def dismiss_alert!
  @connection.post "alert/dismiss"
  self
end

#element(using, value) ⇒ Object



257
258
259
260
261
262
263
# File 'lib/webdriver/session.rb', line 257

def element using, value
  el = @connection.post "element", {}, {
    using: using,
    value: value
  }
  Webdriver::Element.new el["ELEMENT"], @connection
end

#elements(using, value) ⇒ Object



265
266
267
268
269
270
271
# File 'lib/webdriver/session.rb', line 265

def elements using, value
  resp = @connection.post "elements", {}, {
    using: using,
    value: value
  }
  resp.map { |el| Webdriver::Element.new el["ELEMENT"], @connection }
end

#execute_sync!(script, args = []) ⇒ Object

TODO: hangs def execute_async! script, args=[]

@connection.post "execute/async", {}, {
  script: script,
  args: args
}

end



210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
# File 'lib/webdriver/session.rb', line 210

def execute_sync! script, args=[]
  resp = @connection.post "execute/sync", {}, {
    script: script,
    args: args
  }

  value = if resp.is_a?(Hash) && resp["ELEMENT"]
    begin
      el = Webdriver::Element.new resp["ELEMENT"], @connection
      el.tag
      el
    rescue
      resp
    end
  elsif resp.is_a?(Array)
    begin
      resp.map do |r|
        el = Webdriver::Element.new r["ELEMENT"], @connection
        el.tag
        el
      end
    rescue
      resp
    end
  else
    resp
  end
end

#forward!Object



162
163
164
165
# File 'lib/webdriver/session.rb', line 162

def forward!
  @connection.post "forward"
  self
end

#frame!(name) ⇒ Object

iframe id



134
135
136
137
138
139
# File 'lib/webdriver/session.rb', line 134

def frame! name
  @connection.post "frame", {}, {
    id: name
  }
  self
end

#is_loading?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/webdriver/session.rb', line 25

def is_loading?
  @connection.get "is_loading"
end

#keys=(opts) ⇒ Object



40
41
42
# File 'lib/webdriver/session.rb', line 40

def keys= opts
  @connection.post "keys", {}, opts
end

#locationObject



49
50
51
# File 'lib/webdriver/session.rb', line 49

def location
  @connection.get "location"
end

#location!(opts) ⇒ Object



53
54
55
56
# File 'lib/webdriver/session.rb', line 53

def location! opts
  #{location: {latitude: 20, longitude:20}}
  @connection.post "location", {}, opts
end

#log(type) ⇒ Object



79
80
81
82
83
# File 'lib/webdriver/session.rb', line 79

def log type
  @connection.post "log", {}, {
    type: type
  }
end

#log_typesObject



75
76
77
# File 'lib/webdriver/session.rb', line 75

def log_types
  @connection.get "log/types"
end

#moveto!(opts) ⇒ Object



44
45
46
47
# File 'lib/webdriver/session.rb', line 44

def moveto! opts
  # xoffset, yoffset, element
  @connection.post "moveto", {}, opts
end

#page_freeze!Object



29
30
31
# File 'lib/webdriver/session.rb', line 29

def page_freeze!
  @connection.post "goog/page/freeze"
end

#page_resume!Object



33
34
35
36
# File 'lib/webdriver/session.rb', line 33

def page_resume!
  # needs window min/max / timeout to resume
  @connection.post "goog/page/resume"
end

#parent_frame!Object



141
142
143
144
# File 'lib/webdriver/session.rb', line 141

def parent_frame!
  @connection.post "frame/parent", {}, {}
  self
end

#print!(opts) ⇒ Object



239
240
241
# File 'lib/webdriver/session.rb', line 239

def print! opts
  @connection.post "print", {}, opts
end

#refresh!Object



167
168
169
170
# File 'lib/webdriver/session.rb', line 167

def refresh!
  @connection.post "refresh"
  self
end

#reporting_generate_test_report!(opts) ⇒ Object



58
59
60
# File 'lib/webdriver/session.rb', line 58

def reporting_generate_test_report! opts
  @connection.post "reporting/generate_test_report", {}, opts
end

#screenshotObject



243
244
245
# File 'lib/webdriver/session.rb', line 243

def screenshot
  @connection.get "screenshot"
end

#screenshot_fullObject



247
248
249
# File 'lib/webdriver/session.rb', line 247

def screenshot_full
  @connection.get "screenshot/full"
end

#sourceObject

not implemented in chromedriver



90
91
92
# File 'lib/webdriver/session.rb', line 90

def source
  @connection.get "source"
end

#timeoutsObject



62
63
64
# File 'lib/webdriver/session.rb', line 62

def timeouts
  @connection.get "timeouts"
end

#timeouts!(opts) ⇒ Object



66
67
68
69
# File 'lib/webdriver/session.rb', line 66

def timeouts! opts
  @connection.post "timeouts", {}, opts
  self
end

#timeouts_async_script!(opts) ⇒ Object



71
72
73
# File 'lib/webdriver/session.rb', line 71

def timeouts_async_script! opts
  @connection.post "timeouts/async_script", {}, opts
end

#titleObject



172
173
174
# File 'lib/webdriver/session.rb', line 172

def title
  @connection.get "title"
end

#urlObject



153
154
155
# File 'lib/webdriver/session.rb', line 153

def url
  @connection.get "url"
end

#url!(url) ⇒ Object



146
147
148
149
150
151
# File 'lib/webdriver/session.rb', line 146

def url! url
  @connection.post "url", {}, {
    url: url
  }
  self
end

#windowsObject



15
16
17
18
# File 'lib/webdriver/session.rb', line 15

def windows
  value = @connection.get "window/handles"
  value.map { |id| Webdriver::Window.new id, @connection }
end