25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
# File 'lib/webdriver/connection.rb', line 25
def call method, path, ={}, body={}
path = "/#{path}"
body_json = body.to_json if body
Webdriver.debug [method, path, , body_json]
response = @mutex.synchronize do
case method
when :get
@http.get path
when :post
@http.post path, body_json
when :delete
@http.delete path, body_json
else
raise "err"
end
end
response_body = JSON.parse response.body
status = response_body.dig "status"
session_id = response_body.dig "sessionId"
value = response_body.dig "value"
case status
when nil
value
when 0
if method == :post && path == "/session"
value.merge("id" => session_id)
else value
end
when 7
raise Webdriver::NoSuchElementError.new value.dig("message")
when 8
raise Webdriver::NoSuchFrameError.new body[:id]
when 10
raise Webdriver::StaleElementReferenceError.new path
when 11
raise Webdriver::ElementNotInteractableError.new path
when 13
raise Webdriver::UnknownErrorUnhandledInspectorError.new value.dig("message")
when 17
raise Webdriver::JavascriptError.new value.dig("message")
when 23
raise Webdriver::NoSuchWindow.new value.dig("message")
when 26
raise Webdriver::UnexpectedAlertOpen.new value.dig("message")
when 27
raise Webdriver::NoSuchAlert.new value.dig("message")
when 28
raise Webdriver::ScriptTimeout.new value.dig("message")
when 1..nil
error_message = value.dig("message")
raise "#{status}: #{error_message}"
else
if method == :get && path == "/status"
value
else
raise "unknown status: #{status}"
end
end
end
|