0

We created extensions for Chrome, Firefox and Safari and we want to test our extensions with Selenium. I already created tests for Chrome and Firefox with our extension, and now I want to test our Safari extension. I found this answer about Safari but I didn't find out how to do it in Python, I checked and Selenium 2.45.0 (which we are using) doesn't have SafariOptions defined, and I didn't find out how I add an extension to the Safari tests. We use remote testing with Safari and I ran a test with Safari without our extension which passed, but I didn't find out how I create tests with our Safari extension in Python. Here are the relevant functions:

def get_chrome_options(self, file_name):
    chrome_options = ChromeOptions()
    chrome_options.add_extension(extension=file_name)
    return chrome_options

def get_firefox_profile(self, file_name):
    firefox_profile = webdriver.FirefoxProfile()
    firefox_profile.add_extension(extension=file_name)
    return firefox_profile

def start_selenium_webdriver(self, caps, chrome_options=None, firefox_profile=None):
    print("Starting test \"{}\" with {} {}, resolution {}.".format(caps['name'], caps['browser'], caps['browser_version'], caps['resolution']))
    if (self.browser == "chrome"):
        self.driver = webdriver.Chrome(chrome_options=chrome_options)
    elif (self.browser == "firefox"):
        self.driver = webdriver.Firefox(firefox_profile=firefox_profile)
    else:
        self.driver = webdriver.Remote(
            command_executor='http://username:password@hub.browserstack.com:80/wd/hub',
            desired_capabilities=caps
        )
    self.driver.implicitly_wait(time_to_wait=5)
    self.driver.set_window_size(1920, 1080)
    size = self.driver.get_window_size()
    print("Window size: width = {}px, height = {}px.".format(size["width"], size["height"]))

I'll appreciate it if you provide answers both for local and remote testing. We want to test our extensions with Safari 7 and 8.

Community
  • 1
  • 1
Uri
  • 2,992
  • 8
  • 43
  • 86
  • 1
    Unless someone has implemented these APIs for the Python bindings, there is no way to add the extension via Selenium in Python. – Rob W Apr 13 '15 at 13:44
  • Thank you @RobW. Did they merge your code into Selenium in Java? Your answer says they didn't accept it but it says on github "Merged in 2a453fa" in 2013. – Uri Apr 13 '15 at 13:48
  • 1
    Actually they did. I have edited my answer and removed the build instructions. – Rob W Apr 13 '15 at 13:59
  • @RobW Thank you. We use the same code in Python for all our Selenium tests so we prefer to keep using Python. – Uri Apr 13 '15 at 14:04
  • 1
    You could be the one writing the Python bindings for Selenium, wink ;) – Rob W Apr 13 '15 at 14:07
  • I'll see what I can do @RobW, I looked at your commit on github and it looks a bit complicated to convert it to Python. – Uri Apr 13 '15 at 14:12

2 Answers2

1

It is impossible. Automatic installation of extensions was removed in 2.45 due to security updates of safari browser.

Kimo
  • 185
  • 1
  • 1
  • 11
  • Thanks Kimo, but I prefer to leave this question open because it might be possible in the future. I already noticed it from Rob's comments and updated answer. – Uri Apr 16 '15 at 07:30
1

There is no driver for Safari extension but I imagine you can always exec the command from python "open ".

This will bring up the safari install dialog which you can answer using accessibility APIs on the Mac.

Good luck. I hope it helps.

dimitrirostavo
  • 318
  • 1
  • 13