Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS 13 safaridriver can not create safari session

tl;dr: safaridriver very often not able to connect to mobileSafari on real iOS 13 device. mobileSafari seems to be in kind of suspended mode after webdriver connection has been closed. Only solution, to make further connects, is manually killing mobileSafari via iOS app switcher.

edit: The issue can be reproduced only on iPads. The problem does not seem to exist on iPhones.


I am trying to run selenium tests, directly on an iOS device, using the the new iOS 13 webdriver possibilities. It seems to work as described in https://webkit.org/blog/9395/webdriver-is-coming-to-safari-in-ios-13/ but when trying to run a 2nd test session, safaridriver doesnt seem to be able to connect do mobileSafari on the device. This seems to happen, if the 2nd session is not immediately started after the 1st one - mobileSafari seems to be suspended and safaridriver can not handle this situation.

Use Postman, connecting to a running safaridriver -p 5500 server. Make a localhost:5500/session request with raw body:

{
    "capabilities": {
        "alwaysMatch": {
            "browserName": "Safari",
            "platformName": "iOS"
        }
    }
}

After several retries this will result in:

{
    "value": {
        "error": "session not created",
        "message": "Could not create a session: The session timed out while connecting to a Safari instance.",
        "stacktrace": ""
    }
}

It is not possible to get around this issue. Only solution is to manually kill mobileSafari via App Switcher.

Perhaps anyone has an idea, how this could be fixed. Would be thankful, since this is a real showstopper for running continuous automatic running tests.

like image 803
mperkh Avatar asked Dec 08 '25 08:12

mperkh


1 Answers

I had the exact same problem when trying to start a session on a real iPad device.

After digging into the safaridriver manual with man safaridriver, I found out that setting safari:deviceType in the capabilities exists, so I tried it and it works:

POST /session

{
    "capabilities": {
        "firstMatch": [
            {
                "safari:deviceType": "iPad", // <- add this
                "platformName": "ios",
                "browserName": "Safari"
            }
        ]
    }
}

Additional footnotes:

  • I used firstMatch, but alwaysMatch is expected to work too.
  • safaridriver will evaluate the values without case sensitivity
  • Tested with Safari 13.1's safaridriver and Safari Technology Preview 107's safaridriver. Works on both, though STP's error messages are more helpful.
  • Also, you will need to switch on "Safari > Advanced > Web Inspector" on the iPad (this only appears after the iPad is connected to a MacOs machine) to start the session.
like image 113
Shi Ling Avatar answered Dec 10 '25 04:12

Shi Ling



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!