Macaca 極簡教程

macaca.jpg
Macaca 介紹

教程

image.png
原始碼空間: ofollow,noindex">https://github.com/macacajs
模組拆分講解:
Macaca
1. macaca-cli
Macaca提供的命令列工具
$macaca server
啟動server
$macaca server --verbose
啟動server並列印詳細日誌
$macaca doctor
檢驗當前macaca環境配置
2. app-inspector
macaca提供的元素查詢工具,可以將app檢視的結構以佈局結構樹的格式在瀏覽器上展示出來,用過點選某個元素,就可以方便的查詢到該控制元件的基本資訊,以方便查詢。具體使用可參考官網: https://macacajs.com/inspector
3. UI Recorder
macaca提供的指令碼錄製工具,可以通過錄制獲得指令碼,對於入門同學很有幫助。 https://macacajs.com/recorder
WebDriver-Server
Macaca是按照經典的Server-Client設計模式進行設計的,也就是我們常說的C/S架構。WebDriver-server部分便充當了server這部分的角色,他的職責就是等待client傳送請求並做出響應。
WebDriver-Client
client端簡單來講就是我們的測試程式碼,我們測試程式碼中的一些行為,比如控制元件查詢、點選等,這些行為以http請求的方式傳送給server,server接收請求,並執行相應操作,並在response中返回執行狀態、返回值等資訊。
也正是基於這種經典的C/S架構,所以client端具有跨語言的特點,macaca-wd,wd.java,wd.py分別是Macaca團隊針對Js Java 以及Python的封裝,只要能保證client端按照指定的要求傳送Http請求,任意語言都可以。
DriverList
自動化要在不同的平臺上跑,需要有對應平臺的驅動,這部分驅動接收到來自server的操作命令,驅動各自平臺的底層完成對應的操作。
1. Android
Macaca針對安卓平臺的驅動集合
- macaca-android 安卓驅動
- macaca-adb 封裝了安卓的adb命令,來實現一些adb的操作,比如安裝、解除安裝、啟動app、獲取裝置列表這些操作
- android-unicode 經過封裝後的輸入法,解決中文輸入的問題
- uiautomator-client 將來自server的操作指令轉換為UIAutomator可以識別的指令,驅動uiautomator完成對應的操作
- android-performance 用於自動化測試安卓效能相關的支援
2. iOS
Macaca針對iOS平臺的驅動集合
- macaca-ios iOS驅動
- xctest-client 同安卓的uiautomator-client異曲同工,對XCUITest的封裝,將來自server的操作指令轉換為XCUITest可以識別的指令,驅動XCUITest完成對應的操作
- ios-simulator 用於對ios模擬器的支援,可以通過模擬器執行用例
- remote-debug 用於遠端除錯
3. Hybrid
Macaca針對Hybrid的驅動集合。
- macaca-chrome web測試驅動
- macaca-chromedriver 驅動chrome瀏覽器
- ios-webkit-debug-proxy 適用於iOS平臺對webview的除錯
4. Electron
Macaca針對pc端網頁應用的支援
- macaca-electron
快速開始:從無到有搭建 Macaca 環境 (forMac)
https://macacajs.com/zh/quick-start
基礎環境準備
安裝Homebrew
簡易安裝步驟(最新可參考官網)
$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
安裝Node和npm
$ brew install node
安裝後可以用node -v檢視版本號,如果正常則說明安裝成功,Macaca2.0要求當前node版本要高於6.0,如果以前安裝過低版本的Node,可以通過如下命令更新Node版本:
$brew upgrade node
安裝cnpm
npm是node.js的包管理工具,可以用他來安裝和更新各種node的pacakage,可以理解為Java中Maven類似的作用,但是由於眾所周知的那堵牆,直接用npm安裝速度會非常慢,這種情況下可以安裝阿里巴巴提供的cnpm,cnpm提供了國內的映象,可以加快包的下載速度,安裝方法如下:
命令列工具輸入如下命令:
$npm install -g cnpm --registry=https://registry.npm.taobao.org
如果在安裝過程中提示 Permission 許可權相關錯誤,可以嘗試 USER /usr/local,永久破除 sudo 要求。
安裝成功後同樣可以通過cnpm -v來驗證安裝是否成功,安裝成功後,在原來使用npm的地方,直接替換成cnpm即可,
比如,原始命令為
$npm i -g macaca-cli
替換後為:
$cnpm i -g macaca-cli
Macaca相關安裝
iOS
如果不針對iOS作自動化,可以忽略此處
- 安裝XCode(依賴Mac電腦,AppStore下載即可)
- 安裝相關工具
$ brew install usbmuxd$ brew install ios-webkit-debug-proxy $ brew install carthage
Android
- 安裝JDK Macaca支援JDK7及以上,可到官網選擇對應版本安裝 官網下載 注意安裝後需要配置JAVA_HOME環境變數,如果本地命令列工具用的是mac系統的預設命令列工具,將其配置到 ~/.bashprofile中,如果用的是zsh,將其配置到 ~/.zshrc中,如下:
export JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk1.8.0_101.jdk/Contents/Home"
環境變數修改後需要source一下進行更新,比如如果修改的是~/.zshrc,需要執行$source ~/.zshrc
更新後執行echo $JAVA_HOME 如果能正常打印出環境變數,則證明環境變數已經配置成功.
3.安裝gradle(用於打包UIAutomatorWD)
$ brew install gradle
配置gradle環境變數,如果本地命令列工具用的是mac系統的預設命令列工具,將其配置到 /.bashprofile中,如果用的是zsh,將其配置到 /.zshrc中,如下:
export GRADLE_HOME="/usr/local/bin/gradle"
環境變數修改後需要source一下進行更新,比如如果修改的是~/.zshrc,需要執行$source ~/.zshrc
更新後執行 GRADLE_HOME 如果能正常打印出環境變數,則證明環境變數已經配置成功
4.安裝&配置安卓sdk
通過AndroidStudio內的sdkmanager安裝安卓依賴的sdk版本,操作路徑:
AndroidStudio -> Tools -> Android -> SDK Manager
需要安裝的依賴:
SDK Platforms : Android 6.0及以上版本
SDK Tools: Android SDK Platform-Tools && Android SDK Tools && NDK
具體勾選效果如下:
上面第一張圖中紅框標記的ANDROID_HOME地址是安卓SDK的路徑,需要配置到環境變數中,配置方法同gradle一樣
如上都配置好後,需要將兩個環境變數拼接到系統的PATH變數中,全部配置完成後的內容如下:
Macaca命令列工具安裝
macaca-cli為macaca的命令列工具,集成了macaca doctor等命令
$ cnpm i -g macaca-cli
// 備註 -g 表示全域性安裝,如果不加-g引數會在當前目錄下安裝macaca-cli
驅動安裝
執行如下命令安裝對應不同平臺的驅動,可以選擇性安裝
$ cnpm i macaca-ios -g// iOS驅動(用於iOS平臺自動化)$ cnpm i macaca-android -g// Android驅動(用於安卓平臺自動化)$ cnpm i macaca-chrome -g// chrome 驅動$ cnpm i macaca-electron -g// electron 驅動
備註:
- 當需要更新相應驅動時,直接執行如上的安裝命令即可
- cnpm i macaca-ios -g 如果提示 xcode-select: error: tool 'xcodebuild' requires Xcode, but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance 命令列執行如下即可: sudo xcode-select -s /Applications/Xcode.app/Contents/Developer
至此,便完成了完整的Macaca相關環境的安裝,此時我們可以通過macaca doctor命令檢查當前環境配置:
如圖為常規的Macaca環境配置結果,現在Macaca在環境上做了相對嚴格的校驗,如果有部分依賴安裝不成功,會給出相應的提示,針對性解決即可。
程式碼例項
https://github.com/microu2018/macaca-java-biz-sample
macaca-chromedriver
https://github.com/macacajs/macaca-chromedriver
awesome-macaca
A curated list of awesome things regarding Macaca ecosystem.
Table of Contents
Resources
Tutorials
Examples
- sample-nodejs - Macaca test sample for Node.js
- sample-java - Macaca test sample for Java
- sample-python - Macaca test sample for Python
- react-sample - Macaca test sample for browser React
- vue-sample - Macaca test sample for browser framework Vue.js
- webpack-datahub-sample - Webpack proxy middleware sample for DataHub
- antd-sample - Ant Design sample for DataHub
- angular-datahub-sample - Angular's ng toolchain sample for DataHub
- android-datahub-sample - Android sample for DataHub
- ios-datahub-sample - iOS sample for DataHub
- macaca-java-biz-framework - A framework for uiautomation business development based on wd.java
- macaca-java-biz-sample - Sample for Macaca business development based on wd.java
- macaca-reporter-standalone-sample - Sample for Macaca reporter
- android-docker-ci-sample - Sample for Macaca docker ci
- cv-sample-python - Sample for Macaca CV Python
- macaca_ci_android_ios - Macaca iOS 和 Android 並行測試
- po-sample-python - 基於 PageObject 跨平臺的設計模式
Clients
- macaca-wd - Node.js WebDriver Client for Macaca
- wd.java - Java client binding for Macaca
- wd.py - Python client binding for Macaca
Tools
Inspector
- App-inspector - App-inspector is a mobile UI viewer in browser
Recorder
- UI Recorder - UI Recorder is a UI test case recorder like Selenium IDE
DataHub
- DataHub - Continuous data provider for development, testing, staging and production.
- datahub-proxy-middleware - DataHub proxy middleware for Express.js
- datahub-nodejs-sdk - DataHub Node.js SDK
- datahub-java-sdk - DataHub SDK for Android and Java applications
- datahub-ios-sdk - DataHub SDK for iOS
- egg-datahub - Egg.js plugin for Macaca DataHub
- umi-plugin-datahub - UmiJS plugin for Macaca DataHub
Marmot
- Marmot - Release management suite with continuous delivery support for deployments
Coverage
- web-coverage-sample - Coverage sample for Web
- android-coverage-sample Coverage sample for Android
- ios-coverage-sample Coverage sample for iOS
NoSmoke
- NoSmoke - A cross platform UI crawler which scans view trees then generate and execute UI test cases.
Monkey Testing
- zhangzhao4444/Fastmonkey - 非插樁 iOS Monkey, 支援控制元件,每秒4-5 action事件
- baozhida/iosMonkey - 基於 Macaca 和 webdriveragent 模擬 monkey 的執行
- mengdegong/iosMonkey - iOS Monkey
- SwiftMonkey" target="_blank" rel="nofollow,noindex">zalando/SwiftMonkey - A framework for doing randomised UI testing of iOS apps
Computer Vision
- nodecv - Node.js binding to OpenCV
- nodecv-server - NodeCV server side
Page UITest
- Torchjs - Test framework to light up the world
- uitest - UI Test framework for Node.js based on Macaca
Browser Testing
- f2etest - F2etest是一個多瀏覽器相容性測試整體解決方案
Reporter
- macaca-reporter - Macaca reporter is a reporter used for mocha and other frameworks
Bot
- macaca-bot - :octocat: bot to resolve the issues and PR of Macaca
Other Tools
- macaca-adb - Node.js wrapper for ADB
- XCTestWD - A Swift implementation of WebDriver server for iOS that runs on Simulator/iOS devices
- ios-simulator - Node.js wrapper for iOS simulator
- UIAutomatorWD - Node.js wrapper for Android UIAutomator
- iosHookViewId - A solution for ios hook view id
- android-unicode - Android unicode UTF-7 input apk
- command-line-test - command-line test tool for Node.js
- android-performance - Node.js wrapper to android performance with adb
Drivers
- macaca-android - Macaca Android driver
- macaca-ios - Macaca iOS driver
- macaca-chrome - Macaca Chrome driver
- macaca-electron - Macaca Electron driver
- macaca-puppeteer - Macaca Puppeteer driver
Video
Articles
English
- Can you find XPath for mobile apps?
- Extract Xpath from App using Macaca Inspector
- Macaca inspector for Apple Mac - Automation Testing World!!
- Mobile and Web UI Testing with Macaca and OpenCV
Chinese
- UI 自動化框架調研總結
- 基於 Node.js 的自動化持續整合
- 獲取 Android 應用的效能
- 小馬 Macaca 入門指引合集
- Macaca-Java 版入門指南
- Mac OSX 佈署 Reliable
- Macaca 基礎原理淺析
- 應用自動新增控制元件 ID 探索
- Strikingly 團隊2017技術展望
- Macaca 測試用例單步除錯
- 混合 H5 應用 UI 自動化入門
- Android 輸入中文的實現
Presentations
Slides
Community
Contributing
Your contributions and suggestions are always welcome! :smiley:
Contributors
<img src="https://avatars1.githubusercontent.com/u/1011681?v=4" width="100px;"/> <b>xudafeng</b> |
---|
This project follows the git-contributor spec , auto upated at Sat Apr 21 2018 17:02:08 GMT+0800
.
License
[圖片上傳失敗...(image-c99436-1537499061724)]
macaca-wd.js
'use strict'; /** * Query the server's current status. * @summary Support: Android iOS Web(WebView) * @returns {Promise.<Object>} The server's current status. */ function status() {} /** * Create a new session. * @summary Support: Android iOS Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#dfn-new-session|POST /session} * @param {Object} desired Desired Capabilities * @type session * @returns {Promise.<Object>} */ function init(desired) {} /** * Returns a list of the currently active sessions. * @summary Support: Android iOS Web(WebView) * @returns {Promise.<Array>} */ function sessions() {} /** * Delete the session. * @summary Support: Android iOS Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#dfn-delete-session|DELETE /session/:sessionId} * @returns {Promise} * @type session */ function quit() {} /** * Get the current context. * @summary Support: Android iOS * @returns {Promise.<string>} */ function currentContext() {} /** * Set the current context. * @summary Support: Android iOS * @param {string} contextRef context reference from contexts * @returns {Promise} */ function context(contextRef) {} /** * Get a list of the available contexts. * @summary Support: Android iOS * @returns {Promise.<Array>} A list of available contexts. */ function contexts() {} /** * Set the amount of time the driver should wait. * @summary Support: Android iOS Web(WebView) * @param {number} ms The amount of time to wait, in milliseconds * @returns {Promise} */ function sleep(ms) {} /** * Take a screenshot of the current page. * @summary Support: Android iOS Web(WebView) * @returns {Promise.<string>} The screenshot as a base64 encoded PNG. */ function takeScreenshot() {} /** * Save the screenshot of the current page. * @summary Support: Android iOS Web(WebView) * @param {str} filepath The path to save the screenshot or left blank (will create a file in the system temp dir). * @returns {Promise.<string>} The filepath of the screenshot. */ function saveScreenshot(filepath) {} /** * Get the current page source. * @summary Support: Android iOS Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#dfn-get-page-source|GET/session/:sessionId/source} * @returns {Promise.<string>} */ function source() {} /** * Search for an element on the page, starting from the document root. * @summary Support: Android iOS Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#elements|POST /session/:sessionId/element} * @param {string} using The locator strategy to use. * @param {string} value The search target. * @returns {Promise.<Element>} */ function element(using, value) {} /** * Search for an element on the page, starting from the document root. * @summary Support: Android iOS Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#elements|POST /session/:sessionId/element} * @param {string} value The class name * @returns {Promise.<Element>} */ function elementByClassName(value) {} /** * Search for an element on the page, starting from the document root. * @summary Support: Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#elements|POST /session/:sessionId/element} * @param {string} value The css selector * @returns {Promise.<Element>} */ function elementByCss(value) {} /** * Search for an element on the page, starting from the document root. * @summary Support: Android iOS Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#elements|POST /session/:sessionId/element} * @param {string} value The ID attribute * @returns {Promise.<Element>} */ function elementById(value) {} /** * Search for an element on the page, starting from the document root. * @summary Support: Android iOS Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#elements|POST /session/:sessionId/element} * @param {string} value The name attribute * @returns {Promise.<Element>} */ function elementByName(value) {} /** * Search for an element on the page, starting from the document root. * @summary Support: Android iOS Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#elements|POST /session/:sessionId/element} * @param {string} value The text * @returns {Promise.<Element>} */ function elementByLinkText(value) {} /** * Search for an element on the page, starting from the document root. * @summary Support: Android iOS Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#elements|POST /session/:sessionId/element} * @param {string} value The partially text * @returns {Promise.<Element>} */ function elementByPartialLinkText(value) {} /** * Search for an element on the page, starting from the document root. * @summary Support: Android iOS Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#elements|POST /session/:sessionId/element} * @param {string} value The tag name * @returns {Promise.<Element>} */ function elementByTagName(value) {} /** * Search for an element on the page, starting from the document root. * @summary Support: Android iOS Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#elements|POST /session/:sessionId/element} * @param {string} value The XPath expression * @returns {Promise.<Element>} */ function elementByXPath(value) {} /** * Search for multiple elements on the page, starting from the document root. * @summary Support: Android iOS Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#elements|POST /session/:sessionId/elements} * @param {string} using The locator strategy to use. * @param {string} value The search target. * @returns {Promise.<Array>} */ function elements(using, value) {} /** * Search for multiple elements on the page, starting from the document root. * @summary Support: Android iOS Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#elements|POST /session/:sessionId/elements} * @param {string} value The class name * @returns {Promise.<Array>} */ function elementsByClassName(value) {} /** * Search for multiple elements on the page, starting from the document root. * @summary Support: Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#elements|POST /session/:sessionId/elements} * @param {string} value The css selector * @returns {Promise.<Array>} */ function elementsByCss(value) {} /** * Search for multiple elements on the page, starting from the document root. * @summary Support: Android iOS Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#elements|POST /session/:sessionId/elements} * @param {string} value The ID attribute * @returns {Promise.<Array>} */ function elementsById(value) {} /** * Search for multiple elements on the page, starting from the document root. * @summary Support: Android iOS Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#elements|POST /session/:sessionId/elements} * @param {string} value The name attribute * @returns {Promise.<Array>} */ function elementsByName(value) {} /** * Search for multiple elements on the page, starting from the document root. * @summary Support: Android iOS Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#elements|POST /session/:sessionId/elements} * @param {string} value The text * @returns {Promise.<Array>} */ function elementsByLinkText(value) {} /** * Search for multiple elements on the page, starting from the document root. * @summary Support: Android iOS Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#elements|POST /session/:sessionId/elements} * @param {string} value The partially text * @returns {Promise.<Array>} */ function elementsByPartialLinkText(value) {} /** * Search for multiple elements on the page, starting from the document root. * @summary Support: Android iOS Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#elements|POST /session/:sessionId/elements} * @param {string} value The tag name * @returns {Promise.<Array>} */ function elementsByTagName(value) {} /** * Search for multiple elements on the page, starting from the document root. * @summary Support: Android iOS Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#elements|POST /session/:sessionId/elements} * @param {string} value The XPath expression * @returns {Promise.<Array>} */ function elementsByXPath(value) {} /** * All the element-related methods above (except which suffixed with OrNull, IfExists) could be prefixed with the "waitFor-" (need to capitalize the 'e', e.g., waitForElementByClassName) * @summary Support: Android iOS Web(WebView) * @param {string} using The locator strategy to use, omitted when using specific method like waitForElementByClassName. * @param {string} value The css selector * @param {function} [asserter] The asserter function (commonly used asserter function can be found at wd.asserters) (optional) * @param {number} [timeout=1000ms] The timeout before find the element (optional) * @param {number} [interval=200ms] The interval between each searching (optional) * @example waitForElementByClassName('btn', 2000, 100) Search for element which class name is 'btn' at intervals of 100ms, last for 2000ms. * @returns {Promise.<Array>} */ function waitForElement(using, value, asserter, timeout, interval) {} /** * Search for an element on the page, starting from the document root. * @summary Support: Android iOS Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#elements|POST /session/:sessionId/element} * @param {string} using The locator strategy to use. * @param {string} value The search target. * @returns {Promise.<Element|null>} */ function elementOrNull(using, value) {} /** * Search for an element on the page, starting from the document root. * @summary Support: Android iOS Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#elements|POST /session/:sessionId/element} * @param {string} value The class name * @returns {Promise.<Element|null>} */ function elementByClassNameOrNull(value) {} /** * Search for an element on the page, starting from the document root. * @summary Support: Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#elements|POST /session/:sessionId/element} * @param {string} value The css selector * @returns {Promise.<Element|null>} */ function elementByCssOrNull(value) {} /** * Search for an element on the page, starting from the document root. * @summary Support: Android iOS Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#elements|POST /session/:sessionId/element} * @param {string} value The ID attribute * @returns {Promise.<Element|null>} */ function elementByIdOrNull(value) {} /** * Search for an element on the page, starting from the document root. * @summary Support: Android iOS Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#elements|POST /session/:sessionId/element} * @param {string} value The name attribute * @returns {Promise.<Element|null>} */ function elementByNameOrNull(value) {} /** * Search for an element on the page, starting from the document root. * @summary Support: Android iOS Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#elements|POST /session/:sessionId/element} * @param {string} value The text * @returns {Promise.<Element|null>} */ function elementByLinkTextOrNull(value) {} /** * Search for an element on the page, starting from the document root. * @summary Support: Android iOS Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#elements|POST /session/:sessionId/element} * @param {string} value The partially text * @returns {Promise.<Element|null>} */ function elementByPartialLinkTextOrNull(value) {} /** * Search for an element on the page, starting from the document root. * @summary Support: Android iOS Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#elements|POST /session/:sessionId/element} * @param {string} value The tag name * @returns {Promise.<Element|null>} */ function elementByTagNameOrNull(value) {} /** * Search for an element on the page, starting from the document root. * @summary Support: Android iOS Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#elements|POST /session/:sessionId/element} * @param {string} value The XPath expression * @returns {Promise.<Element|null>} */ function elementByXPathOrNull(value) {} /** * Search for an element on the page, starting from the document root. * @summary Support: Android iOS Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#elements|POST /session/:sessionId/element} * @param {string} using The locator strategy to use. * @param {string} value The search target. * @returns {Promise.<Element|null>} */ function elementIfExists(using, value) {} /** * Search for an element on the page, starting from the document root. * @summary Support: Android iOS Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#elements|POST /session/:sessionId/element} * @param {string} value The class name * @returns {Promise.<Element|undefined>} */ function elementByClassNameIfExists(value) {} /** * Search for an element on the page, starting from the document root. * @summary Support: Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#elements|POST /session/:sessionId/element} * @param {string} value The css selector * @returns {Promise.<Element|undefined>} */ function elementByCssIfExists(value) {} /** * Search for an element on the page, starting from the document root. * @summary Support: Android iOS Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#elements|POST /session/:sessionId/element} * @param {string} value The ID attribute * @returns {Promise.<Element|undefined>} */ function elementByIdIfExists(value) {} /** * Search for an element on the page, starting from the document root. * @summary Support: Android iOS Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#elements|POST /session/:sessionId/element} * @param {string} value The name attribute * @returns {Promise.<Element|undefined>} */ function elementByNameIfExists(value) {} /** * Search for an element on the page, starting from the document root. * @summary Support: Android iOS Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#elements|POST /session/:sessionId/element} * @param {string} value The text * @returns {Promise.<Element|undefined>} */ function elementByLinkTextIfExists(value) {} /** * Search for an element on the page, starting from the document root. * @summary Support: Android iOS Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#elements|POST /session/:sessionId/element} * @param {string} value The partially text * @returns {Promise.<Element|undefined>} */ function elementByPartialLinkTextIfExists(value) {} /** * Search for an element on the page, starting from the document root. * @summary Support: Android iOS Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#elements|POST /session/:sessionId/element} * @param {string} value The tag name * @returns {Promise.<Element|undefined>} */ function elementByTagNameIfExists(value) {} /** * Search for an element on the page, starting from the document root. * @summary Support: Android iOS Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#elements|POST /session/:sessionId/element} * @param {string} value The XPath expression * @returns {Promise.<Element|undefined>} */ function elementByXPathIfExists(value) {} /** * Check if element exists. * @summary Support: Android iOS Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#elements|POST /session/:sessionId/element} * @param {string} using The locator strategy to use. * @param {string} value The search target. * @type assert * @returns {Promise.<boolean>} */ function hasElement(using, value) {} /** * Check if element exists. * @summary Support: Android iOS Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#elements|POST /session/:sessionId/element} * @param {string} value The class name. * @type assert * @returns {Promise.<boolean>} */ function hasElementByClassName(value) {} /** * Check if element exists. * @summary Support: Android iOS Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#elements|POST /session/:sessionId/element} * @param {string} value The ID attribute. * @type assert * @returns {Promise.<boolean>} */ function hasElementById(value) {} /** * Check if element exists. * @summary Support: Android iOS Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#elements|POST /session/:sessionId/element} * @param {string} value The name attribute. * @type assert * @returns {Promise.<boolean>} */ function hasElementByName(value) {} /** * Check if element exists. * @summary Support: Android iOS Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#elements|POST /session/:sessionId/element} * @param {string} value The text. * @type assert * @returns {Promise.<boolean>} */ function hasElementByLinkText(value) {} /** * Check if element exists. * @summary Support: Android iOS Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#elements|POST /session/:sessionId/element} * @param {string} value The partially text. * @type assert * @returns {Promise.<boolean>} */ function hasElementByPartialLinkText(value) {} /** * Check if element exists. * @summary Support: Android iOS Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#elements|POST /session/:sessionId/element} * @param {string} value The tag name. * @type assert * @returns {Promise.<boolean>} */ function hasElementByTagName(value) {} /** * Check if element exists. * @summary Support: Android iOS Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#elements|POST /session/:sessionId/element} * @param {string} value The XPath expression. * @type assert * @returns {Promise.<boolean>} */ function hasElementByXPath(value) {} /** * Click on an element. * @summary Support: Android iOS Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#dfn-element-click|POST /session/:sessionId/element/:id/click} * @returns {Promise} */ function click() {} /** * Send a sequence of key strokes to the active element. * @summary Support: Android iOS Web(WebView) * @param {string} keys The keys sequence to be sent. * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#dfn-element-send-keys|POST /session/:sessionId/element/:id/sendKeys} * @type element * @returns {Promise} */ function sendKeys(keys) {} /** * Send a sequence of key strokes to the active window. * @summary Support: Android Web(WebView) More: https://github.com/alibaba/macaca/issues/487 * @param {string} keys The keys sequence to be sent. * @returns {Promise} */ function keys(keys) {} /** * Returns the visible text for the element. * @summary Support: Android iOS Web(WebView) * @type element * @returns {Promise.<string>} */ function text() {} /** * Clear a TEXTAREA or text INPUT element's value. * @summary Support: Android iOS Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#element-clear|POST /session/:sessionId/element/:id/clear} * @type element * @returns {Promise.<string>} */ function clear() {} /** * Determine if an element is currently displayed. * @summary Support: Android Web(WebView) * @type element * @returns {Promise.<string>} */ function isDisplayed() {} /** * Get the result of a property of a element. * @summary Support: Android iOS Web(WebView). iOS: 'isVisible', 'isAccessible', 'isEnabled', 'type', 'label', 'name', 'value', Android: 'selected', 'description', 'text' * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#dfn-get-element-property|GET /session/:sessionId/element/:id/property/:name} * @param {string} name The property name * @type element * @returns {Promise.<string>} */ function getProperty(name) {} /** * Query the value of an element's computed CSS property. * @summary Support: Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#get-element-css-value|GET /session/:sessionId/element/:id/css/:propertyName} * @param {string} propertyName The property name * @type element * @returns {Promise.<string>} */ function getComputedCss(propertyName) {} /** * Get the dimensions and coordinates of the given element with a object including x/y/height/width. * @summary Support: Android iOS. * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#dfn-get-element-rect|GET /session/:sessionId/element/:id/rect} * @type element * @returns {Promise.<string>} */ function getRect() {} /** * Inject a snippet of JavaScript into the page for execution in the context of the currently selected frame. * @summary Support: Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#executing-script|POST /session/:sessionId/execute} * @param code script * @param [args] script argument array * @returns {Promise.<string>} */ function execute() {} /** * Get the current page title or focus activity or viewController. * @summary Support: Android iOS Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#accept-alert|GET /session/:sessionId/title} * @returns {Promise.<string>} */ function title() {} /** * Accepts the currently displayed alert dialog. * @summary Support: Android iOS * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#accept-alert|POST /session/:sessionId/accept_alert} * @returns {Promise.<string>} */ function acceptAlert() {} /** * Dismisses the currently displayed alert dialog. * @summary Support: Android iOS * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#dismiss-alert|POST /session/:sessionId/dismiss_alert} * @returns {Promise.<string>} */ function dismissAlert() {} /** * Gets the text of the currently displayed JavaScript alert(), confirm(), or prompt() dialog. * @summary Support: iOS * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#send-alert-text|GET /session/:sessionId/alert_text} * @returns {Promise.<string>} */ function alertText() {} /** * Sends keystrokes to a JavaScript prompt() dialog. * @summary Support: iOS * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#send-alert-text|POST /session/:sessionId/alert_text} * @param keys * @returns {Promise.<string>} */ function alertKeys() {} /** * Retrieve the URL of the current page. * @summary Support: Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#get-current-url|GET /session/:sessionId/url} * @returns {Promise.<string>} */ function url() {} /** * Navigate to a new URL. * @summary Support: Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#get|POST /session/:sessionId/url} * @param url get a new url. * @type browser * @returns {Promise.<string>} */ function get() {} /** * Navigate forwards in the browser history, if possible. * @summary Support: Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#back|POST /session/:sessionId/forward} * @type browser * @returns {Promise.<string>} */ function forward() {} /** * Navigate backwards in the browser history, if possible. * @summary Support: Android Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#back|POST /session/:sessionId/back} * @type browser * @returns {Promise.<string>} */ function back() {} /** * Refresh the current page. * @summary Support: Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#refresh|POST /session/:sessionId/refresh} * @type browser * @returns {Promise.<string>} */ function refresh() {} /** * Change focus to another window. * @summary Support: Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#switch-to-window|POST /session/:sessionId/window} * @returns {Promise.<string>} */ function window() {} /** * Close the current window. * @summary Support: Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#close-window|DELETE /session/:sessionId/window} * @type window * @returns {Promise.<string>} */ function close() {} /** * Retrieve the current window handle. * @summary Support: Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#get-window-handle|GET /session/:sessionId/window_handle} * @returns {Promise.<string>} */ function windowHandle() {} /** * Retrieve the list of all window handles available to the session. * @summary Support: Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#get-window-handles|GET /session/:sessionId/window_handles} * @returns {Promise.<string>} */ function windowHandles() {} /** * Get the size of the specified window. * @summary Support: Android iOS Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#get-window-size|GET /session/:sessionId/window/size} * @param [handle] window handle to set size for (optional, default: 'current') * @returns {Promise.<string>} */ function getWindowSize() {} /** * Change the size of the specified window. * @summary Support: Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#set-window-size|POST /session/:sessionId/window/size} * @param width width in pixels to set size to * @param height height in pixels to set size to * @param [handle] window handle to set size for (optional, default: 'current') * @returns {Promise.<string>} */ function setWindowSize() {} /** * Maximize the specified window if not already maximized. * @summary Support: Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#dfn-maximize-window|POST /session/:sessionId/window/maximize} * @param handle window handle * @type browser * @returns {Promise.<string>} */ function maximize() {} /** * Change focus to another frame on the page. * @summary Support: Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#switch-to-frame|POST /session/:sessionId/frame} * @param {string|number|null} frameRef Identifier(id/name) for the frame to change focus to * @returns {Promise.<string>} */ function frame(frameRef) {} /** * Apply touch actions on devices. * @summary Support: iOS, Android * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#actions|POST /session/:sessionId/actions} * @param {string} action Name of the action, tap/doubleTap/press/pinch/rotate/drag. * @param [object] args Parameters of the action {@link https://github.com/alibaba/macaca/issues/366 more params} * @example driver.touch('doubleTap', {x: 100, y: 100}); * @returns {Promise.<string>} */ function touch(action, args) {} /** * Returns all cookies associated with the address of the current browsing context’s active document. * @summary Support: Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#get-all-cookies|GET /session/:sessionId/cookie} * @returns {Promise.<string>} */ function allCookies() {} /** * Adds a single cookie to the cookie store associated with the active document’s address. {url: 'https://macacajs.github.io', name:'foo', value:'bar'} Optional cookie fields: secure, expiry * @summary Support: Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#add-cookie|POST /session/:sessionId/cookie} * @returns {Promise.<string>} */ function setCookie() {} /** * Delete either a single cookie by parameter name, or all the cookies associated with the active document’s address if name is undefined. * @summary Support: Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#delete-cookie|DELETE /session/:sessionId/cookie/:name} * @returns {Promise.<string>} */ function deleteCookie() {} /** * Allows deletion of all cookies associated with the active document’s address. * @summary Support: Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#delete-all-cookies|DELETE /session/:sessionId/cookie/:name} * @returns {Promise.<string>} */ function deleteAllCookies() {} const helper = require('./helper'); const wd = require('../wd/lib/main'); module.exports = wd; module.exports.helper = helper; module.exports.webpackHelper = helper(wd);