Skip to content

Commit b2a5013

Browse files
committed
Removing Chrome profile after testing.
1 parent 02bd103 commit b2a5013

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

codebender_testing/config.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
import yaml
77
import simplejson
88
import pytest
9-
9+
import string
10+
import random
1011

1112
def _rel_path(*args):
1213
"""Returns a path relative to config.py file's directory."""
@@ -103,6 +104,12 @@ def _get_firefox_profile():
103104
)
104105
return firefox_profile
105106

107+
def _get_chrome_profile():
108+
"""Returns the Chrome profile directory to be used for the Chrome webdriver."""
109+
seed = string.ascii_letters + string.digits
110+
profile_hash = ''.join(random.choice(seed) for x in range(6))
111+
return '.org.chromium.Chromium.' + profile_hash
112+
106113
def get_browsers(capabilities_file_path=None):
107114
"""Returns a list of capabilities. Each item in the list will cause
108115
the entire suite of tests to be re-run for a browser with those
@@ -138,17 +145,19 @@ def create_webdriver(command_executor, desired_capabilities):
138145
BROWSER = "chrome"
139146
desired_capabilities = DesiredCapabilities.CHROME.copy()
140147
desired_capabilities.update(_capabilities)
148+
options = chrome.options.Options()
149+
browser_profile_path = os.path.join('/tmp', _get_chrome_profile())
150+
options.add_argument('--user-data-dir=' + browser_profile_path)
141151
if desired_capabilities["version"] > CHROME_EXT_MAX_CHROME_VERSION:
142152
# Add new chrome extension to capabilities.
143-
options = chrome.options.Options()
144153
options.add_extension(os.path.join(_EXTENSIONS_DIR, _CHROME_APP_FNAME))
145154
options.add_argument("--user-agent=" + TESTS_USER_AGENT_CHROME)
146-
desired_capabilities.update(options.to_capabilities())
147-
desired_capabilities.update(_capabilities)
148155
else:
149156
raise ValueError("The testing suite only supports Chrome versions greater than v%d, "
150157
"but v%d was specified. Please specify a higher version number."
151158
% (CHROME_EXT_MAX_CHROME_VERSION, desired_capabilities["version"]))
159+
desired_capabilities.update(options.to_capabilities())
160+
desired_capabilities.update(_capabilities)
152161

153162
elif browser_name == "firefox":
154163
desired_capabilities = DesiredCapabilities.FIREFOX.copy()
@@ -159,6 +168,7 @@ def create_webdriver(command_executor, desired_capabilities):
159168
desired_capabilities["firefox_profile"] = browser_profile.update_preferences()
160169
else:
161170
raise ValueError("Invalid webdriver %s (only chrome and firefox are supported)" % browser_name)
171+
162172
return {
163173
'driver': webdriver.Remote(
164174
command_executor=command_executor,

0 commit comments

Comments
 (0)