2015-02-05 188 views
1

我遇到了MacOS 10.10和Safari 8.0的問題,其中Selenium驅動程序無法與SafariDriver建立連接。此線程的詳細信息:https://code.google.com/p/selenium/issues/detail?id=7933。要在本地運行測試,解決方法是下載Selenium 2.44.0,解壓縮軟件包,然後雙擊SafariDriver.safariextz進行安裝。但是通過SSH連接,這不起作用。我想在每次測試運行之前從命令行安裝SafariDriver.safariextz。有關如何從命令行安裝.safariextz文件的任何線索?從命令行安裝.safariextz

更新:剛剛證實,每次從SSH連接啓動Safari(/Applications/Safari.app/Contents/MacOS/Safari)時,所有擴展都會被刪除(Safari-> Preferences-> Extensions爲空)。

+0

還沒有找到解決方案。通過SSH啓動Safari後,擴展消失。想法? – 2015-02-12 18:03:55

回答

1

如果你是在同一臺機器上,AppleScript的應工作:

# this first part might not be needed 
osascript -e 'tell application "Safari" 
    activate 
end tell' 

osascript -e 'ignoring application responses 
    tell application "Safari" 
    open "'"/path/to/SafariDriver.safariextz"'" 
    end tell 
end ignoring 
tell application "System Events" 
    tell process "Safari" 
    set frontmost to true 
     repeat until (exists window 1) and subrole of window 1 is "AXDialog" -- wait until the dialog is displayed. 
     delay 1 
     end repeat 
    click button 1 of front window -- install 
    end tell 
end tell' 

如果失敗,那麼你可能通過打開系統偏好設置>安全&隱私>隱私啓用輔助設備和應用程序的訪問> Accessibility並檢查你想允許訪問的應用程序(Safari等等)。

更多信息:https://support.apple.com/en-us/HT202866

雅各布Salmela也創造了一個實用程序的命令行做到這一點:

http://jacobsalmela.com/os-x-yosemite-enable-access-assistive-devices-command-line/

0

以下的解決方法也招對我來說: 升級後Safari擴展是鑰匙串的一部分,並且通過SSH,用戶無權訪問登錄鑰匙串。解決方案是授予每個ssh會話的訪問權限。

security -v unlock-keychain -p <password> ~/Library/Keychains/login.keychain 

然後用以下步驟打開Safari瀏覽器應該工作 /Applications/Safari.app/Contents/MacOS/Safari

對於「常任」的解決方案添加一個構建步驟,如下執行shell腳本:

#!/bin/bash 
keychain="~/Library/Keychains/login.keychain" 
security unlock-keychain -p <password> ${keychain} &>/dev/null 

if [ $? -ne 0 ];then 
    echo "Cannot open keychain ${keychain}" 
    exit 1 
fi 

如此處所述http://sap-production.github.io/xcode-maven-plugin/site/howto/HandlingKeychainsInMasterSlaveEnvironment.html