Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
216 changes: 216 additions & 0 deletions android-native-app-test
Original file line number Diff line number Diff line change
@@ -0,0 +1,216 @@
import 'babel-polyfill'
import 'colors'
import wd from 'wd'
import {assert} from 'chai'
import { WebDriver } from 'selenium-webdriver'
const waitingTime = 60000
const config = {
protocol: 'http',
host: '192.168.36.47',
pathname: '/webdriver'
}


// const config = {
// protocol: 'http',
// host: '127.0.0.1:4723',
// }


const desiredCaps = {
'gigafox:device': 'f88b319e-306c-45f4-bd51-f0e7481f627c',
'gigafox:application': 'API Demos',
'gigafox:username': 'admin',
'gigafox:apiKey': 'f619219b-0de5-4e3b-a9f7-326bec843358',
//'browser': '',
'browserName': '',
'gigafox:existingSession': 'delete'
}


// const desiredCaps = {
// 'platformName': 'Android',
// 'platformVersion': '11',
// 'deviceName': 'Samsung Galaxy S20 Ultra LTE',
// 'automationName': 'Appium',
// 'app': 'https://s3-ap-southeast-1.amazonaws.com/kobiton-devvn/apps-test/ApiDemos-debug.apk',
// 'appPackage': 'io.appium.android.apis',
// 'appActivity': '.ApiDemos',
// }

let driver


describe('Android App sample', () => {

before(async () => {
driver = wd.promiseChainRemote(config)

driver.on('status', (info) => {
console.log(info.cyan)
})
driver.on('command', (meth, path, data) => {
console.log(' > ' + meth.yellow, path.grey, data || '')
})
driver.on('http', (meth, path, data) => {
console.log(' > ' + meth.magenta, path, (data || '').grey)
})

try {
await driver.init(desiredCaps)
}
catch (err) {
if (err.data) {
console.error(`init driver: ${err.data}`)
}
throw err
}
})

it('should show the app label', async () => {
console.error(`Run TC`)
await driver
.context('NATIVE_APP')
.execute('mobile: shell', {command: 'echo', args: ['hello']})
//.installApp("/Volumes/Macintosh\ HD\ -\ Data/ApiDemos-debug.apk ")
.waitForElementByXPath("//android.widget.TextView[@content-desc='App']", waitingTime)
// .elementByXPath("//android.widget.TextView[@content-desc='App']")
// .noop()
// .click()
// .waitForElementByXPath("//android.widget.TextView[@content-desc='Activity']", waitingTime)
// .elementByXPath("//android.widget.TextView[@content-desc='Activity']")
// .click()
// .sleep(2000)
// .elementByXPath("//android.widget.TextView[@content-desc='Intent Activity Flags']")

// //Point
// .flick(0, -700, 200)
// .flick(0, -700, 200)
// .elementByXPath("//android.widget.TextView[@content-desc='Soft Input Modes']")
// .click()
// .elementById('saved')
// .click()
// .isKeyboardShown()
// .hideDeviceKeyboard()
// .elementById('saved')
// .click()
// .clear()
// .type('Tab')
// .currentContext()
// .contexts()
// .context('NATIVE_APP')
// .availableIMEEngines()
// .activeIMEEngine()
// //.deactivateIMEEngine() adb -P 5037 -s R5CN205DJ2J shell ime disable
// .activeIMEEngine()
// .elementByClassName('android.widget.TextView')
// .elementByClassNameOrNull('android.widget.TextView')
// .hideDeviceKeyboard()
// .element('xpath', "//android.widget.TextView[@content-desc='Resize mode:']").then((ele) => {
// driver
// .isEnabled(ele)
// .isSelected(ele)
// .getAttribute(ele)
// })
// .elements('xpath', '//android.widget.TextView')
// .sessions()
// .sessionCapabilities()
// .setCommandTimeout(waitingTime)
// .setImplicitWaitTimeout(waitingTime)
// .takeScreenshot()
// .saveScreenshot('screenshot.png')
// .back()
// .back()
// .back()
// .sleep(2)
// .execute('mobile: shell', {command: 'echo', args: ['hello']}) //appium --relaxed-security
// eslint-disable-next-line babel/no-await-in-loop
// let hasEle = await driver.hasElementByXPath("//*[@content-desc='Accessibility']")
// if (!hasEle) {
// await driver // eslint-disable-line babel/no-await-in-loop
// .back()
// .waitForElementByXPath("//*[@content-desc='Accessibility']", waitingTime)
// }
await driver // eslint-disable-line babel/no-await-in-loop
.waitForElementByXPath("//*[@content-desc='Accessibility']", waitingTime)
// .elementByXPath("//*[@content-desc='Accessibility']").text()
// .elementByXPath("//*[@content-desc='Accessibility']")
// .click()
// .back()
// .source()
// .hasElementById('android:id/list')
// .elementById('android:id/list')
// .flick(0, -700, 200)
// .elementById('android:id/list')
// .flick(300, 700, 200)
.getWindowSize()
// .waitForElementByXPath("//android.widget.TextView[@content-desc='Animation']", waitingTime)
// .click()
// .waitForElementByXPath("//android.widget.TextView[@content-desc='Bouncing Balls']",
// waitingTime)
// .click()
// .elementById('container')
// .flick(getRandomInt(1, 1000),
// getRandomInt(-200, 200), getRandomInt(100, 1000))
// .sleep(5)
// .flick(getRandomInt(-200, 200),
// getRandomInt(-1000, 0), getRandomInt(100, 1000))
// .back()
// .back()
// .waitForElementByXPath("//android.widget.TextView[@content-desc='Animation']")
// .flick(0, -700, 200)
// .waitForElementByXPath("//android.widget.TextView[@content-desc='Views']")
// .click()
// .sleep(7000)
// .element('xpath', "//android.widget.TextView[@content-desc='Controls']")
// .flick(0, -700, 200)
// .flick(0, -700, 200)
// .waitForElementByXPath("//android.widget.TextView[@content-desc='WebView']")
// .click()
// .execute('mobile: getPermissions', {type: 'granted', appPackage: 'io.appium.android.apis'})
// // eslint-disable-next-line max-len
// .execute('mobile: changePermissions', {action: 'grant', appPackage: 'io.appium.android.apis', permissions: 'android.permission.READ_CONTACTS'})
// .contexts()
// .context('WEBVIEW_io.appium.android.apis')
// let touchAction = new wd.TouchAction(driver)
// touchAction.press({x: 10, y: 10})
// touchAction.moveTo({x: 10, y: 100})
// touchAction.release()
// await touchAction.perform() // eslint-disable-line babel/no-await-in-loop
// let secondTouchAction = new wd.TouchAction(driver)
// secondTouchAction.press({x: 10, y: 10})
// secondTouchAction.moveTo({x: 10, y: 100})
// secondTouchAction.release()
// let multiTouchAction = new wd.MultiAction(driver)
// multiTouchAction.add(touchAction)
// multiTouchAction.add(secondTouchAction)
// await multiTouchAction.perform() // eslint-disable-line babel/no-await-in-loop
// await driver.context('NATIVE_APP') // eslint-disable-line babel/no-await-in-loop
// .getOrientation()
// .setOrientation('PORTRAIT')
// .setOrientation('LANDSCAPE')
// .setOrientation('PORTRAIT')
// //.openNotifications()
// .elements('xpath', '//android.widget.TextView')
// .sessions()
// .sessionCapabilities()
// .setImplicitWaitTimeout(waitingTime)
// .startActivity({
// appPackage: 'io.appium.android.apis',
// appActivity: '.accessibility.AccessibilityNodeProviderActivity'
// })
})
function getRandomInt(min, max) {
return Math.floor(Math.random() * (max - min + 1) + min)
}
after(async () => {
if (driver != null) {
try {
await driver.quit()
}
catch (err) {
console.error(`quit driver: ${err}`)
}
}
})
})