wda-driver
Facebook WebDriverAgent Node Client Library (not official)
This project is a transplant of this project https://github.com/openatx/facebook-wda
Most functions finished.
Installation
- You need to start WebDriverAgent by yourself
Follow the instructions in https://github.com/facebook/WebDriverAgent
It is better to start with Xcode to prevent CodeSign issues.
But it is also ok to start WDA with command line.
xcodebuild -project WebDriverAgent.xcodeproj -scheme WebDriverAgentRunner -destination 'platform=iOS Simulator,name=iPhone 6' test
- Install wda-driver client
npm install --save wda-driver
TCP connection over USB (optional)
You can use wifi network, it is very convinient, but not very stable enough.
I found a tools named iproxy
which can forward device port to localhost, it's source code is here https://github.com/libimobiledevice/libusbmuxd
The usage is very simple iproxy <local port> <remote port> [udid]
Configuration
const wda =
How to use
Create a client
const wda = const c = 'http://localhost:8100' // http://localhost:8100 is the default value if $DEVICE_URL is emptyc = wda
Client
// Show statusconsole // Press home buttonawait c // Hit healthcheckawait c // Get page source // format (str): only 'xml' and 'json' source types are supported// accessible (bool): when set to true, format is always 'json'const source = await csource // format XMLconst source = await csourcenull true // default false, format JSON
Take screenshot, only can save format png
await c
Open app
const s = await cconsoleawait s
For web browser like Safari you can define page whit which will be opened:
const s = await cconsoleawait s
Session operations
// Current bundleId and sessionIdconsole // One of <PORTRAIT | LANDSCAPE>console // expect PORTRAIT // Change orientation// LANDSCAPE | PORTRAIT | UIA_DEVICE_ORIENTATION_LANDSCAPERIGHT |UIA_DEVICE_ORIENTATION_PORTRAIT_UPSIDEDOWNawait s // Deactivate App for some timeawait s // 5s // Get width and heightconsole// Expect json output// For example: {'height': 736, 'width': 414} // Simulate touchawait s // Double touchawait s // Simulate swipe, utilizing drag apiawait s // 0.5sawait sawait sawait sawait s // tap holdawait s
Find element
Note: if element not found, will throw error
// For example, expect: true or false// using id to find element and check if existsconst selector = sawait selector // return true or false // using id or other query conditionssss // text is alias of namessss # find the second element index starts from 0 // combines search conditions// attributes bellow can combines// :"className", "name", "label", "visible", "enabled" s
More powerful findding method
sss
tap
, scroll
, set_text
etc...)
Element operations (eg: Exmaple search element and tap
// Get first match Element object// The function get() is very important.it will return an Element object// when elements founded in 10 seconds(:default:), Element object returns const e = await s // e is elements objectawait e // tap element
Click element if exists
await s // return immediately if not found await s // wait for 5s
Other Element operations
// Check if elements existsconsole // Find all matches elements, return Array of Element objectawait s // Use index to find second elementawait s // Use child to search sub elementsawait s // Default timeout is 10 seconds// But you can change bys // do element operationsawait eawait e // alias of tap// The default keyboard must be requestedawait eawait eawait e // tapAndHold for 2.0s await e // scroll to make element visiable // directions can be "up", "down", "left", "right"// swipe distance default to its height or width according to the directionawait e // Set textawait e // normal usageawait e // send text with enterawait e // delete 3 chars // Wait element goneawait // Swipe TODO// s(className="Image").swipe("left") // Pinch // scale=2, speed=1 // scale=0.1, speed=-1 (I donot very understand too) // properties (bool)await eawait eawait eawait eawait e // properties (str)await e await eawait eawait eawait eawait eawait eawait eawait e // Bounds return namedtupleconst rect = await e // Rect { x: 0, y: 73, width: 375, height: 666 }recty // 73
Alert
consoleconsoleconsole await saccept // Actually do click first alert buttonawait s // Actually do click second alert buttonawait s // if alert apper in 5 second it will return true,else return false (default 20.0)await s // wait alert apper in 20 second await s// example return: ["设置", "好"] await s
iOS Build-in Apps
苹果自带应用
Name | Bundle ID |
---|---|
iMovie | com.apple.iMovie |
Apple Store | com.apple.AppStore |
Weather | com.apple.weather |
相机Camera | com.apple.camera |
iBooks | com.apple.iBooks |
Health | com.apple.Health |
Settings | com.apple.Preferences |
Watch | com.apple.Bridge |
Maps | com.apple.Maps |
Game Center | com.apple.gamecenter |
Wallet | com.apple.Passbook |
电话 | com.apple.mobilephone |
备忘录 | com.apple.mobilenotes |
指南针 | com.apple.compass |
浏览器 | com.apple.mobilesafari |
日历 | com.apple.mobilecal |
信息 | com.apple.MobileSMS |
时钟 | com.apple.mobiletimer |
照片 | com.apple.mobileslideshow |
提醒事项 | com.apple.reminders |
Desktop | com.apple.springboard (Start this will cause your iPhone reboot) |
第三方应用 Thirdparty
Name | Bundle ID |
---|---|
腾讯QQ | com.tencent.mqq |
微信 | com.tencent.xin |
部落冲突 | com.supercell.magic |
钉钉 | com.laiwang.DingTalk |
Skype | com.skype.tomskype |
Chrome | com.google.chrome.ios |
Another way to list apps installed on you phone is use ideviceinstaller
install with brew install ideviceinstaller
List apps with command
$ ideviceinstaller -l
Reference
Source code