X Tutup
Skip to content

Commit 5eacfc8

Browse files
committed
Better logging when error in closing browser
1 parent d56564d commit 5eacfc8

File tree

4 files changed

+34
-2
lines changed

4 files changed

+34
-2
lines changed

atest/acceptance/open_and_close.robot

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
*** Settings ***
22
Suite Teardown Close All Browsers
33
Resource resource.robot
4+
Library ../resources/testlibs/cache_error.py
45

56
*** Test Cases ***
67
Browser Should Open And Close
@@ -77,3 +78,13 @@ Open Browser desired_capabilities As Dictionary
7778
${caps} Create Dictionary foo=${True}
7879
Open Browser ${ROOT}/forms/prefilled_email_form.html ${BROWSER}
7980
... remote_url=${REMOTE_URL} desired_capabilities=${caps}
81+
82+
When Closing Browsers Causes An Error
83+
[Documentation]
84+
... FAIL AttributeError: 'NoneType' object has no attribute 'quit'
85+
... LOG 3:8 ERROR When closing browser, received exception: 'NoneType' object has no attribute 'quit'
86+
... LOG 3:9 ERROR When closing browser, received exception: 'NoneType' object has no attribute 'quit'
87+
Open Browser ${ROOT}/forms/prefilled_email_form.html ${BROWSER} Browser 1
88+
... remote_url=${REMOTE_URL} desired_capabilities=${DESIRED_CAPABILITIES}
89+
Invalidate Driver
90+
Close All Browsers
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from robot.libraries.BuiltIn import BuiltIn
2+
3+
4+
def invalidate_driver():
5+
sl = BuiltIn().get_library_instance('SeleniumLibrary')
6+
sl.register_driver(None, 'tidii')
7+
sl.register_driver(None, 'foobar')

src/SeleniumLibrary/keywords/webdrivertools.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
import os
1818
import warnings
1919

20+
from robot.api import logger
2021
from robot.utils import ConnectionCache
2122
from selenium import webdriver
22-
from selenium.common.exceptions import WebDriverException
2323

2424
from SeleniumLibrary.utils import is_falsy, is_truthy, is_noney
2525

@@ -240,7 +240,8 @@ def close_all(self):
240240
def _quit(self, driver, error):
241241
try:
242242
driver.quit()
243-
except WebDriverException as exception:
243+
except Exception as exception:
244+
logger.error('When closing browser, received exception: %s' % exception)
244245
error = exception
245246
return error
246247

utest/test/keywords/test_webdrivercache.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,19 @@ def test_close_all_cache_all_quite_fails(self):
198198
cache.close_all()
199199
self.verify_cache(cache)
200200

201+
def test_close_all_cache_not_selenium_error(self):
202+
cache = WebDriverCache()
203+
driver0, driver1, driver2 = mock(), mock(), mock()
204+
when(driver0).quit().thenRaise(RemoteDriverServerException('stuff.'))
205+
when(driver1).quit().thenRaise(ValueError('stuff.'))
206+
when(driver2).quit().thenRaise(TimeoutException('timeout.'))
207+
cache.register(driver0, 'bar0')
208+
cache.register(driver1, 'bar1')
209+
cache.register(driver2, 'bar2')
210+
with self.assertRaises(TimeoutException):
211+
cache.close_all()
212+
self.verify_cache(cache)
213+
201214
def test_close_all_no_error(self):
202215
cache = WebDriverCache()
203216
driver0, driver1, driver2 = mock(), mock(), mock()

0 commit comments

Comments
 (0)
X Tutup