3

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.

mperkh
  • 31
  • 2

1 Answers1

1

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.
Shi Ling
  • 146
  • 8
  • Thanks for the reply. I tried all combinations of custom capabilities, including `safari:deviceUDID`, `safari:deviceName` or `safari:deviceType` mentioned in safaridriver's man page. Unfortunately it didn't have any influence on the issue. Does a DELETE request also close mobileSafari on the iPad? It is strange that on iPhones mobileSafari stays open, while on iPads it gets closed. – mperkh Jun 01 '20 at 12:18
  • Where do you watch STP's error mesages? Konsole app, searching for `webdriver`? – mperkh Jun 01 '20 at 12:19
  • Bummer! Guess we'll have to wait for updates from the safaridriver team. I forgot to mention, I'm using an iPad Pro on the latest iOS version - perhaps that's a factor? Yes a `DELETE /session` request closes the mobile safari test automation session on the iPad (I see the orange browser closing and the iPad navigating to home or the last opened app). In my experience, it also closes the mobile safari test session on iPhone too. On the error messages, I'm referring to the error returned in the response from the safaridriver. I'm just using PostMan to do to the http requests by hand. – Shi Ling Jun 02 '20 at 01:01