Skip to content

Commit

Permalink
Merge branch 'remote' of github.com:cobrateam/splinter
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewsmedina committed Mar 19, 2012
2 parents d53df3e + 0b4a278 commit 8d11778
Show file tree
Hide file tree
Showing 3 changed files with 150 additions and 0 deletions.
2 changes: 2 additions & 0 deletions splinter/browser.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
# -*- coding: utf-8 -*-
from splinter.driver.webdriver.firefox import WebDriver as FirefoxWebDriver
from splinter.driver.webdriver.remote import WebDriver as RemoteWebDriver
from splinter.driver.webdriver.chrome import WebDriver as ChromeWebDriver
from splinter.exceptions import DriverNotFoundError
from splinter.utils import deprecate_driver_class


_DRIVERS = {
'firefox': FirefoxWebDriver,
'remote': RemoteWebDriver,
'chrome': ChromeWebDriver,
'webdriver.chrome': deprecate_driver_class(ChromeWebDriver, message="'webdriver.chrome' is deprecated, use just 'chrome'"),
'webdriver.firefox': deprecate_driver_class(FirefoxWebDriver, message="'webdriver.firefox' is deprecated, use just 'firefox'"),
Expand Down
60 changes: 60 additions & 0 deletions splinter/driver/webdriver/remote.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import subprocess

from selenium.webdriver import Remote
from splinter.driver.webdriver import BaseWebDriver, WebDriverElement as BaseWebDriverElement
from splinter.cookie_manager import CookieManagerAPI


class WebDriver(BaseWebDriver):

def __init__(self, server='localhost', port=4444):
self.old_popen = subprocess.Popen

self._patch_subprocess()
dest = 'http://%s:%s/wd/hub' % (server, port)
self.driver = Remote(dest, {})
self._unpatch_subprocess()

self.element_class = WebDriverElement

self._cookie_manager = CookieManagerAPI()

super(WebDriver, self).__init__()


class WebDriverElement(BaseWebDriverElement):

def mouse_over(self):
"""
Remote Firefox doesn't support mouseover.
"""
raise NotImplementedError("Remote Firefox doesn't support mouse over")

def mouse_out(self):
"""
Remote Firefox doesn't support mouseout.
"""
raise NotImplementedError("Remote Firefox doesn't support mouseout")

def double_click(self):
"""
Remote Firefox doesn't support doubleclick.
"""
raise NotImplementedError("Remote Firefox doesn't support doubleclick")

def right_click(self):
"""
Remote Firefox doesn't support right click'
"""
raise NotImplementedError("Remote Firefox doesn't support right click")

def drag_and_drop(self, droppable):
"""
Remote Firefox doesn't support drag and drop
"""
raise NotImplementedError("Remote Firefox doesn't support drag an drop")

mouseover = mouse_over
mouseout = mouse_out
88 changes: 88 additions & 0 deletions tests/test_webdriver_remote.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# -*- coding: utf-8 -*-

try:
import unittest2 as unittest
except ImportError:
import unittest

from splinter import Browser
from fake_webapp import EXAMPLE_APP
from base import WebDriverTests

import sys


@unittest.skipUnless('-remote' in sys.argv, 'Skipping the remote webdriver tests')
class RemoteBrowserTest(WebDriverTests, unittest.TestCase):

@classmethod
def setUpClass(cls):
cls.browser = Browser("remote")

@classmethod
def tearDownClass(cls):
cls.browser.quit()

def setUp(self):
self.browser.visit(EXAMPLE_APP)

def test_mouse_over(self):
"Remote should not support mouseover"
with self.assertRaises(NotImplementedError):
self.browser.find_by_id('visible').first.mouse_over()

def test_mouse_out(self):
"Remote should not support mouseout"
with self.assertRaises(NotImplementedError):
self.browser.find_by_id('visible').first.mouse_out()

def test_double_click(self):
"Remote should not support double_click"
with self.assertRaises(NotImplementedError):
self.browser.find_by_id('visible').double_click()

def test_right_click(self):
"Remote should not support right_click"
with self.assertRaises(NotImplementedError):
self.browser.find_by_id('visible').right_click()

def test_drag_and_drop(self):
"Remote should not support drag_and_drop"
with self.assertRaises(NotImplementedError):
droppable = self.browser.find_by_css('.droppable')
self.browser.find_by_css('.draggable').drag_and_drop(droppable)

def test_mouseover_should_be_an_alias_to_mouse_over_and_be_deprecated(self):
"Remote should not support mouseover"
with self.assertRaises(NotImplementedError):
self.browser.find_by_id('visible').mouseover()

def test_mouseout_should_be_an_alias_to_mouse_out_and_be_deprecated(self):
"Remote should not support mouseout"
with self.assertRaises(NotImplementedError):
self.browser.find_by_id('visible').mouseout()

def test_create_and_access_a_cookie(self):
"Remote should not support cookies"
with self.assertRaises(NotImplementedError):
self.browser.cookies.add({'sha': 'zam'})

def test_create_some_cookies_and_delete_them_all(self):
"Remote should not support cookies"
with self.assertRaises(NotImplementedError):
self.browser.cookies.delete()

def test_create_and_delete_a_cookie(self):
"Remote should not support cookies"
with self.assertRaises(NotImplementedError):
self.browser.cookies.delete('cookie')

def test_create_and_delete_many_cookies(self):
"Remote should not support cookies"
with self.assertRaises(NotImplementedError):
self.browser.cookies.delete('cookie', 'notacookie')

def test_try_to_destroy_an_absent_cookie_and_nothing_happens(self):
"Remote should not support cookies"
with self.assertRaises(NotImplementedError):
self.browser.cookies.delete('mwahahahaha')

0 comments on commit 8d11778

Please sign in to comment.