Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract Safari version from safaridriver #13467

Merged
merged 4 commits into from
Nov 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 29 additions & 13 deletions tools/wpt/browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def find_webdriver(self, channel=None):
return NotImplemented

@abstractmethod
def version(self, binary=None):
def version(self, binary=None, webdriver_binary=None):
"""Retrieve the release version of the installed browser."""
return NotImplemented

Expand Down Expand Up @@ -367,7 +367,7 @@ def install_geckodriver_nightly(self, dest):

return path

def version(self, binary=None):
def version(self, binary=None, webdriver_binary=None):
"""Retrieve the release version of the installed browser."""
version_string = call(binary, "--version").strip()
m = re.match(r"Mozilla Firefox (.*)", version_string)
Expand All @@ -394,7 +394,7 @@ def find_webdriver(self, channel=None):
def install_webdriver(self, dest=None, channel=None):
raise NotImplementedError

def version(self, binary=None):
def version(self, binary=None, webdriver_binary=None):
return None


Expand Down Expand Up @@ -458,7 +458,7 @@ def install_webdriver(self, dest=None, channel=None):
os.chmod(path, st.st_mode | stat.S_IEXEC)
return path

def version(self, binary=None):
def version(self, binary=None, webdriver_binary=None):
binary = binary or self.binary
if uname[0] != "Windows":
try:
Expand Down Expand Up @@ -497,7 +497,7 @@ def install_webdriver(self, dest=None, channel=None):
chrome = Chrome()
return chrome.install_webdriver(dest, channel)

def version(self, binary):
def version(self, binary=None, webdriver_binary=None):
return None

class Opera(Browser):
Expand Down Expand Up @@ -562,7 +562,7 @@ def install_webdriver(self, dest=None, channel=None):
os.chmod(path, st.st_mode | stat.S_IEXEC)
return path

def version(self, binary):
def version(self, binary=None, webdriver_binary=None):
"""Retrieve the release version of the installed browser."""
binary = binary or self.binary
try:
Expand Down Expand Up @@ -593,7 +593,7 @@ def find_webdriver(self, channel=None):
def install_webdriver(self, dest=None, channel=None):
raise NotImplementedError

def version(self, binary):
def version(self, binary=None, webdriver_binary=None):
return None


Expand All @@ -619,7 +619,7 @@ def find_webdriver(self, channel=None):
def install_webdriver(self, dest=None, channel=None):
raise NotImplementedError

def version(self, binary):
def version(self, binary=None, webdriver_binary=None):
return None


Expand Down Expand Up @@ -647,8 +647,24 @@ def find_webdriver(self, channel=None):
def install_webdriver(self, dest=None, channel=None):
raise NotImplementedError

def version(self, binary):
return None
def version(self, binary=None, webdriver_binary=None):
if webdriver_binary is None:
logger.warn("Cannot find Safari version without safaridriver")
return None
# Use `safaridriver --version` to get the version. Example output:
# "Included with Safari 12.1 (14607.1.11)"
# "Included with Safari Technology Preview (Release 67, 13607.1.9.0.1)"
# The `--version` flag was added in STP 67, so allow the call to fail.
try:
version_string = call(webdriver_binary, "--version").strip()
except subprocess.CalledProcessError:
logger.warn("Failed to call %s --version", webdriver_binary)
return None
m = re.match(r"Included with Safari (.*)", version_string)
if not m:
logger.warn("Failed to extract version from: s%", version_string)
return None
return m.group(1)


class SafariWebDriver(Safari):
Expand Down Expand Up @@ -707,7 +723,7 @@ def find_webdriver(self, channel=None):
def install_webdriver(self, dest=None, channel=None):
raise NotImplementedError

def version(self, binary):
def version(self, binary=None, webdriver_binary=None):
"""Retrieve the release version of the installed browser."""
output = call(binary, "--version")
m = re.search(r"Servo ([0-9\.]+-[a-f0-9]+)?(-dirty)?$", output.strip())
Expand Down Expand Up @@ -737,7 +753,7 @@ def find_webdriver(self, channel=None):
def install_webdriver(self, dest=None, channel=None):
raise NotImplementedError

def version(self, binary):
def version(self, binary=None, webdriver_binary=None):
return None


Expand All @@ -759,5 +775,5 @@ def find_webdriver(self, channel=None):
def install_webdriver(self, dest=None, channel=None):
raise NotImplementedError

def version(self, binary):
def version(self, binary=None, webdriver_binary=None):
return None
3 changes: 2 additions & 1 deletion tools/wpt/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,8 @@ def setup_wptrunner(venv, prompt=True, install_browser=False, **kwargs):

venv.install_requirements(os.path.join(wptrunner_path, "requirements.txt"))

kwargs['browser_version'] = setup_cls.browser.version(kwargs.get("binary"))
kwargs['browser_version'] = setup_cls.browser.version(binary=kwargs.get("binary"),
webdriver_binary=kwargs.get("webdriver_binary"))
return kwargs


Expand Down
32 changes: 32 additions & 0 deletions tools/wpt/tests/test_browser.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import mock
import subprocess

from tools.wpt import browser

@mock.patch('subprocess.check_output')
def test_safari_version(mocked_check_output):
safari = browser.Safari()

# Safari
mocked_check_output.return_value = 'Included with Safari 12.1 (14607.1.11)'
assert safari.version(webdriver_binary="safaridriver") == '12.1 (14607.1.11)'

# Safari Technology Preview
mocked_check_output.return_value = 'Included with Safari Technology Preview (Release 67, 13607.1.9.0.1)'
assert safari.version(webdriver_binary="safaridriver") == 'Technology Preview (Release 67, 13607.1.9.0.1)'

@mock.patch('subprocess.check_output')
def test_safari_version_errors(mocked_check_output):
safari = browser.Safari()

# No webdriver_binary
assert safari.version() is None

# `safaridriver --version` return gibberish
mocked_check_output.return_value = 'gibberish'
assert safari.version(webdriver_binary="safaridriver") is None

# `safaridriver --version` fails (as it does for Safari <=12.0)
mocked_check_output.return_value = 'dummy'
mocked_check_output.side_effect = subprocess.CalledProcessError(1, 'cmd')
assert safari.version(webdriver_binary="safaridriver") is None
2 changes: 1 addition & 1 deletion tools/wpt/tests/test_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ def test_setup_wptrunner(venv, product):
parser = run.create_parser()
kwargs = vars(parser.parse_args(["--channel=nightly", product]))
kwargs["prompt"] = False
kwargs["webdriver_binary"] = "fake"
# Hack to get a real existing path
kwargs["binary"] = sys.argv[0]
kwargs["webdriver_binary"] = sys.argv[0]
if kwargs["product"] == "sauce":
kwargs["product"] = "sauce:firefox:63"
run.setup_wptrunner(venv, **kwargs)