Created
May 6, 2012 23:37
-
-
Save omaciel/2625008 to your computer and use it in GitHub Desktop.
A Selenium WebDriver Singleton class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- encoding: utf-8 -*- | |
# vim: ts=4 sw=4 expandtab ai | |
from robot.api import logger | |
from robot.utils import asserts | |
from selenium import webdriver | |
class Singleton(object): | |
instance = None | |
def __new__(cls, base_url, browser='firefox'): | |
if cls.instance is None: | |
i = object.__new__(cls) | |
cls.instance = i | |
cls.base_url = base_url | |
cls.browser = browser | |
if browser == "firefox": | |
# Create a new instance of the Firefox driver | |
cls.driver = webdriver.Firefox() | |
elif browser == "remote": | |
# Create a new instance of the Chrome driver | |
cls.driver = webdriver.Remote("http://localhost:4444/wd/hub", webdriver.DesiredCapabilities.HTMLUNITWITHJS) | |
else: | |
# Sorry, we can't help you right now. | |
asserts.fail("Support for Firefox or Remote only!") | |
else: | |
i = cls.instance | |
return i |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, could you please explain how does this work? I am trying to get selenium chrome driver in multiple modules but failed on almost every solution