Skip to content

Commit 56b3440

Browse files
carlosgcamposAutomatedTester
authored andcommitted
[py] Add WebKitGTK driver (#4635)
* [py] Add WebKitGTK driver
1 parent fa164f6 commit 56b3440

9 files changed

Lines changed: 238 additions & 0 deletions

File tree

py/conftest.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
'PhantomJS',
4545
'Remote',
4646
'Safari',
47+
'WebKitGTK',
4748
)
4849

4950

py/selenium/webdriver/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
from .blackberry.webdriver import WebDriver as BlackBerry # noqa
2727
from .phantomjs.webdriver import WebDriver as PhantomJS # noqa
2828
from .android.webdriver import WebDriver as Android # noqa
29+
from .webkitgtk.webdriver import WebDriver as WebKitGTK # noqa
30+
from .webkitgtk.options import Options as WebKitGTKOptions # noqa
2931
from .remote.webdriver import WebDriver as Remote # noqa
3032
from .common.desired_capabilities import DesiredCapabilities # noqa
3133
from .common.action_chains import ActionChains # noqa

py/selenium/webdriver/common/desired_capabilities.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,3 +120,9 @@ class DesiredCapabilities(object):
120120
"platform": "ANY",
121121
"javascriptEnabled": True,
122122
}
123+
124+
WEBKITGTK = {
125+
"browserName": "MiniBrowser",
126+
"version": "",
127+
"platform": "ANY",
128+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Licensed to the Software Freedom Conservancy (SFC) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The SFC licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
# Licensed to the Software Freedom Conservancy (SFC) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The SFC licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
19+
20+
21+
class Options(object):
22+
23+
def __init__(self):
24+
self._browser_executable_path = ''
25+
self._browser_arguments = []
26+
self._overlay_scrollbars_enabled = True
27+
28+
@property
29+
def browser_executable_path(self):
30+
"""
31+
Returns the location of the browser binary otherwise an empty string
32+
"""
33+
return self._browser_executable_path
34+
35+
@browser_executable_path.setter
36+
def browser_executable_path(self, value):
37+
"""
38+
Allows you to set the browser binary to launch
39+
40+
:Args:
41+
- value : path to the browser binary
42+
"""
43+
self._browser_executable_path = value
44+
45+
@property
46+
def browser_arguments(self):
47+
"""
48+
Returns a list of arguments needed for the browser
49+
"""
50+
return self._browser_arguments
51+
52+
def add_browser_argument(self, argument):
53+
"""
54+
Adds an argument to the list
55+
56+
:Args:
57+
- Sets the arguments
58+
"""
59+
if argument:
60+
self._browser_arguments.append(argument)
61+
else:
62+
raise ValueError("argument can not be null")
63+
64+
@property
65+
def overlay_scrollbars_enabled(self):
66+
"""
67+
Returns whether overlay scrollbars should be enabled
68+
"""
69+
return self._overlay_scrollbars_enabled
70+
71+
@overlay_scrollbars_enabled.setter
72+
def overlay_scrollbars_enabled(self, value):
73+
"""
74+
Allows you to enable or disable overlay scrollbars
75+
76+
:Args:
77+
- value : True or False
78+
"""
79+
self._overlay_scrollbars_enabled = value
80+
81+
def to_capabilities(self):
82+
"""
83+
Creates a capabilities with all the options that have been set and
84+
returns a dictionary with everything
85+
"""
86+
webkitgtk = DesiredCapabilities.WEBKITGTK.copy()
87+
88+
browser_options = {}
89+
if self.browser_executable_path:
90+
browser_options["binary"] = self.browser_executable_path
91+
browser_options["args"] = self.browser_arguments
92+
browser_options["useOverlayScrollbars"] = self.overlay_scrollbars_enabled
93+
94+
webkitgtk["webkitgtk:browserOptions"] = browser_options
95+
96+
return webkitgtk
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Licensed to the Software Freedom Conservancy (SFC) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The SFC licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
from selenium.webdriver.common import service
19+
20+
21+
class Service(service.Service):
22+
"""
23+
Object that manages the starting and stopping of the WebKitGTKDriver
24+
"""
25+
26+
def __init__(self, executable_path, port=0, log_path=None):
27+
"""
28+
Creates a new instance of the Service
29+
30+
:Args:
31+
- executable_path : Path to the WebKitGTKDriver
32+
- port : Port the service is running on
33+
- log_path : Path for the WebKitGTKDriver service to log to
34+
"""
35+
log_file = open(log_path, "wb") if log_path is not None and log_path != "" else None
36+
service.Service.__init__(self, executable_path, port, log_file)
37+
38+
def command_line_args(self):
39+
return ["-p", "%d" % self.port]
40+
41+
def send_remote_shutdown_command(self):
42+
pass
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# Licensed to the Software Freedom Conservancy (SFC) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The SFC licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
try:
19+
import http.client as http_client
20+
except ImportError:
21+
import httplib as http_client
22+
23+
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
24+
from selenium.webdriver.remote.webdriver import WebDriver as RemoteWebDriver
25+
from .service import Service
26+
27+
28+
class WebDriver(RemoteWebDriver):
29+
"""
30+
Controls the WebKitGTKDriver and allows you to drive the browser.
31+
"""
32+
33+
def __init__(self, executable_path="WebKitWebDriver", port=0,
34+
browser_options=None,
35+
desired_capabilities=DesiredCapabilities.WEBKITGTK,
36+
service_log_path=None):
37+
"""
38+
Creates a new instance of the WebKitGTK driver.
39+
40+
Starts the service and then creates new instance of WebKitGTK Driver.
41+
42+
:Args:
43+
- executable_path : path to the executable. If the default is used it assumes the executable is in the $PATH.
44+
- port : port you would like the service to run, if left as 0, a free port will be found.
45+
- browser_options : an instance of WebKitGTKOptions
46+
- desired_capabilities : Dictionary object with desired capabilities
47+
- service_log_path : Path to write service stdout and stderr output.
48+
"""
49+
if browser_options is not None:
50+
capabilities = browser_options.to_capabilities()
51+
capabilities.update(desired_capabilities)
52+
desired_capabilities = capabilities
53+
54+
self.service = Service(executable_path, port=port, log_path=service_log_path)
55+
self.service.start()
56+
57+
RemoteWebDriver.__init__(
58+
self,
59+
command_executor=self.service.service_url,
60+
desired_capabilities=desired_capabilities)
61+
self._is_remote = False
62+
63+
def quit(self):
64+
"""
65+
Closes the browser and shuts down the WebKitGTKDriver executable
66+
that is started when starting the WebKitGTKDriver
67+
"""
68+
try:
69+
RemoteWebDriver.quit(self)
70+
except http_client.BadStatusLine:
71+
pass
72+
finally:
73+
self.service.stop()

py/test/selenium/webdriver/common/driver_element_finding_tests.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,7 @@ def test_Finding_ALink_By_Xpath_Using_Contains_Keyword_Should_Work(driver, pages
358358
@pytest.mark.xfail_marionette(raises=WebDriverException)
359359
@pytest.mark.xfail_phantomjs(raises=InvalidSelectorException)
360360
@pytest.mark.xfail_safari(raises=NoSuchElementException)
361+
@pytest.mark.xfail_webkitgtk(raises=InvalidSelectorException)
361362
def test_Should_Be_Able_To_Find_Element_By_XPath_With_Namespace(driver, pages):
362363
pages.load("svgPage.html")
363364
element = driver.find_element(By.XPATH, "//svg:svg//svg:text")

py/test/selenium/webdriver/common/frame_switching_tests.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,7 @@ def testShouldBeAbleToSwitchToTheTopIfTheFrameIsDeletedFromUnderUsWithWebelement
382382
@pytest.mark.xfail_phantomjs(raises=BadStatusLine)
383383
@pytest.mark.xfail_marionette(raises=WebDriverException,
384384
reason='https://github.com/mozilla/geckodriver/issues/614')
385+
@pytest.mark.xfail_webkitgtk(raises=NoSuchElementException)
385386
def testShouldNotBeAbleToDoAnythingTheFrameIsDeletedFromUnderUs(driver, pages):
386387
if driver.name == 'firefox' and driver.w3c:
387388
pytest.skip('Stalls tests, https://bugzilla.mozilla.org/show_bug.cgi?id=1410799')

0 commit comments

Comments
 (0)