Web Quality Test¶
The WebQualityTest
is designed to measure the performance and quality of loading and interacting with web pages. It utilizes a WebView to render web content and collect relevant metrics. For a practical implementation, refer to the WebTestActivity.java
file in the demo application.
Warning
Ensure that client registration is successfully completed before attempting to instantiate or start the WebQualityTest
builder. Failure to do so will result in an exception. Your application should verify the registration status prior to initiating any test.
Starting the Test¶
To begin a web quality test, you'll use the WebQualityTest.Builder
. This builder requires the application context and the URL of the web page to be tested. You also need to attach a FrameLayout
to the builder where the WebView will be displayed, and set a result listener.
Here's an example of how to configure and start the WebQualityTest
:
WebQualityTest mQTest;
FrameLayout mFrame; // Initialize this FrameLayout, e.g., findViewById(R.id.test_web_view);
String testUrl = "https://www.google.com"; // Example URL
// Ensure mFrame is initialized from your layout
mFrame = findViewById(R.id.test_web_view);
WebQualityTest.Builder builder = new WebQualityTest.Builder(
this, // Activity context
Uri.parse(testUrl)
)
.setWebQualityTestResultListener(this) // Implement WebQualityTestResultListener in your Activity
.attachToView(mFrame); // WebView will be added to this FrameLayout
try {
mQTest = builder.build();
mQTest.start();
} catch (Exception e) {
Log.e(TAG, "Test start failed", e);
// Handle exception
}
Receiving Test Results¶
To receive the outcomes of the test, your activity or class must implement the WebQualityTestResultListener
interface. This interface includes methods for handling successful results, errors, and state changes.
Test Success¶
When the test completes successfully, the onTestResult
method is called:
@Override
public void onTestResult(@NonNull Map<String, Object> result) {
Log.i(TAG, "Test result received: " + result);
// Convert the result to a JSON string for display or storage
Gson gson = new GsonBuilder().setPrettyPrinting().create();
String resultJson = gson.toJson(result);
// Process or display the resultJson
}
The results correspond to the measurement data, so please refer to that page for more information on the values.
Test Errors¶
If an error occurs during the test, the onTestError
method is invoked:
@Override
public void onTestError(@NonNull QualityTestException error) {
// Handle the error, e.g., display a message to the user
Log.e(TAG, "Test error: " + error.getMessage(), error);
}
Test State Changes¶
You can monitor the lifecycle of the test by implementing the onTestStateChanged
method from the WebQualityTestResultListener
interface:
@Override
public void onTestStateChanged(QualityTestState state) {
Log.d(TAG, "Test state: " + state);
}
Instrumented Usage¶
The WebQualityTest
can be initiated via adb
by passing intent extras to the demo WebTestActivity
. This is useful for automated testing scenarios.
adb shell am start -n "com.aveq.qualitytestlibdemo/.WebTestActivity" \
--ez autoRunTest true \
--es url "https://www.example.com"
--ez autoRunTest true
: Automatically starts the test when the activity launches.--es url "https://www.example.com"
: Specifies the URL to test.
Note that these intent parameters are directly passed to the web quality test; check the demo app source code for more info on how they are handled.
We provide a shell script to run the quality test using the above call, which extracts the test results directly from the Android log. See ./run_web_quality_test.sh
for more info.
Background Execution¶
Note
Currently, background execution is not supported for WebQualityTest
. Tests require the application to be visible on screen. We are working on enabling this feature in a future update.