### Add OkReplayInterceptor to OkHttpClient Source: https://github.com/airbnb/okreplay/blob/master/readme.md Create an OkReplayInterceptor and add it to an OkHttpClient.Builder. The interceptor is inactive by default until explicitly started. ```java OkReplayInterceptor okReplayInterceptor = new OkReplayInterceptor(); OkHttpClient client = new OkHttpClient.Builder() .addInterceptor(okReplayInterceptor) .build() ``` -------------------------------- ### Gradle plugin integration in build.gradle Source: https://github.com/airbnb/okreplay/blob/master/readme.md Add the OkReplay Gradle plugin by declaring the snapshot repository and classpath dependency, then apply the plugin. After applying, the tasks clearDebugOkReplayTapes and pullDebugOkReplayTapes become available. ```groovy buildscript { repositories { maven { url 'https://oss.sonatype.org/content/repositories/snapshots/' } } dependencies { classpath 'com.airbnb.okreplay:gradle-plugin:1.5.0' } } apply plugin: 'okreplay' ``` -------------------------------- ### Espresso integration with OkReplayConfig and OkReplayRuleChain Source: https://github.com/airbnb/okreplay/blob/master/readme.md Configure OkReplay for an Android instrumentation test using ActivityTestRule, OkReplayConfig, and OkReplayRuleChain. The default mode is READ_WRITE or READ_ONLY, and sslEnabled(true) is set. Remove the @Rule annotation from ActivityTestRule if present. ```java private final ActivityTestRule activityTestRule = new ActivityTestRule<>(MainActivity.class); private final OkReplayConfig configuration = new OkReplayConfig.Builder() .tapeRoot(new AndroidTapeRoot(getContext(), getClass())) .defaultMode(TapeMode.READ_WRITE) // or TapeMode.READ_ONLY .sslEnabled(true) .interceptor(okReplayInterceptor)) .build(); @Rule public final TestRule testRule = new OkReplayRuleChain(configuration, activityTestRule).get(); @Test @OkReplay public void testFooBar() { // write your test as usual... } ``` -------------------------------- ### Maven dependency for OkReplay Source: https://github.com/airbnb/okreplay/blob/master/readme.md Declare the OkReplay library as a Maven dependency with groupId com.airbnb.okreplay, artifactId okreplay, and version 1.5.0. ```xml com.airbnb.okreplay okreplay 1.5.0 ``` -------------------------------- ### Gradle tasks output after applying plugin Source: https://github.com/airbnb/okreplay/blob/master/readme.md Output of ./gradlew tasks showing the two OkReplay tasks added by the plugin: clearDebugOkReplayTapes and pullDebugOkReplayTapes. ```text clearDebugOkReplayTapes - Remove OkReplay tapes from the device pullDebugOkReplayTapes - Pull OkReplay tapes from the device ``` -------------------------------- ### Gradle dependencies for OkReplay Source: https://github.com/airbnb/okreplay/blob/master/readme.md Add OkReplay dependencies for debug, release, and androidTest configurations. The release variant uses the noop artifact to disable recording. ```groovy debugImplementation 'com.airbnb.okreplay:okreplay:1.5.0' releaseImplementation 'com.airbnb.okreplay:noop:1.5.0' androidTestImplementation 'com.airbnb.okreplay:espresso:1.5.0' ``` -------------------------------- ### Apache License 2.0 text Source: https://github.com/airbnb/okreplay/blob/master/readme.md The Apache License, Version 2.0 license text included in the project's README. ```text Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ```