How do I test a Safari extension with Selenium in Python?

巧了我就是萌 提交于 2020-01-07 00:31:51

问题


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.


回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/29606672/how-do-i-test-a-safari-extension-with-selenium-in-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!