goandroid

package module
v0.0.0-...-028fd47 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 29, 2019 License: MIT Imports: 6 Imported by: 0

README

goandroid_logo

goandroid

Project Status Build Status Coverage Status Issues Documentation License

Introduction

"goandroid" is an Android automation library purely written in GO.

Project Status : Under Development, not yet ready for v1.0 release.

Whether you are an android developer and want to do some automation tasks on your android device to reduce some manual human work, or an enthusiastic developer who want to do some automation taks on your android device, this library allows you to write automation code and do cool stuffs on your android device.

TODO's
  • Complete all Package Documentation's
  • Implement all features for v1.0
  • Write test code for all packages such that it can be tested on Travis CI over emulator
FAQ's
  • Is it a wrapper arround Android UI Automator library?

    No, goandroid does not uses UI Automator for its implementation. It does not uses any java backend or JSON RPC service to communicate UI Automator.

  • Is it Android testing framework?

    No, goandroid is not an android trsting framework. Its an automation framework, but can be used for android UI automation and testing perpuses also.

  • Does it installs anything on my android device?

    No, goandroid does not installs any APK or other tools in your android device to provide any features.

  • Can you explain how does it work?

    This library is purely based on ADB (Android Debugger Bridge) and adb tool. It uses adb commands to perform all operations on device. You can write automation code using this library and check logs for what adb command has been executed for that automation logic.

  • I want this feature X, can you include X in goandroid?

    If the feature you are requesting can be implemented only by using adb commands, yes I will add the feature for you. Just make a pull request or start a new issue describing the adb equivalent implementation for the feature.

  • What are the dependencies of goandroid?

    The only dependency of goandroid library is "adb" executable tool.

Usage & Example

Install adb

First of all make sure you have "adb" tool in your system path.

For Ubuntu 14.04 or later use following commands to install adb:

sudo apt-get update
sudo apt-get install android-tools-adb

For other distributions, download Android SDK and "adb" tool can be located inside"platform-tools" direcory. Now add this to your system path using following comands:

cd <root folder of sdk>
export PATH=$PATH:$PWD/platform-tools
Initialize Android device instance

First import "github.com/kunaldawn/goandroid" in your source, and you are ready to write some cool automation code. To interact with an android device, you need to create an android device instance first. Following example shows how to create a new android device instance and enable "Show CPU Usage" settings using automation. Please locate the documentation for package goandroid for more information.

Example:

Youtube Screen Cast

package main

import (
	"github.com/kunaldawn/goandroid"
)

func main() {
	// Creat a new android manager with 60 seconds adb time out and take adb
	// executable path from system path.
	android_manager := goandroid.GetNewAndroidManager(60, "adb")

	// Create an android device instance with following serial
	android := android_manager.GetNewAndroidDevice("emulator-5554")

	// Start settings activity
	android.Activity.StartActivity("com.android.settings")
	// Wait for settings activity to get focused and displayed on screen
	// with 10 seconds timeout
	android.Activity.WaitForActivityToFocus("com.android.settings", 10)

	// Scroll down to "About phone"
	android.View.ScrollDownToText("About phone", 0, 10)
	// Now click "About phone" settings item
	android.View.ClickText("About phone", 0, 5)

	// Now scroll down to "Build number"
	android.View.ScrollDownToText("Build number", 0, 10)

	// Now for faster click operation, we are going to get the view for "Build number" text
	view, _ := android.View.GetViewForText("Build number", 0, 5)

	// Now we will click the text 10 times
	for i := 0; i < 10; i++ {
		android.Input.TouchScreen.Tap(view.Center.X, view.Center.Y)
	}

	// Now go back to main settings page
	android.Input.Key.PressBack(1)
	// Click developer options
	android.View.ClickText("Developer options", 0, 10)
	
	// Now scroll down to "Show CPU Usage" and enable it
	android.View.ScrollDownToMatchingText("show cpu", 0, 10)
	android.View.ClickMatchingText("show cpu", 0, 10)
}

Translated adb commands by goandroid for above code:

adb : [-s emulator-5554 root]
adb : [-s emulator-5554 wait-for-device]
adb : [-s emulator-5554 shell am start com.android.settings]
adb : [-s emulator-5554 shell dumpsys activity | grep mFocusedActivity:]
adb : [-s emulator-5554 shell uiautomator dump]
adb : [-s emulator-5554 shell cat /storage/sdcard/window_dump.xml]
adb : [-s emulator-5554 shell wm size]
adb : [-s emulator-5554 shell input touchscreen swipe 540 1440 540 480 1000]
adb : [-s emulator-5554 shell uiautomator dump]
adb : [-s emulator-5554 shell cat /storage/sdcard/window_dump.xml]
adb : [-s emulator-5554 shell wm size]
adb : [-s emulator-5554 shell input touchscreen swipe 540 1440 540 480 1000]
adb : [-s emulator-5554 shell uiautomator dump]
adb : [-s emulator-5554 shell cat /storage/sdcard/window_dump.xml]
adb : [-s emulator-5554 shell wm size]
adb : [-s emulator-5554 shell input touchscreen swipe 540 1440 540 480 1000]
adb : [-s emulator-5554 shell uiautomator dump]
adb : [-s emulator-5554 shell cat /storage/sdcard/window_dump.xml]
adb : [-s emulator-5554 shell uiautomator dump]
adb : [-s emulator-5554 shell cat /storage/sdcard/window_dump.xml]
adb : [-s emulator-5554 shell input tap 369 1643]
adb : [-s emulator-5554 shell uiautomator dump]
adb : [-s emulator-5554 shell cat /storage/sdcard/window_dump.xml]
adb : [-s emulator-5554 shell uiautomator dump]
adb : [-s emulator-5554 shell cat /storage/sdcard/window_dump.xml]
adb : [-s emulator-5554 shell input tap 188 1684]
adb : [-s emulator-5554 shell input tap 188 1684]
adb : [-s emulator-5554 shell input tap 188 1684]
adb : [-s emulator-5554 shell input tap 188 1684]
adb : [-s emulator-5554 shell input tap 188 1684]
adb : [-s emulator-5554 shell input tap 188 1684]
adb : [-s emulator-5554 shell input tap 188 1684]
adb : [-s emulator-5554 shell input tap 188 1684]
adb : [-s emulator-5554 shell input tap 188 1684]
adb : [-s emulator-5554 shell input tap 188 1684]
adb : [-s emulator-5554 shell input keyevent 4]
adb : [-s emulator-5554 shell uiautomator dump]
adb : [-s emulator-5554 shell cat /storage/sdcard/window_dump.xml]
adb : [-s emulator-5554 shell input tap 433 1426]
adb : [-s emulator-5554 shell uiautomator dump]
adb : [-s emulator-5554 shell cat /storage/sdcard/window_dump.xml]
adb : [-s emulator-5554 shell wm size]
adb : [-s emulator-5554 shell input touchscreen swipe 540 1440 540 480 1000]
adb : [-s emulator-5554 shell uiautomator dump]
adb : [-s emulator-5554 shell cat /storage/sdcard/window_dump.xml]
adb : [-s emulator-5554 shell wm size]
adb : [-s emulator-5554 shell input touchscreen swipe 540 1440 540 480 1000]
adb : [-s emulator-5554 shell uiautomator dump]
adb : [-s emulator-5554 shell cat /storage/sdcard/window_dump.xml]
adb : [-s emulator-5554 shell wm size]
adb : [-s emulator-5554 shell input touchscreen swipe 540 1440 540 480 1000]
adb : [-s emulator-5554 shell uiautomator dump]
adb : [-s emulator-5554 shell cat /storage/sdcard/window_dump.xml]
adb : [-s emulator-5554 shell wm size]
adb : [-s emulator-5554 shell input touchscreen swipe 540 1440 540 480 1000]
adb : [-s emulator-5554 shell uiautomator dump]
adb : [-s emulator-5554 shell cat /storage/sdcard/window_dump.xml]
adb : [-s emulator-5554 shell wm size]
adb : [-s emulator-5554 shell input touchscreen swipe 540 1440 540 480 1000]
adb : [-s emulator-5554 shell uiautomator dump]
adb : [-s emulator-5554 shell cat /storage/sdcard/window_dump.xml]
adb : [-s emulator-5554 shell wm size]
adb : [-s emulator-5554 shell input touchscreen swipe 540 1440 540 480 1000]
adb : [-s emulator-5554 shell uiautomator dump]
adb : [-s emulator-5554 shell cat /storage/sdcard/window_dump.xml]
adb : [-s emulator-5554 shell wm size]
adb : [-s emulator-5554 shell input touchscreen swipe 540 1440 540 480 1000]
adb : [-s emulator-5554 shell uiautomator dump]
adb : [-s emulator-5554 shell cat /storage/sdcard/window_dump.xml]
adb : [-s emulator-5554 shell wm size]
adb : [-s emulator-5554 shell input touchscreen swipe 540 1440 540 480 1000]
adb : [-s emulator-5554 shell uiautomator dump]
adb : [-s emulator-5554 shell cat /storage/sdcard/window_dump.xml]
adb : [-s emulator-5554 shell uiautomator dump]
adb : [-s emulator-5554 shell cat /storage/sdcard/window_dump.xml]
adb : [-s emulator-5554 shell input tap 229 1677]

Documentation

Overview

Package goandroid is an automation library for android devices.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Android

type Android struct {
	Device   device.Device      // Raw adb device communication interface
	Input    input.InputManager // Device input interaction interface
	View     view.DeviceView    // Device UI View query interface
	Display  display.Display    // Device display insterface
	Activity activity.Activity  // Device application activity interface
}

Android struct defines an android device. Android device has raw device communication interface via Device struct, device input interaction interface via Input struct, device ui view query interface via View struct, device display information interface via Display struct and device application activity interface via Activity struct. See their respective documentation for list of available mechanisms.

type AndroidManager

type AndroidManager struct {
	Endpoint adbutility.AdbEndpoint // Associated adb endpoint
	Timeout  int                    // Default adb operation timeout in seconds
}

AndroidManager struct defines a android device manager with an associated adb endpoint and adb operation timeout. All devices returned by this android manager will be having this adb operation timeout.

func GetNewAndroidManager

func GetNewAndroidManager(timeout int, adb string) AndroidManager

GetAndroidManager method returns a new AndroidManager instance based on specified adb executable path and adb operation timeout. Please note that adb executable must be present on the specified path. If adb is on system path then just pass "adb". Timeout specified is in seconds and all adb commands will timeout after specified seconds.

func (AndroidManager) GetAttachedAndroidDevices

func (am AndroidManager) GetAttachedAndroidDevices() ([]Android, error)

GetAttachedAndroidDevices method returns list of attached android devices to the system. It returns error if any error occurred wile performing adb operation.

func (AndroidManager) GetNewAndroidDevice

func (am AndroidManager) GetNewAndroidDevice(serial string) Android

GetNewAndroidDevice method returns a new Android device instance based on the specified serial number.

Directories

Path Synopsis
Package activity provides useful methods to determine or handle activity on associated android device.
Package activity provides useful methods to determine or handle activity on associated android device.
Package adbutility provides useful methods to communicate with underlying adb tool.
Package adbutility provides useful methods to communicate with underlying adb tool.
Package device provides some useful methods to operate on an associated android device.
Package device provides some useful methods to operate on an associated android device.
Package input provides a set of useful methods that helps on input based interaction with an associated android device.
Package input provides a set of useful methods that helps on input based interaction with an associated android device.
Package view provides various query and UI operation methods on android UI View.
Package view provides various query and UI operation methods on android UI View.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL