Skip to content

Commit 41736a7

Browse files
author
AutomatedTester
committed
Initial implementation of EdgeDriver for python
1 parent 36b48db commit 41736a7

File tree

10 files changed

+232
-2
lines changed

10 files changed

+232
-2
lines changed

MANIFEST.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ recursive-include py/selenium/webdriver/phantomjs *.py
99
recursive-include py/selenium/webdriver/firefox *.py *.xpi *.json
1010
recursive-include py/selenium/webdriver/firefox/x86 *.so
1111
recursive-include py/selenium/webdriver/firefox/amd64 *.so
12-
recursive-include py/selenium/webdriver/ie *.py
12+
recursive-include py/selenium/webdriver/ie *.py
13+
recursive-include py/selenium/webdriver/edge *.py
1314
recursive-include py/selenium/webdriver/remote *.py
1415
recursive-include py/selenium/webdriver/support *.py
1516
include py/selenium/selenium.py
1617
include py/selenium/__init__.py
1718
include py/CHANGES
1819
include py/README
1920
recursive-include selenium.egg-info *
20-

py/build.desc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ py_test(
4040
deps = [ ":test_ie" ],
4141
browsers = [ "ie" ])
4242

43+
py_test(
44+
name = "edge_test",
45+
deps = [":test_edge"],
46+
browsers = [ "edge"])
47+
4348
py_test(
4449
name = "remote_firefox_test",
4550
remote_firefox_specific_tests = [ "test/selenium/webdriver/remote/*_tests.py" ],
@@ -69,6 +74,7 @@ py_test(
6974
"chrome",
7075
"ff",
7176
"ie",
77+
"edge",
7278
"blackberry",
7379
"phantomjs",
7480
"remote_firefox",

py/selenium/webdriver/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from .chrome.webdriver import WebDriver as Chrome
2121
from .chrome.options import Options as ChromeOptions
2222
from .ie.webdriver import WebDriver as Ie
23+
from .edge.webdriver import WebDriver as Edge
2324
from .opera.webdriver import WebDriver as Opera
2425
from .safari.webdriver import WebDriver as Safari
2526
from .blackberry.webdriver import WebDriver as BlackBerry

py/selenium/webdriver/common/desired_capabilities.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,12 @@ class DesiredCapabilities(object):
6262
"javascriptEnabled": True,
6363
}
6464

65+
EDGE = {
66+
"browserName": "MicrosoftEdge",
67+
"version": "",
68+
"platform": "WINDOWS"
69+
}
70+
6571
CHROME = {
6672
"browserName": "chrome",
6773
"version": "",
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: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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._page_load_strategy = "normal"
25+
26+
@property
27+
def page_load_strategy(self):
28+
return self._page_load_strategy
29+
30+
@page_load_strategy.setter
31+
def page_load_strategy(self, value):
32+
if value not in ['normal', 'eager', 'none']:
33+
raise ValueError("Page Load Strategy should be 'normal', 'eager' or 'none'.")
34+
self._page_load_strategy = value
35+
36+
def to_capabilities(self):
37+
"""
38+
Creates a capabilities with all the options that have been set and
39+
40+
returns a dictionary with everything
41+
"""
42+
edge = DesiredCapabilities.EDGE.copy()
43+
edge['pageLoadStrategy'] = self._page_load_strategy
44+
45+
return edge
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
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+
import subprocess
18+
from subprocess import PIPE
19+
import time
20+
from selenium.common.exceptions import WebDriverException
21+
from selenium.webdriver.common import utils
22+
23+
class Service(object):
24+
"""
25+
Object that manages the starting and stopping of the EdgeDriver
26+
"""
27+
28+
def __init__(self, executable_path, port=0):
29+
"""
30+
Creates a new instance of the Service
31+
32+
:Args:
33+
- executable_path : Path to the EdgeDriver
34+
- port : Port the service is running on
35+
"""x
36+
37+
self.path = executable_path
38+
39+
self.port = port
40+
if self.port == 0:
41+
self.port = utils.free_port()
42+
43+
def start(self):
44+
"""
45+
Starts the EdgeDriver Service.
46+
47+
:Exceptions:
48+
- WebDriverException : Raised either when it can't start the service
49+
or when it can't connect to the service
50+
"""
51+
try:
52+
cmd = [self.path, "--port=%d" % self.port]
53+
self.process = subprocess.Popen(cmd,
54+
stdout=PIPE, stderr=PIPE)
55+
except TypeError:
56+
raise
57+
except:
58+
raise WebDriverException(
59+
"The EdgeDriver executable needs to be available in the path. "
60+
"Please download from http://go.microsoft.com/fwlink/?LinkId=619687 ")
61+
count = 0
62+
while not utils.is_url_connectable(self.port):
63+
count += 1
64+
time.sleep(1)
65+
if count == 30:
66+
raise WebDriverException("Can not connect to the EdgeDriver")
67+
68+
def stop(self):
69+
"""
70+
Tells the EdgeDriver to stop and cleans up the process
71+
"""
72+
#If its dead dont worry
73+
if self.process is None:
74+
return
75+
76+
#Tell the Server to die!
77+
try:
78+
from urllib import request as url_request
79+
except ImportError:
80+
import urllib2 as url_request
81+
82+
url_request.urlopen("http://127.0.0.1:%d/shutdown" % self.port)
83+
count = 0
84+
while utils.is_connectable(self.port):
85+
if count == 30:
86+
break
87+
count += 1
88+
time.sleep(1)
89+
90+
#Tell the Server to properly die in case
91+
try:
92+
if self.process:
93+
self.process.stdout.close()
94+
self.process.stderr.close()
95+
self.process.kill()
96+
self.process.wait()
97+
except WindowsError:
98+
# kill may not be available under windows environment
99+
pass
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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 utils
19+
from selenium.webdriver.remote.webdriver import WebDriver as RemoteWebDriver
20+
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
21+
from .service import Service
22+
23+
24+
class WebDriver(RemoteWebDriver):
25+
26+
def __init__(self, executable_path='MicrosoftWebDriver.exe',
27+
capabilities=None, port=0):
28+
self.port = port
29+
if self.port == 0:
30+
self.port = utils.free_port()
31+
32+
self.edge_service = Service(executable_path, port=self.port)
33+
self.edge_service.start()
34+
35+
if capabilities is None:
36+
capabilities = DesiredCapabilities.EDGE
37+
38+
RemoteWebDriver.__init__(
39+
self,
40+
command_executor='http://localhost:%d' % self.port,
41+
desired_capabilities=capabilities)
42+
self._is_remote = False
43+
44+
def quit(self):
45+
RemoteWebDriver.quit(self)
46+
self.edge_service.stop()

rake-tasks/browsers.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,16 @@
3535
:browser_name => "internet explorer",
3636
:available => windows?
3737
},
38+
"edge" => {
39+
:python => {
40+
:ignore => "edge",
41+
:dir => "edge",
42+
:file_string => "edge",
43+
:class => "Edge"
44+
},
45+
:browser_name => "MicrosoftEdge",
46+
:available => windows?
47+
},
3848
"chrome" => {
3949
:python => {
4050
:ignore => "chrome",

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
'selenium.webdriver.support',
7373
'selenium.webdriver.firefox',
7474
'selenium.webdriver.ie',
75+
'selenium.webdriver.edge',
7576
'selenium.webdriver.opera',
7677
'selenium.webdriver.phantomjs',
7778
'selenium.webdriver.remote',

0 commit comments

Comments
 (0)