Status | ||||
---|---|---|---|---|
|
Table of Contents |
---|
API
...
reference
setUpMeasure
Code Block | ||
---|---|---|
| ||
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.- Context: We pass the context of the
context
: Context of your 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.
...
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.
...
online
:
...
- Set
false
...
- to write the results on your device, set
true
...
- to send the measures immediately to your GREENSPECTOR server.
startMeasure
Code Block | ||
---|---|---|
| ||
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 | ||
---|---|---|
| ||
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 | ||
---|---|---|
| ||
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 | ||
---|---|---|
| ||
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 | ||
---|---|---|
| ||
setProxypublic void setProxy(String url, int port) (Optional) |
Sets the proxy URL and port
If never set it, no proxy will be used.
Code Block | ||
---|---|---|
| ||
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 | ||
---|---|---|
| ||
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
Code Block | ||||
---|---|---|---|---|
| ||||
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.setUpMeasure(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
...
GREENSPECTOR Test Runnner or Power Test Bench/Cloud
The probe configuration is slightly different in the case you integrate GREENSPECTOR Meter Android API in your automated tests (UI Automator or Espresso for example) that you launch with the Test Runner or the Power Test Bench/Cloud.
- Some fields will be directly handled by the Test Runner (or the Power Test Bench/Cloud). You can leave empty string values for the following fields:
application
,version
,url
andprivateToken
. - Set
online
tofalse
because the Test Runner (or the Power Test Bench/Cloud) will read the results on the device.
As an example, the previous code would be updated in this way:
Code Block | ||||
---|---|---|---|---|
| ||||
//...
/** 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;
//...
|
Related articles
Filter by label (Content by label) | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|