Skip to content

Commit

Permalink
SimonStewart and DavidBurns: Landing the new python bindings. Thanks …
Browse files Browse the repository at this point in the history
…to AnthonyLong for his help. There are known issues with theese bindings at present. They will be addressed very shortly

r10480
  • Loading branch information
shs96c committed Dec 1, 2010
1 parent 073a9f5 commit 41aaff3
Show file tree
Hide file tree
Showing 247 changed files with 590 additions and 54,927 deletions.
25 changes: 12 additions & 13 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
prune *
recursive-include common/src/web *.dll *.js *.gif *.html *.cs *.xhtml
recursive-include common/src/web *.txt *.Config
recursive-include common/src/py *.py
recursive-include common/test/py *.py
recursive-include chrome/src/py *.py
recursive-include chrome/src/py *.zip
recursive-include chrome/test/py *.py
recursive-include firefox/src/py *.py *.xpi
recursive-include firefox/test/py *.py
recursive-include jobbie/src/py *.py *.dll
recursive-include jobbie/test/py *.py
recursive-include remote/client/src/py *.py
recursive-include remote/client/test/py *.py
include selenium/src/py/selenium.py
include selenium/src/py/__init__.py
recursive-include py/selenium/webdriver/common *.py
recursive-include py/test/selenium/webdriver/common *.py
recursive-include py/selenium/webdriver/chrome *.py *.zip
recursive-include py/test/selenium/webdiver/chrome *.py
recursive-include py/selenium/webdriver/firefox *.py *.xpi
recursive-include py/test/selenium/webdriver/firefox *.py
recursive-include py/selenium/webdriver/ie *.py *.dll
recursive-include py/test/selenium/webdriver/ie *.py
recursive-include py/selenium/webdriver/remote *.py
recursive-include py/test/selenium/webdriver/remote *.py
include py/selenium/selenium.py
include py/selenium/__init__.py
include __init__.py
include docs/api/py/index.rst
recursive-include selenium.egg-info *
Expand Down
108 changes: 72 additions & 36 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -320,9 +320,16 @@ task :javadocs => [:common, :firefox, "//htmlunit", :jobbie, :remote, :support,
end

# Installs the webdriver python bindings using virtualenv for testing.
task :webdriver_py => [:chrome, :firefox, "//firefox:webdriver", :remote_client] do
task :webdriver_py do
if python? then
sh "virtualenv build/python", :verbose => true do |ok, res|
virtualenv = "virtualenv build/python"
pip_install = 'build/python/bin/' + "pip install simplejson py pytest"
if (windows?) then
virtualenv = "virtualenv build\\python"
pip_install = "build\\python\\Scripts\\" + "pip install simplejson py pytest"
end

sh virtualenv, :verbose => true do |ok, res|
if ! ok
puts ""
puts "PYTHON DEPENDENCY ERROR: Virtualenv not found."
Expand All @@ -331,61 +338,89 @@ task :webdriver_py => [:chrome, :firefox, "//firefox:webdriver", :remote_client]
end
end

sh "build/python/bin/pip install simplejson py", :verbose => true

# Copy browser extensions over to src so setup.py will pick them up. This is such a hack.
cp 'build/chrome/chrome-extension.zip', "chrome/src/py/", :verbose => true
cp 'build/firefox/webdriver.xpi', "firefox/src/py/", :verbose => true

sh "build/python/bin/python setup.py build", :verbose => true
sh pip_install, :verbose => true
end
end

# Remove the extensions we copied to src.
rm "chrome/src/py/chrome-extension.zip", :verbose => true
rm "firefox/src/py/webdriver.xpi", :verbose => true
task :test_ie_py => :webdriver_py do
win = windows?
if win != nil then
if python? then
cp 'jobbie\\prebuilt\\Win32\\Release\\InternetExplorerDriver.dll', "py\\selenium\\webdriver\\ie", :verbose => true
sh "build\\python\\Scripts\\python setup.py build", :verbose => true

if File.exists?('build\\python\\Scripts\\py.test.exe')
py_test = 'build\\python\\Scripts\\py.test.exe'
else
py_test = 'py.test.exe'
end

test_dir = Dir.glob('build/lib**/selenium/test/selenium/webdriver/ie').first
sh py_test, test_dir, :verbose => true
rm "py\\selenium\\webdriver\\ie\\InternetExplorerDriver.dll"
end
end
end

task :test_chrome_py => :webdriver_py do
task :test_chrome_py => [:webdriver_py, :chrome] do
if python? then
sh "virtualenv build/python", :verbose => true do |ok, res|
if ! ok
puts ""
puts "PYTHON DEPENDENCY ERROR: Virtualenv not found."
puts "Please run '[sudo] pip install virtualenv'"
puts ""
end
chrome_zip_build = 'build/chrome/chrome-extension.zip'
chrome_py_home = "py/selenium/webdriver/chrome/"
py_test_path = 'build/python/bin/py.test'
py_setup = "build/python/bin/python " + 'setup.py build'
if (windows?) then
chrome_zip_build = chrome_zip_build.gsub(/\//, "\\")
chrome_py_home = chrome_py_home.gsub(/\//, "\\")
py_test_path = 'build\\python\\Scripts\\py.test.exe'
py_setup = 'build\\python\\Scripts\\python ' + 'setup.py build'
end
if File.exists?('build/python/bin/py.test')
py_test = 'build/python/bin/py.test'
cp chrome_zip_build , chrome_py_home , :verbose => true

sh py_setup , :verbose => true

if File.exists?(py_test_path)
py_test = py_test_path
else
py_test = 'py.test'
end
test_dir = Dir.glob('build/lib**/selenium/chrome_tests').first
test_dir = Dir.glob('build/lib**/selenium/test/selenium/webdriver/chrome').first
sh py_test, test_dir, :verbose => true
chrome_zip = chrome_py_home + "chrome-extension.zip"
rm chrome_zip , :verbose => true
end
end

task :test_firefox_py => :webdriver_py do
task :test_firefox_py => [:webdriver_py, :firefox, "//firefox:webdriver"] do
if python? then
sh "virtualenv build/python", :verbose => true do |ok, res|
if ! ok
puts ""
puts "PYTHON DEPENDENCY ERROR: Virtualenv not found."
puts "Please run '[sudo] pip install virtualenv'"
puts ""
end
xpi_zip_build = 'build/firefox/webdriver.xpi'
firefox_py_home = "py/selenium/webdriver/firefox/"
py_test_path = 'build/python/bin/py.test'
py_setup = "build/python/bin/python " + 'setup.py build'
if (windows?) then
xpi_zip_build = xpi_zip_build.gsub(/\//, "\\")
firefox_py_home = firefox_py_home .gsub(/\//, "\\")
py_test_path = 'build\\python\\Scripts\\py.test.exe'
py_setup = 'build\\python\\Scripts\\python ' + 'setup.py build'
end
if File.exists?('build/python/bin/py.test')
py_test = 'build/python/bin/py.test'

cp xpi_zip_build , firefox_py_home, :verbose => true

sh py_setup , :verbose => true


if File.exists?(py_test_path)
py_test = py_test_path
else
py_test = 'py.test'
end
test_dir = Dir.glob('build/lib**/selenium/firefox_tests').first
test_dir = Dir.glob('build/lib**/selenium/test/selenium/webdriver/firefox').first
sh py_test, test_dir, :verbose => true
webdriver_zip = firefox_py_home + 'webdriver.xpi'
rm webdriver_zip , :verbose => true
end
end

task :test_remote_py => [:webdriver_py, :'selenium-server-standalone'] do
task :test_remote_py => [:webdriver_py, :remote_client, :'selenium-server-standalone'] do
if python? then
sh "virtualenv build/python", :verbose => true do |ok, res|
if ! ok
Expand All @@ -400,7 +435,7 @@ task :test_remote_py => [:webdriver_py, :'selenium-server-standalone'] do
else
py_test = 'py.test'
end
test_dir = Dir.glob('build/lib**/selenium/remote_tests').first
test_dir = Dir.glob('build/lib**/selenium/test/selenium/webdriver/remote').first
sh py_test, test_dir, :verbose => true
end
end
Expand Down Expand Up @@ -539,3 +574,4 @@ desc 'Build and package Selenium IDE'
task :release_ide => [:ide] do
cp 'build/ide/selenium-ide.xpi', "build/ide/selenium-ide-#{ide_version}.xpi"
end

23 changes: 0 additions & 23 deletions jobbie/test/py/api_examples.py

This file was deleted.

4 changes: 2 additions & 2 deletions selenium/src/py/__init__.py → py/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Copyright 2008-2009 WebDriver committers
# Copyright 2008-2009 Google Inc.
# Copyright 2010 WebDriver committers
# Copyright 2010 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down
14 changes: 14 additions & 0 deletions py/selenium/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copyright 2008-2010 WebDriver committers
# Copyright 2008-2010 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
File renamed without changes.
47 changes: 47 additions & 0 deletions py/selenium/webdriver/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/usr/bin/python
#
# Copyright 2008-2010 Webdriver_name committers
# Copyright 2008-2010 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


def connect(driver_name, server_address='http://127.0.0.1:4444', browser_name='', version='', platform='ANY', javascript_enabled=True):
"""Usage:
driver_name: use 'firefox', 'ie', 'chrome' or 'remote'.
server_address: only needed if you are using 'remote'. Do not add /wd/hub/ we will do that for you.
browser_name: only needed if you are using 'remote'. Use the browser you want to test on,
or leave blank and we will pick any available browser on the machine.
version: choose a browser version, or leave blank and we will pick any available version.
platform, choose a platform or leave default of 'ANY'
javascript_enabled: True or False. Default is True.
"""
driver_name = driver_name.strip('*').lower()
path = '/wd/hub'
if driver_name.lower() == 'firefox':
from firefox.webdriver import WebDriver as firefox_driver
return firefox_driver()
if driver_name.lower() == 'ie':
from ie.webdriver import WebDriver as ie_driver
return ie_driver()
if driver_name.lower() == 'chrome':
from chrome.webdriver import WebDriver as chrome_driver
return chrome_driver()
if driver_name.lower() == 'remote':
if not path.startswith("/"):
path = "/" + path
if not server_address.startswith("http://"):
server_address = "http://" + server_address
from remote import webdriver as remote_driver
wd = remote_driver.connect(driver_name, server_address, path, browser_name, version, platform, javascript_enabled)
return wd
File renamed without changes.
36 changes: 15 additions & 21 deletions chrome/src/py/driver.py → py/selenium/webdriver/chrome/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
# limitations under the License.

from __future__ import with_statement

from selenium.common.exceptions import RemoteDriverServerException
from selenium.remote import utils
import os
from selenium.webdriver.common.exceptions import RemoteDriverServerException
from selenium.webdriver.remote import utils
from subprocess import Popen
import httplib
from BaseHTTPServer import HTTPServer
Expand All @@ -27,16 +27,13 @@
import json
except ImportError:
import simplejson as json

if not hasattr(json, 'dumps'):
import simplejson as json

from time import sleep, time
from urllib import urlopen
from os.path import expanduser, join, dirname, abspath, isdir, isfile, exists
from os.path import expanduser, join, dirname, abspath, isdir, exists
from sys import platform
from tempfile import mkdtemp
from shutil import copytree, rmtree, copy
import shutil
#from shutil import shutil.copytree, shutil.rmtree, copy
from os import environ

INITIAL_HTML = '''
Expand All @@ -58,7 +55,6 @@
class RequestHandler(SimpleHTTPRequestHandler):
def do_GET(self):
self.respond(INITIAL_HTML, "text/html")

# From my (Miki Tebeka) understanding, the driver works by sending a POST http
# request to the server, the server replies with the command to execute and the
# next POST reply will have the result. So we hold a command and result
Expand Down Expand Up @@ -181,17 +177,13 @@ def create_extension_dir():
if not isdir(extdir):
extdir = join(dirname(dirname(abspath(__file__))), "extension")
assert isdir(extdir), "can't find extension"

# copytree need to create the directory
rmtree(path)
copytree(extdir, path)

# shutil.copytree need to create the directory
shutil.rmtree(path)
shutil.copytree(extdir, path)
return path

def create_profile_dir():
path = mkdtemp()
touch(join(path, "First Run"))
touch(join(path, "First Run Dev"))
return path

# FIXME: Find a free one dinamically
Expand Down Expand Up @@ -266,12 +258,14 @@ def stop(self):
self._server = None

for path in (self._profile_dir, self._extension_dir):
print path
if not path:
continue
try:
rmtree(path)
except IOError:
pass
for i in xrange(5):
if os.path.exists(path):
shutil.rmtree(path)
if os.path.exists(path):
return "Couldn't delete profile. Please try manually."

def execute(self, command, params):
to_send = params.copy()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,13 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import with_statement

from __future__ import with_statement

__all__ = [ "WebDriver" ]

from selenium.remote.command import Command
from selenium.remote.webdriver import WebDriver as RemoteWebDriver
__all__ = ["WebDriver"]
from selenium.webdriver.remote.command import Command
from selenium.webdriver.remote.webdriver import WebDriver as RemoteWebDriver
from driver import ChromeDriver

class WebDriver(RemoteWebDriver):

class WebDriver(RemoteWebDriver):
def __init__(self):
RemoteWebDriver.__init__(self,
command_executor=ChromeDriver(),
Expand All @@ -45,8 +41,9 @@ def save_screenshot(self, jpeg_file):
with open(jpeg_file, "w") as fo:
fo.write(image.decode("base64"))


def _test():
wd = WebDriver()
wd = RemoteWebDriver.connect('*chrome')
wd.get("http://www.google.com")
print "Current URL: %s" % wd.get_current_url()
print "2 + 2 = %s" % wd.execute_script("return 2 + 2;")
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 41aaff3

Please sign in to comment.