开发者

Clean way to programmatically control Safari on iPhone?

开发者 https://www.devze.com 2023-01-15 07:24 出处:网络
The title say\'s almost all. What I have is short lived server processes that serves a web-based javascript test suite with optionally accompanying back-ends for integration tests (see here for how it

The title say's almost all. What I have is short lived server processes that serves a web-based javascript test suite with optionally accompanying back-ends for integration tests (see here for how it's done). I'm looking for a better way to direct the iPhone Emulator's Safari to the URL given.

More, possibly optional background:

Up until iOS SDK 4.0 I've managed to control XCode using AppleScript to start a specially prepared PhoneGap project in this fashion:

  1. AppleScript (referred to as "AS") starts XCode (referred to as "XC")
  2. AS instructs XC to load the previously set up PhoneGap project.
  3. AS instructs XC to launch the 开发者_如何转开发PhonePap project.
  4. The PhoneGap project will redirect to the server serving the test suite, and the test suite runs.

In iOS 4.0 SDK, this only works the first round, the next time the test suite runner tries to make XC do the above routine, it fails requesting the previous run to be stopped. And I can't for the life of me find a way to stop the debugging session with AS [1], so I can only run one test suite without manual intervention, witch is pretty much a show stopper for us since we rely a lot on nightly test runs.

Now, what I really want to do is just start the iPhone Emulator, and then start Safari on the emulator with the possibility of sending an arbitrary URL to the emulated Safari.

What I've found so far is iphonesim, but I'm running into this issue and can't get it to properly start pre-compiled apps. A way to circumvent this issue in iphonesim would also be a good way forward.

[1] I'd accept a way to do this as a valid answer too.


I have a very different solution for you.

Write a custom iPhone app that just contains a web view. It will behave pretty much the same as MobileSafari. Then, embed a little web server in the app.

You can then control your app by calling specific urls on that server.

This is a very simple app. Will take you 30 minutes to put together.

This is easily integrated in Xcode or a bigger (Apple) script. You can use commands like curl to open URLs.


This is possible now:

xcrun simctl openurl booted "https://google.com"

https://apple.stackexchange.com/a/198798/144271


Post scriptum: how it was solved in the end.

A while after I asked this question, a user at github added a comment in issue 3 that what you need for iphonesim to work correctly is to give the absolute path to the application to start. So now we have a prebuilt PhoneGap project where a script modifies the contents of the www directory inside build/Debug-iphonesimulator/PhoneGap.app. The absolute path to this directory is then sent to iphonesim, starting up the project now pointing towards the correct server. No AppleScript and no XCode (except for the initial build). The test suite now takes 1/7 of the time it took to run earlier.

0

精彩评论

暂无评论...
验证码 换一张
取 消