Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 8 Next »

UP TO DATE

API Documentation

setUpMeasure

setUpMeasure(Context context, String[] packageName, int[] lstPid, String Appname, String Version, String URL, String privateToken, int timeout, int interval, boolean online)


Sets up the measure with all the needed data.

- Context: We pass the context of the application.
- PackageName: Package name of the application to survey. For example, "com.android.chrome". If it is blank (""), the probe does not survey any particular process.
- lstPid: (Optional) In case of system application, the probe can't get the pid by package name so you need to precise the PID list matching the package name list.
- Appname: GREENSPECTOR's application name
- Version: Current application's version
- URL: GREENSPECTOR's server URL. For saas : https://api.greenspector.com/api. For on premises server, replace api.greenspector.com. by your URL
- privateToken: User's private token
- timeout: Test time in seconds. The measure stops when the measure time reaches timeout.
- interval: Measure interval in milliseconds. The interval must be greater than 100 ms or be 0 for not setting the interval.
- online: set false for recording the measures in phones, set true for sending it immediately to server.

startMeasure

startMeasure()

stopMeasure

Starts the measure.

stopMeasure(String testName)

Stops the measure and write the results on the phone or send it to the GREENSPECTOR Server.

- testName: Name of the current test.

setCoverageFile

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

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

setProxy(String url, int port) (Optional)

Sets the proxy URL and port

If never set it, no proxy will be used.

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


Sets the proxy URL, port and authentication informations

If never set it, no proxy will be used.

cpt_test

int cpt_test

Sends the number of the completed tests to the probe. Enables the number of tests identification and the calculation of standardized metrics.

Usage

Example

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 gsptpp;

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

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

gsptpp.stopMeasure("test_Idle");
}
}

Usage with Greenspector Testrunnner

You can also use the Greenspector Meter Android API in continuous integration with the Testrunner. To do so, you have to setup your Android Espresso or UIAutomator tests with the Greenspector Probe just like in the previous section with little changes.
Indeed, you only need to initialize the *BASIC_SAMPLE_PACKAGE* and leave default values in the *Probe configuration* of the code sample above and the rest will be handled by the Testrunner.

Related articles


  • No labels