Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Status
colourGreen
titleUP TO DATE

Table of Contents

API Documentation

...

You can include Meter Android API in your automated tests (UI Automator or Espresso for example) so that you can measure your application without modifying the code of your application.

Note : You can also include it in an android application directly if the goal is not to measure this application (Prefer not using this way)

API reference

init

Code Block
languagejava
public void init(Context context)

Init the probe with the Context.

  • context: Context of your Instumentation or Android's application.

init

Code Block
languagejava
public void init(Context context, String[] packageName, int[] lstPid, String appName, String version, String url, String privateToken, boolean online)

Sets up the probe with all the needed data.

  • context: Context of your Instumentation or Android's application.
  • packageName: Package name of the application to monitor (for example com.android.chrome). If it is blank (""), the probe does not monitor any particular process.
  • lstPid: In case of system applications, the probe can't get the PID by package name so you need to precise the PID list matching the package name. (Optional)
  • appName: GREENSPECTOR's application name.
  • version: GREENSPECTOR's application version.
  • url: GREENSPECTOR's server URL. For SaaS: https://api.greenspector.com/api. For on premises servers, replace api.greenspector.com by your URL.
  • privateToken: Your private token.
  • online: Set false to write the results on your device. Use this case if you launch your automated tests (UI Automator or Espresso for example) with the Test Runner or the Power Test Cloud/Bench.  Set true to send the measures immediately to your GREENSPECTOR server. Use this case if you launch your tests with Android Studio (i.e. you do not use the Test Runner or the Power Test Cloud / Bench).

setUpMeasure (Deprecated)

Code Block
languagejava
public void setUpMeasure(Context context, String[] packageName, int[] lstPid, String AppnameappName, String Versionversion, String URLurl, String privateToken, int timeout, int interval, boolean online)

Sets up the measure probe with all the needed data. This method is deprecated.- Context: We pass the context of the

  • context: Context of your Instumentation or Android's application.

...

  • packageName: Package name of the application to

...

  • monitor (for example com.android.chrome

...

  • ). If it is blank (""), the probe does not

...

  • monitor any particular process.

...

  • lstPid:

...

  • In case of system

...

  • applications, the probe can't get the

...

  • PID by package name so you need to precise the PID list matching the package name

...

  • . (Optional)

...

  • appName: GREENSPECTOR's application name.

...

  • version:

...

  •  GREENSPECTOR's application version.

...

  • url: GREENSPECTOR's server URL. For

...

...

...

  • by your URL.

...

  • privateToken:

...

  • Your private token.

...

  • timeout: Test time in seconds. The measure stops when the measure time reaches this timeout. deprecated

...

  • interval: Measure interval in milliseconds. The interval must be greater than 100 ms or can be 0

...

  • if you do not want to set it. deprecated
  • online: Set false to write the results on your device. Use this case if you launch your automated tests (UI Automator or Espresso for example) with the Test Runner or the Power Test Cloud/Bench.  Set true to send the measures immediately to your GREENSPECTOR server. Use this case if you launch your tests with Android Studio (i.e. you do not use the Test Runner or the Power Test Cloud / Bench).

startMeasure

Code Block
languagejava
public boolean startMeasure()

stopMeasure

Starts the measure.Starts the measure.

Returns a boolean indicating whether the measure was successfully started or not.

stopMeasure

Code Block
languagejava
public boolean stopMeasure(String testName)

Stops the measure and write writes the results on the phone device or send it sends them to the your GREENSPECTOR Server.-

  • testName: Name of the current test.

setCoverageFile

Code Block
languagejava
setCoverageFile(String fileName) (Optional)

Sets the path to coverage file.

If never set it, the default value is: /mnt/sdcard/greenspector/coverages/[Application Package]/[Test Name]-coverage.ec

setMetadataFile

Returns a boolean indicating whether the measure was successfully stopped or not.

setProxy (optional)

Code Block
languagejava
setMetadataFile(String fileName) (Optional)

Sets the path to metadata file.

If never set it, the default value is: /mnt/sdcard/greenspector/coverages/[Application Package]/coverage.em

setProxy

Code Block
languagejava
public void setProxy(String url, int port) (Optional)

Sets the proxy URL and port

If never set it, no proxy will be used.

Code Block
languagejava

public void setProxy(String url, int port, String login, String password) (Optional)

Sets the proxy URL , and port and authentication informations.

If never set it, no proxy will be used.

cpt_test

Code Block
languagejava
public int cpt_test

Sends Use this counter to set the number of the completed tests to the probe. Enables the number of tests identification and the calculation of standardized metricsiterations (default: 1 iteration). This counter must be uptaded before calling the method stopMeasure() to be taken into account.

If you set a number of iterations for your test case, measures and data displayed on GREENSPECTOR Web Interface will refer to the mean value for one iteration.

Usage

Example of a Test Instrumentation

Code Block
languagejava
titleInstrumentationTestCase.java
package com.greenspector.sample.BasicExample;

import android.content.Context;
import android.test.InstrumentationTestCase;

import android.support.test.InstrumentationRegistry;

import com.greenspector.probe.android.interfaces.Api;

public class GreenspectorBasicExample extends InstrumentationTestCase {

	//** Package to measure **/
	private static final String BASIC_SAMPLE_PACKAGE = "com.android.chrome";

	/** Probe configuration **/
	private static final String APPLICATION = "TestApplication";
	private static final String VERSION = "1.0.2";
	private static final String URL = "https://my-instance.greenspector.com/api";
	private static final String PRIVATETOKEN = "123456789AZERTY";
private static final int TIMEOUT = 180;
private static final int INTERVAL = 200;
	private static final boolean ONLINE = true;

	private Api gsptppgsptApi;
	
	public void testBasicExample() {
gsptpp		gsptApi = new Api();
gsptpp		gsptApi.setUpMeasureinit(getInstrumentation().getTargetContext(), new String[]{BASIC_SAMPLE_PACKAGE}, null, APPLICATION, VERSION, URL, PRIVATETOKEN, TIMEOUT, INTERVAL, ONLINE);
gsptpp		gsptApi.startMeasure();

		try {
			Thread.sleep(10000);
		} catch (InterruptedException e) {
gsptpp			gsptApi.stopMeasure("test_Idle_Failed");
			return;
		}

gsptpp		gsptApi.stopMeasure("test_Idle");
	}
}

Usage with

...

Android Studio 

If you launch your automated tests (UI Automator or Espresso for example) with Android Studio, if you have set all parameters, especially online to true, the measure is sent to your instance. Use this method :

Code Block
languagejava
public void init(Context context, String[] packageName, int[] lstPid, String appName, String version, String url, String privateToken, boolean online)

Usage with GREENSPECTOR Test Runnner or Power Test Cloud/Bench

If you launch your automated tests (UI Automator or Espresso for example) with the Test Runner or the Power Test Cloud/Bench, the probe configuration is not important. All fields are not taken into account because they are directly handled by Test Runner Or Test Bench job parameters.

Use this method.

Code Block
languagejava
public void init(Context context)

or this method (all arguments except context are not taken into account). So you do not need to change your code if you launch with Test Runner or with Android Studio

Code Block
languagejava
public void init(Context context, String[] packageName, int[] lstPid, String appName, String version, String url, String privateToken, boolean online)


Related articles


Filter by label (Content by label)
showLabelsfalse
max5
spacescom.atlassian.confluence.content.render.xhtml.model.resource.identifiers.SpaceResourceIdentifier@185bfa9a
showSpacefalse
sortmodified
reversetrue
typepage
cqllabel = "probeapi" and type = "page" and space = "DOCUMENTATION"
labelskb-how-to-article