Skip to content

Commit 36e81d7

Browse files
authored
Merge pull request #552 from seleniumbase/safari-updates
Updates to running WebDriver tests with Safari
2 parents 7a28677 + d7799b9 commit 36e81d7

File tree

8 files changed

+50
-7
lines changed

8 files changed

+50
-7
lines changed

examples/test_apple_site.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from seleniumbase import BaseCase
2+
3+
4+
class AppleTestClass(BaseCase):
5+
6+
def test_apple_developer_site_webdriver_instructions(self):
7+
self.demo_mode = True
8+
self.demo_sleep = 0.5
9+
self.message_duration = 2.0
10+
self.open("https://developer.apple.com/search/")
11+
page = "Testing with WebDriver in Safari"
12+
self.update_text('[placeholder*="developer.apple.com"]', page + "\n")
13+
self.click("link=Testing with WebDriver in Safari")
14+
self.assert_element('[href="/documentation"]')
15+
self.assert_text("Testing with WebDriver in Safari", "h1")
16+
self.highlight("div.topic-description p")
17+
self.highlight("h2")
18+
h3 = "h3:nth-of-type(%s)"
19+
self.assert_text("Make Sure You Have Safari’s WebDriver", h3 % "1")
20+
self.assert_text("Get the Correct Selenium Library", h3 % "2")
21+
self.assert_text("Configure Safari to Enable WebDriver", h3 % "3")
22+
self.assert_text("Write a WebDriver Testing Suite", h3 % "4")
23+
self.assert_text("Run Your Test", h3 % "5")

help_docs/method_summary.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,8 @@ self.execute_async_script(script, timeout=None)
138138

139139
self.safe_execute_script(script)
140140

141+
self.set_window_rect(x, y, width, height)
142+
141143
self.set_window_size(width, height)
142144

143145
self.maximize_window()

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ soupsieve==1.9.5;python_version<"3.5"
2929
soupsieve==2.0;python_version>="3.5"
3030
beautifulsoup4==4.9.0
3131
atomicwrites==1.3.0
32-
cryptography==2.9
32+
cryptography==2.9.2
3333
pyopenssl==19.1.0
3434
pygments==2.5.2;python_version<"3.5"
3535
pygments==2.6.1;python_version>="3.5"

seleniumbase/core/browser_launcher.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,13 @@ def _set_chrome_options(
241241
return chrome_options
242242

243243

244+
def _set_safari_capabilities():
245+
from selenium.webdriver.safari.webdriver import DesiredCapabilities as SDC
246+
safari_capabilities = SDC.SAFARI.copy()
247+
safari_capabilities["cleanSession"] = True
248+
return safari_capabilities
249+
250+
244251
def _create_firefox_profile(
245252
downloads_path, proxy_string, user_agent, disable_csp):
246253
profile = webdriver.FirefoxProfile()
@@ -674,7 +681,8 @@ def get_local_driver(
674681
if ("-n" in sys.argv) or ("-n=" in arg_join) or (arg_join == "-c"):
675682
# Skip if multithreaded
676683
raise Exception("Can't run Safari tests in multi-threaded mode!")
677-
return webdriver.Safari()
684+
safari_capabilities = _set_safari_capabilities()
685+
return webdriver.Safari(desired_capabilities=safari_capabilities)
678686
elif browser_name == constants.Browser.OPERA:
679687
if LOCAL_OPERADRIVER and os.path.exists(LOCAL_OPERADRIVER):
680688
try:

seleniumbase/fixtures/base_case.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1473,6 +1473,10 @@ def safe_execute_script(self, script):
14731473
self.activate_jquery() # It's a good thing we can define it here
14741474
self.execute_script(script)
14751475

1476+
def set_window_rect(self, x, y, width, height):
1477+
self.driver.set_window_rect(x, y, width, height)
1478+
self.__demo_mode_pause_if_active()
1479+
14761480
def set_window_size(self, width, height):
14771481
self.driver.set_window_size(width, height)
14781482
self.__demo_mode_pause_if_active()
@@ -1674,7 +1678,7 @@ def get_new_driver(self, browser=None, headless=None,
16741678
width = settings.HEADLESS_START_WIDTH
16751679
height = settings.HEADLESS_START_HEIGHT
16761680
try:
1677-
self.set_window_size(width, height)
1681+
self.driver.set_window_size(width, height)
16781682
self.wait_for_ready_state_complete()
16791683
except Exception:
16801684
# This shouldn't fail, but in case it does,
@@ -1702,6 +1706,11 @@ def get_new_driver(self, browser=None, headless=None,
17021706
self.wait_for_ready_state_complete()
17031707
except Exception:
17041708
pass # Keep existing browser resolution
1709+
else:
1710+
try:
1711+
self.driver.set_window_rect(10, 30, 945, 630)
1712+
except Exception:
1713+
pass
17051714
if self.start_page and len(self.start_page) >= 4:
17061715
if page_utils.is_valid_url(self.start_page):
17071716
self.open(self.start_page)

seleniumbase/plugins/pytest_plugin.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,8 @@ def pytest_addoption(parser):
216216
username:password@servername:port OR
217217
A dict key from proxy_list.PROXY_LIST
218218
Default: None.""")
219-
parser.addoption('--agent', action='store',
219+
parser.addoption('--agent', '--user-agent', '--user_agent',
220+
action='store',
220221
dest='user_agent',
221222
default=None,
222223
help="""Designates the User-Agent for the browser to use.

seleniumbase/plugins/selenium_plugin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ def options(self, parser, env):
119119
A dict key from proxy_list.PROXY_LIST
120120
Default: None.""")
121121
parser.add_option(
122-
'--agent',
122+
'--agent', '--user-agent', '--user_agent',
123123
action='store',
124124
dest='user_agent',
125125
default=None,

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545

4646
setup(
4747
name='seleniumbase',
48-
version='1.37.8',
48+
version='1.37.9',
4949
description='Fast, Easy, and Reliable Browser Automation & Testing.',
5050
long_description=long_description,
5151
long_description_content_type='text/markdown',
@@ -111,7 +111,7 @@
111111
'soupsieve==2.0;python_version>="3.5"',
112112
'beautifulsoup4==4.9.0',
113113
'atomicwrites==1.3.0',
114-
'cryptography==2.9',
114+
'cryptography==2.9.2',
115115
'pyopenssl==19.1.0',
116116
'pygments==2.5.2;python_version<"3.5"',
117117
'pygments==2.6.1;python_version>="3.5"',

0 commit comments

Comments
 (0)