Network Logs and Monitoring
Appelium supports rich network log capturing for bug reports and monitoring.
Structured request and response logs in bug reports include information like:
- Headers
- Complete payloads
- Response status codes
- Connection type
- Request duration
and via network monitoring you get access to statistics like:
- Appdex
- Request duration (avg, p90, p95, p99)
- DNS lookup duration
- Connection duration
- Response status code
- Payload size information
OkHttp
Appelium offers a package with OkHttp Interceptors and EventListeners for a seamless integration of network monitoring.
The package can be integrated like this:
implementation ('com.appelium:okhttp-v4:5.1.0:release@aar') {
transitive = true
}
Usage
Depending on your integration goal, you may want to integrate only AppeliumOkhttpEventListener or to enrich the data with AppeliumOkhttpInterceptor. We will cover the differences here.
AppeliumOkhttpEventListener
This class is responsible for capturing all network requests statistics for network monitoring purposes. It enables capture of:
- Request duration (avg, p90, p95, p99)
- DNS lookup duration
- Connection duration
- Response status code
- Payload size information
val okHttpClient = OkHttpClient.Builder()
.eventListenerFactory(AppeliumOkhttpEventListener.Factory())
.build()
Note
It is important to add AppeliumOkhttpEventListener via .Factory(), so that a new instance is created for every requests.
AppeliumOkhttpInterceptor
This class is used in addition to the AppeliumOkhttpEventListener in order to enable full capture of request and response payloads and headers for bug reporting purposes.
val okHttpClient = OkHttpClient.Builder()
.addInterceptor(AppeliumOkhttpInterceptor())
.build()
If your client uses a CookieJar, pass it to AppeliumOkhttpInterceptor so that cookies injected by OkHttp at send time are visible in the captured request log:
val cookieJar: CookieJar = /* your CookieJar */
val okHttpClient = OkHttpClient.Builder()
.cookieJar(cookieJar)
.addInterceptor(AppeliumOkhttpInterceptor(cookieJar = cookieJar))
.build()
Note
If you only wish to enable network monitoring for your app, you only need to integrate AppeliumOkhttpEventListener.
HttpUrlConnection
To log native network requests, use AppeliumFeedback.Log.n with the HttpURLConnection, requestBody and responseBody:
val connection: HttpsURLConnection = url.openConnection() as HttpsURLConnection
AppeliumFeedback.Log.n(connection = connection, requestBody = requestBody, responseBody = responseBody)