|
| 1 | +# Support iOS automation |
| 2 | + |
| 3 | +From Midscene v0.29, we are happy to announce the support for iOS automation. The era for AI-driven iOS automation is here! |
| 4 | + |
| 5 | +## Showcases |
| 6 | + |
| 7 | +### Auto-like tweets |
| 8 | + |
| 9 | +Open Twitter and auto-like the first tweet by [@midscene_ai](https://x.com/midscene_ai). |
| 10 | + |
| 11 | +<video src="https://lf3-static.bytednsdoc.com/obj/eden-cn/nupipfups/Midscene/ios-twitter.mp4" controls/> |
| 12 | + |
| 13 | +## Suitable for all apps |
| 14 | + |
| 15 | +For our developers, all you need is the WebDriver Server and a visual-language model (vl-model) service. Everything is ready! |
| 16 | + |
| 17 | +Behind the scenes, we utilize the visual grounding capabilities of vl-model to locate target elements on the screen. So, regardless of whether it's a native iOS app, a Safari web page, or a hybrid app with a WebView, it makes no difference. Developers can write automation scripts without the burden of worrying about the technology stack of the app. |
| 18 | + |
| 19 | +## With all the power of Midscene |
| 20 | + |
| 21 | +When using Midscene to do web automation, our users loves the tools like playgrounds and reports. Now, we bring the same power to iOS automation! |
| 22 | + |
| 23 | +### Use the playground to run automation without any code |
| 24 | + |
| 25 | +<video src="https://lf3-static.bytednsdoc.com/obj/eden-cn/nupipfups/Midscene/ios-playground-demo.mp4" controls/> |
| 26 | + |
| 27 | +### Use the report to replay the whole process |
| 28 | + |
| 29 | +<video src="https://lf3-static.bytednsdoc.com/obj/eden-cn/nupipfups/Midscene/ios-twitter.mp4" controls/> |
| 30 | + |
| 31 | +### Write the automation scripts by YAML file |
| 32 | + |
| 33 | +Open Safari on iOS device, search for content and extract information. |
| 34 | + |
| 35 | +```yaml |
| 36 | +# Open Safari browser on iOS device, search for content and extract information |
| 37 | + |
| 38 | +ios: |
| 39 | + deviceId: "iPhone" |
| 40 | + bundleId: "com.apple.mobilesafari" |
| 41 | + |
| 42 | +tasks: |
| 43 | + - name: search content |
| 44 | + flow: |
| 45 | + - aiAction: tap address bar |
| 46 | + - aiAction: input 'Midscene AI automation' |
| 47 | + - aiAction: tap search button |
| 48 | + - sleep: 3000 |
| 49 | + - aiAction: scroll down 500px |
| 50 | + |
| 51 | + - name: extract search results |
| 52 | + flow: |
| 53 | + - aiQuery: > |
| 54 | + {title: string, url: string, description: string}[], |
| 55 | + return search result titles, links and descriptions |
| 56 | + name: searchResults |
| 57 | +
|
| 58 | + - name: verify page elements |
| 59 | + flow: |
| 60 | + - aiAssert: there is a search results list on the page |
| 61 | +``` |
| 62 | +
|
| 63 | +### Use the JavaScript SDK |
| 64 | +
|
| 65 | +Use the javascript SDK to do the automation by code. |
| 66 | +
|
| 67 | +```ts |
| 68 | +import { IOSAgent, IOSDevice } from '@midscene/ios'; |
| 69 | +import "dotenv/config"; // read environment variables from .env file |
| 70 | + |
| 71 | +const sleep = (ms) => new Promise((r) => setTimeout(r, ms)); |
| 72 | +Promise.resolve( |
| 73 | + (async () => { |
| 74 | + // 👀 initialize iOS device |
| 75 | + const device = new IOSDevice({ |
| 76 | + deviceId: 'iPhone', |
| 77 | + bundleId: 'com.apple.mobilesafari' |
| 78 | + }); |
| 79 | + |
| 80 | + // 👀 initialize Midscene agent |
| 81 | + const agent = new IOSAgent(device, { |
| 82 | + aiActionContext: |
| 83 | + 'If any permission popup appears, tap allow. If login page pops up, skip it.', |
| 84 | + }); |
| 85 | + |
| 86 | + await device.connect(); |
| 87 | + await device.launchApp(); |
| 88 | + |
| 89 | + await sleep(3000); |
| 90 | + |
| 91 | + // 👀 tap address bar and input search keywords |
| 92 | + await agent.aiAction('tap address bar and input "Midscene automation"'); |
| 93 | + |
| 94 | + // 👀 perform search |
| 95 | + await agent.aiAction('tap search button'); |
| 96 | + |
| 97 | + // 👀 wait for loading to complete |
| 98 | + await agent.aiWaitFor("there is at least one search result on the page"); |
| 99 | + // or you may use a plain sleep: |
| 100 | + // await sleep(5000); |
| 101 | + |
| 102 | + // 👀 understand page content, find search results |
| 103 | + const results = await agent.aiQuery( |
| 104 | + "{title: string, url: string}[], find titles and links in search results list" |
| 105 | + ); |
| 106 | + console.log("search results", results); |
| 107 | + |
| 108 | + // 👀 assert by AI |
| 109 | + await agent.aiAssert("relevant search results are displayed on the page"); |
| 110 | + })() |
| 111 | +); |
| 112 | + |
| 113 | +``` |
| 114 | + |
| 115 | +### Two style APIs to do interaction |
| 116 | + |
| 117 | +The auto-planning style: |
| 118 | + |
| 119 | +```javascript |
| 120 | +await agent.ai('tap address bar and input "Midscene automation", then search'); |
| 121 | +``` |
| 122 | + |
| 123 | +The instant action style: |
| 124 | + |
| 125 | +```javascript |
| 126 | +await agent.aiTap('address bar'); |
| 127 | +await agent.aiInput('Midscene automation', 'address bar'); |
| 128 | +await agent.aiTap('search button'); |
| 129 | +``` |
| 130 | + |
| 131 | +## Quick start |
| 132 | + |
| 133 | +You can use the playground to experience the iOS automation without any code. Please refer to [Quick experience with iOS](./quick-experience-with-ios) for more details. |
| 134 | + |
| 135 | +After the experience, you can integrate with the iOS device by javascript code. Please refer to [Integrate with iOS(WebDriverAgent)](./integrate-with-ios) for more details. |
| 136 | + |
| 137 | +If you prefer the yaml file for automation scripts, please refer to [Automate with scripts in yaml](./automate-with-scripts-in-yaml). |
0 commit comments