如何在Python中使用Selenium测试Safari扩展?
我们为Chrome、Firefox和Safari创建了扩展,我们想用Selenium测试我们的扩展。我已经用我们的扩展为Chrome和Firefox创建了测试,现在我想测试我们的Safari扩展。我找到了Safari,但没有找到如何在Python中实现它,我检查了Selenium 2.45.0(我们正在使用的)没有定义Safario选项,也没有找到如何向Safari测试添加扩展。我们对Safari使用远程测试,我在没有通过扩展的情况下使用Safari运行了一个测试,但我没有发现如何使用Python中的Safari扩展创建测试。以下是相关功能:如何在Python中使用Selenium测试Safari扩展?,python,selenium,safari,safari-extension,Python,Selenium,Safari,Safari Extension,我们为Chrome、Firefox和Safari创建了扩展,我们想用Selenium测试我们的扩展。我已经用我们的扩展为Chrome和Firefox创建了测试,现在我想测试我们的Safari扩展。我找到了Safari,但没有找到如何在Python中实现它,我检查了Selenium 2.45.0(我们正在使用的)没有定义Safario选项,也没有找到如何向Safari测试添加扩展。我们对Safari使用远程测试,我在没有通过扩展的情况下使用Safari运行了一个测试,但我没有发现如何使用Pytho
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"]))
如果您能提供本地和远程测试的答案,我将不胜感激。我们想用Safari 7和8测试我们的扩展。这是不可能的。由于safari浏览器的安全更新,扩展的自动安装在2.45中被删除。safari扩展没有驱动程序,但我想您可以始终从python“open”中执行命令 这将打开safari安装对话框,您可以使用Mac上的辅助功能API来回答该对话框
祝你好运。我希望有帮助 除非有人为Python绑定实现了这些API,否则无法在Python中通过Selenium添加扩展。他们是否将您的代码合并到Java中的Selenium中?你的回答说他们不接受,但在2013年github上说“合并于2a453fa”。事实上他们接受了。我已经编辑了我的答案并删除了构建说明。@RobW谢谢。我们在所有Selenium测试中都使用相同的Python代码,因此我们更愿意继续使用Python谢谢Kimo,但我更愿意把这个问题留待讨论,因为将来可能会有。我已经从Rob的评论和更新的答案中注意到了这一点。