Skip to content

Commit 4525159

Browse files
committed
Removing temporary browser's profile directory from /tmp once the webdriver closes.
Avoids the pilling of many old temporary directories in /tmp, after multiple runs of the tests.
1 parent 566e837 commit 4525159

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

codebender_testing/config.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ def create_webdriver(command_executor, desired_capabilities):
122122
# missing from the desired_capabilities dict above.
123123
_capabilities = desired_capabilities
124124
browser_profile = None
125+
browser_profile_path = None
125126

126127
if browser_name == "chrome":
127128
desired_capabilities = DesiredCapabilities.CHROME.copy()
@@ -149,12 +150,16 @@ def create_webdriver(command_executor, desired_capabilities):
149150
desired_capabilities = DesiredCapabilities.FIREFOX.copy()
150151
desired_capabilities.update(_capabilities)
151152
browser_profile = _get_firefox_profile()
153+
browser_profile_path = browser_profile.path
152154
browser_profile.set_preference("general.useragent.override", TESTS_USER_AGENT)
153155
desired_capabilities["firefox_profile"] = browser_profile.update_preferences()
154156
else:
155157
raise ValueError("Invalid webdriver %s (only chrome and firefox are supported)" % browser_name)
156-
return webdriver.Remote(
157-
command_executor=command_executor,
158-
desired_capabilities=desired_capabilities,
159-
browser_profile=browser_profile,
160-
)
158+
return {
159+
'driver': webdriver.Remote(
160+
command_executor=command_executor,
161+
desired_capabilities=desired_capabilities,
162+
browser_profile=browser_profile,
163+
),
164+
'profile_path': browser_profile_path
165+
}

tests/conftest.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import os
1010
import sys
11+
import shutil
1112

1213
import pytest
1314

@@ -55,7 +56,9 @@ def webdriver(request, desired_capabilities):
5556

5657
command_executor = os.environ['CODEBENDER_SELENIUM_HUB_URL']
5758

58-
driver = config.create_webdriver(command_executor, desired_capabilities)
59+
webdriver = config.create_webdriver(command_executor, desired_capabilities)
60+
driver = webdriver['driver']
61+
profile_path = webdriver['profile_path']
5962

6063
# TODO: update sauce status via SauceClient, but only if the command_executor
6164
# is a sauce URL.
@@ -70,6 +73,9 @@ def finalizer():
7073
# sauce.jobs.update_job(driver.session_id, passed=False)
7174
finally:
7275
driver.quit()
76+
if profile_path and os.path.exists(profile_path):
77+
print '\n\nRemoving browser profile directory:', profile_path
78+
shutil.rmtree(profile_path, ignore_errors=True)
7379

7480
request.addfinalizer(finalizer)
7581
return driver

0 commit comments

Comments
 (0)