Unable to run tests against Safari 11 remotely (ssh, CI)

后端 未结 2 930
别跟我提以往
别跟我提以往 2021-01-07 00:52

I\'m having troubles running Ruby/RSpec tests against Safari 11 when I\'m trying to run tests via ssh manually or via Jenkins (where machine where Safari exists is remote sl

相关标签:
2条回答
  • 2021-01-07 01:22

    For my case:

    1. On OSX host side was created Automator app as described above and modified a little bit:
    security unlock-keychain -p your_host_password /Users/$USER/Library/Keychains/login.keychain-db
    safaridriver --enable
    safaridriver -p 7050
    
    1. On CCI/Jenkins side:
    open /Applications/StartSafariDriver7050.app/
    run pytest cmd
    osascript -e 'quit app "StartSafariDriver7050"'
    pkill safaridriver
    
    1. In Python:
    def safaridriver():
        return webdriver.Safari(desired_capabilities=Caps.SAFARI, port=7050)
    
    0 讨论(0)
  • 2021-01-07 01:34

    There is a possible workaround to do this. First you need to create a Automator Workflow or Apple Script that launches the SafariDriver

    Then save this as a application. Let assume we name it SafariDriver7050.

    Then from the SSH session you need to execute

    open /Applications/SafariDriver7050.app
    

    This will actually launch SafariDriver in the logged in session and it should work for you.

    The caveat being shutting it down, you will need to first kill the SafariDriver7050 app and then you need to kill the safaridriver process. The order matters, else it will create a error dialog on UI

    Edit-1:

    As you suggested, it would be even easier to do this, when you wrap your test as a app and then it will be automatically be able to launch SafariDriver without any issues. The key to issue is using open command in a SSH session

    Edit-2

    Why does SafariDriver not work in SSH? Well if you look at the linux counterpart

    In case of linux we can use the DISPLAY environment variable to launch an app in an existing display or we can use something like XVFB to launch the browser in a virtual display. That is the concept that most frameworks use in case of linux machines.

    But Mac doesn't have such kind of feature, which is why this workaround is needed. Now why it doesn't have that, I am not sure. There may be some other workaround that I may not be aware of, so anyone who has valuable info, can help improve this part of the answer

    0 讨论(0)
提交回复
热议问题