Status |
---|
colour | Green |
---|
title | UP TO DATE |
---|
|
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 |
---|
|
public void init(Context context) |
Init the probe with the Context.
context
: Context of your Instumentation or Android's application.
init
Code Block |
---|
|
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 |
---|
|
public void setUpMeasure(Context context, String[] packageName, int[] lstPid, String appName, String version, String url, String privateToken, int timeout, int interval, boolean online) |
Sets up the probe with all the needed data. This method is deprecated.
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.timeout
: Test time in seconds. The measure stops when the measure time reaches this timeout. deprecatedinterval
: Measure interval in milliseconds. The interval must be greater than 100 ms or can be 0 if you do not want to set it. deprecatedonline
: 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).
...
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 |
---|
language | java |
---|
title | InstrumentationTestCase.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 gsptApi;
public void testBasicExample() {
gsptApi = new Api();
gsptApi.setUpMeasureinit(getInstrumentation().getTargetContext(), new String[]{BASIC_SAMPLE_PACKAGE}, null, APPLICATION, VERSION, URL, PRIVATETOKEN, TIMEOUT, INTERVAL, ONLINE);
gsptApi.startMeasure();
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
gsptApi.stopMeasure("test_Idle_Failed");
return;
}
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 |
---|
|
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
The probe configuration is slightly different in the case you integrate GREENSPECTOR Meter Android API in your If you launch your automated tests (UI Automator or Espresso for example) that you launch 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
...
As an example, the previous code would be updated in this way:Or Test Bench job parameters.
Use this method.
Code Block |
---|
|
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 |
---|
language | java |
---|
title | InstrumentationTestCase.java |
---|
|
//...
/** Package to measure **/
private static final String BASIC_SAMPLE_PACKAGE = "com.android.chrome";
/** Probe configuration **/
private static final String APPLICATION = "";
private static final String VERSION = "";
private static final String URL = "";
private static final String PRIVATETOKEN = "";
private static final int TIMEOUT = 180;
private static final int INTERVAL = 200;
private static final boolean ONLINE = false;
private Api gsptApi;
//...
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) |
---|
showLabels | false |
---|
max | 5 |
---|
spaces | com.atlassian.confluence.content.render.xhtml.model.resource.identifiers.SpaceResourceIdentifier@185bfa9a |
---|
showSpace | false |
---|
sort | modified |
---|
reverse | true |
---|
type | page |
---|
cql | label = "probeapi" and type = "page" and space = "DOCUMENTATION" |
---|
labels | kb-how-to-article |
---|
|