0.0.6 • Published 5 years ago

webdriver-android-helper v0.0.6

Weekly downloads
2
License
MIT
Repository
github
Last release
5 years ago

webdriver-android-helper

:black_square_button: a webdriver android helper with zero dependences

NPM

install

npm i webdriver-android-helper -S

usage

const wd = require('webdriverio')
const driver = wd.remote({})
const WdAndroidHelper = require('webdriver-android-helper')
const helper = new WdAndroidHelper(driver)
namedesc
isElFindedDetermine whether an element is found
isElsFindedDetermine whether a set of elements is found
androidIdGenerate androidId selectors for webdriver
findElByIdFind element by Android Id
findElByXpathFind element by Xpath
findElsByIdFind elements by Android Id
findElsByXpathFind elements by Xpath
findElByIdAndClickFind element by Android Id And Click it
findElByXpathAndClickFind element by Xpath And Click it
waitElFindedWaiting for the element to be found
waitElsFindedWaiting for the elements to be found
waitActivityResumedWaiting for the Activity Resume
waitActivitiesResumedWaiting for the Some Activities Resume
waitActivityDestroyWaiting for the Activity Destroy
slideOnElementSlide on element by direction
slideOnScreenSlide on screen by direction
setElTextAndPressSBset text and trigger change event on EditText
backToActivityBack to the designated Activity
findElByIdAndSetTextFind element by Android Id And set text
findElByXpathAndSetTextFind element by xpath And set text
momentwait for between 1s - 3s
findElByMatcherInViewsfind element in listviews by matcher function
isThisActivityDetermine if the current activity is the specified activity
pushImagesPush images to /sdcard/DCIM/Camera/
logAppend log to file

sample

const wdio = require('webdriverio')
const WdAndroidHelper = require('webdriver-android-helper')
// sample to Init ss client
async function startSs() {
    let driver
    try {
        driver = await wdio.remote({
            port: 4723,
            capabilities: {
                "platformName": "Android",
                "platformVersion": "5",
                "deviceName": 'emulator-5554',
                "appPackage": "com.github.shadowsocks",
                "appActivity": ".MainActivity",
                "automationName": "UiAutomator2",
                "noReset": true,
                "udid": 'emulator-5554',
                "autoGrantPermissions": true,
                "systemPort": 8203
            },
            logLevel: !debug ? 'silent' : 'error'
        })
        const helper = new WdAndroidHelper(driver)
        await driver.unlock()
        // wait MainActivity
        await helper.waitActivityResumed('.MainActivity')
        await helper.moment()
        // start edit 
        await helper.findElByIdAndClick('com.github.shadowsocks:id/edit')
        await helper.moment()
        // set ip
        await helper.findElByXpathAndClick('/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.view.View/android.widget.LinearLayout[3]/android.widget.RelativeLayout')
        await helper.moment()
        await helper.findElByIdAndSetText('android:id/edit', 'ssr ip')
        await helper.moment()
        await helper.findElByIdAndClick('android:id/button1')
        await helper.moment()
        // set port
        await helper.findElByXpathAndClick('/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.view.View/android.widget.LinearLayout[4]/android.widget.RelativeLayout')
        await helper.moment()
        await helper.findElByIdAndSetText('android:id/edit', 'ssr port')
        await helper.moment()
        await helper.findElByIdAndClick('android:id/button1')
        await helper.moment()
        // set password
        await helper.findElByXpathAndClick('/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.view.View/android.widget.LinearLayout[5]/android.widget.RelativeLayout/android.widget.TextView[2]')
        await helper.moment()
        await helper.findElByIdAndSetText('android:id/edit', 'ssr password')
        await helper.moment()
        await helper.findElByIdAndClick('android:id/button1')
        await helper.moment()
        // set encrypt
        await helper.findElByXpathAndClick('/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.view.View/android.widget.FrameLayout[1]/android.widget.LinearLayout/android.widget.RelativeLayout')
        await helper.moment()
        await helper.findElByMatcherInViews('/hierarchy/android.widget.FrameLayout/android.view.View', 'android:id/text1', async (item) => {
            const text = await item.getText()
            return text === 'ssr encrypt type'.toUpperCase()
        }, async (item) => {
            await item.click()
        })
        await helper.findElByIdAndClick('com.github.shadowsocks:id/action_apply')
        await helper.waitActivityDestroy('.ProfileConfigActivity')
        await helper.moment()
        // final start
        await helper.findElByIdAndClick('com.github.shadowsocks:id/fab')
        await helper.moment(3000, 3500)
        const is = await helper.isThisActivity('.ConfirmDialog')
        if (is) {
            await helper.moment()
            await helper.findElByIdAndClick('android:id/button1')
        }
    } catch (err) {
        console.log(err)
    }
    await driver.pause(5000)
    await driver.deleteSession()
}
0.0.6

5 years ago

0.0.5

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago