Skip to content

Commit 0987ba3

Browse files
authored
Fix error initialisation (#67)
* fix Error::WebDriverError initliase error * update changelog
1 parent 0064cee commit 0987ba3

File tree

7 files changed

+71
-8
lines changed

7 files changed

+71
-8
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ All notable changes to this project will be documented in this file.
88
- [iOS] Add `start_performance_record` and `get_performance_record`
99

1010
### Bug fixes
11+
- Fix _create_session attempt to throw non-existent error type Appium::Core::Error::WebDriverError_ [#66](https://github.com/appium/ruby_lib_core/issues/66)
1112

1213
### Deprecations
1314

lib/appium_lib_core/common/base/bridge.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def self.handshake(**opts)
2222

2323
if desired_capabilities.is_a?(Symbol)
2424
unless ::Selenium::WebDriver::Remote::Capabilities.respond_to?(desired_capabilities)
25-
raise Error::WebDriverError, "invalid desired capability: #{desired_capabilities.inspect}"
25+
raise ::Selenium::WebDriver::Error::WebDriverError, "invalid desired capability: #{desired_capabilities.inspect}"
2626
end
2727
desired_capabilities = Remote::Capabilities.__send__(desired_capabilities)
2828
end
@@ -105,7 +105,7 @@ def create_session(desired_capabilities)
105105
end
106106

107107
unless @session_id
108-
raise Error::WebDriverError, 'no sessionId in returned payload'
108+
raise ::Selenium::WebDriver::Error::WebDriverError, 'no sessionId in returned payload'
109109
end
110110

111111
json_create(oss_status, value)

lib/appium_lib_core/driver.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -190,14 +190,14 @@ def start_driver(server_url: nil,
190190
# Ignore setting default wait if the target driver has no implementation
191191
def set_implicit_wait_by_default(wait)
192192
@driver.manage.timeouts.implicit_wait = wait
193-
rescue Selenium::WebDriver::Error::UnknownError => e
193+
rescue ::Selenium::WebDriver::Error::UnknownError => e
194194
unless e.message.include?('The operation requested is not yet implemented')
195195
raise e.message, ::Appium::Core::Error::ServerError
196196
end
197197

198198
Appium::Logger.debug(e.message)
199199
{}
200-
rescue Selenium::WebDriver::Error::WebDriverError => e
200+
rescue ::Selenium::WebDriver::Error::WebDriverError => e
201201
# FIXME: Temporary rescue until Appium support W3C's implicit wait
202202
# https://github.com/jlipps/simple-wd-spec#set-timeouts
203203
unless e.message.include?('Parameters were incorrect. We wanted {"required":["type","ms"]} and you sent ["implicit"]')

test/functional/android/android/device_test.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def test_background_reset
6060
assert_equal 'App', e.name
6161

6262
@@driver.background_app(-1)
63-
error = assert_raises Selenium::WebDriver::Error::WebDriverError do
63+
error = assert_raises ::Selenium::WebDriver::Error::WebDriverError do
6464
@@driver.find_element :accessibility_id, 'App'
6565
end
6666
assert 'An element could not be located on the page using the given search parameters.', error.message
@@ -277,7 +277,7 @@ def test_open_notifications
277277

278278
# Sometimes, we should wait animation
279279
@@core.wait(timeout: 5) do
280-
error = assert_raises Selenium::WebDriver::Error::WebDriverError do
280+
error = assert_raises ::Selenium::WebDriver::Error::WebDriverError do
281281
@@driver.find_element :accessibility_id, ':-|'
282282
end
283283
assert 'An element could not be located on the page using the given search parameters.', error.message

test/functional/ios/ios/device_test.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def test_background_reset
5757
assert_equal 'TextView', e.name
5858

5959
@@driver.background_app(-1)
60-
error = assert_raises Selenium::WebDriver::Error::WebDriverError do
60+
error = assert_raises ::Selenium::WebDriver::Error::WebDriverError do
6161
@@driver.find_element :accessibility_id, 'TextView'
6262
end
6363
assert 'An element could not be located on the page using the given search parameters.', error.message
@@ -213,7 +213,7 @@ def test_hidekeyboard
213213
sleep 1 # wait animation
214214
end
215215

216-
m = assert_raises Selenium::WebDriver::Error::WebDriverError do
216+
m = assert_raises ::Selenium::WebDriver::Error::WebDriverError do
217217
@@driver.find_element(:class, 'XCUIElementTypeKeyboard')
218218
end
219219
assert 'An element could not be located on the page using the given search parameters.', m.message

test/unit/android/webdriver_test.rb

+34
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,40 @@ def setup
1212
@driver ||= android_mock_create_session
1313
end
1414

15+
def test_no_session_id
16+
response = {
17+
status: 0, # To make bridge.dialect == :oss
18+
value: {
19+
capabilities: {
20+
desired: {
21+
platformName: 'Android',
22+
automationName: 'uiautomator2',
23+
platformVersion: '7.1.1',
24+
deviceName: 'Android Emulator',
25+
app: '/test/apps/ApiDemos-debug.apk',
26+
newCommandTimeout: 240,
27+
unicodeKeyboard: true,
28+
resetKeyboard: true
29+
},
30+
platformName: 'Android',
31+
automationName: 'uiautomator2',
32+
platformVersion: '7.1.1',
33+
deviceName: 'emulator-5554',
34+
app: '/test/apps/ApiDemos-debug.apk'
35+
}
36+
}
37+
}.to_json
38+
39+
stub_request(:post, 'http://127.0.0.1:4723/wd/hub/session')
40+
.to_return(headers: HEADER, status: 200, body: response)
41+
42+
error = assert_raises ::Selenium::WebDriver::Error::WebDriverError do
43+
@core.start_driver
44+
end
45+
46+
assert_equal 'no sessionId in returned payload', error.message
47+
end
48+
1549
def test_remote_status
1650
stub_request(:get, 'http://127.0.0.1:4723/wd/hub/status')
1751
.to_return(headers: HEADER, status: 200, body: { value: 'xxxx' }.to_json)

test/unit/android/webdriver_w3c_test.rb

+28
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,34 @@ def setup
1212
@driver ||= android_mock_create_session_w3c
1313
end
1414

15+
def test_no_session_id
16+
response = {
17+
value: {
18+
capabilities: {
19+
platformName: :android,
20+
automationName: 'uiautomator2',
21+
app: 'test/functional/app/api.apk',
22+
platformVersion: '7.1.1',
23+
deviceName: 'Android Emulator',
24+
appPackage: 'io.appium.android.apis',
25+
appActivity: 'io.appium.android.apis.ApiDemos',
26+
someCapability: 'some_capability',
27+
unicodeKeyboard: true,
28+
resetKeyboard: true
29+
}
30+
}
31+
}.to_json
32+
33+
stub_request(:post, 'http://127.0.0.1:4723/wd/hub/session')
34+
.to_return(headers: HEADER, status: 200, body: response)
35+
36+
error = assert_raises ::Selenium::WebDriver::Error::WebDriverError do
37+
@core.start_driver
38+
end
39+
40+
assert_equal 'no sessionId in returned payload', error.message
41+
end
42+
1543
def test_remote_status
1644
stub_request(:get, 'http://127.0.0.1:4723/wd/hub/status')
1745
.to_return(headers: HEADER, status: 200, body: { value: 'xxxx' }.to_json)

0 commit comments

Comments
 (0)