Skip to content

Commit

Permalink
added lambdatest runner
Browse files Browse the repository at this point in the history
  • Loading branch information
Gauravpandeyr committed Nov 21, 2024
1 parent 28e6070 commit 5b5065d
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 6 deletions.
54 changes: 54 additions & 0 deletions packages/patrol/android/src/main/LambdatestPatrolJUnitRunner.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package pl.leancode.patrol;

import android.util.Log;
import pl.leancode.patrol.contracts.PatrolAppServiceClientException;

import java.net.Inet4Address;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.Enumeration;
import java.util.Objects;

public class LambdatestPatrolJUnitRunner extends PatrolJUnitRunner {
@Override
public PatrolAppServiceClient createAppServiceClient() {
// Create client with a default constructor (localhost:8082) by default.
PatrolAppServiceClient client = new PatrolAppServiceClient();
waitForPatrolAppService();

try {
client.listDartTests();

//TODO verify in a project where we use Browserstack
} catch (PatrolAppServiceClientException ex) {
ex.printStackTrace();
// If the client on localhost:8082 fails, let's apply the wokraround
Logger.INSTANCE.i("PatrolAppServiceClientException in createAppServiceClient " + ex.getMessage());
Logger.INSTANCE.i("LOOPBACK: " + getLoopback());
client = new PatrolAppServiceClient(getLoopback());
}

return client;
}

public String getLoopback() {
try {
Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces();
while (interfaces.hasMoreElements()) {
NetworkInterface i = interfaces.nextElement();
Log.d("LOOPBACK", i.getDisplayName());
if (Objects.equals(i.getDisplayName(), "tun0")) {
for (java.net.InterfaceAddress a : i.getInterfaceAddresses()) {
if (a.getAddress() instanceof Inet4Address) {
return a.getAddress().toString().substring(1);
}
}
}

}
} catch (SocketException e) {
}

return null;
}
}
6 changes: 4 additions & 2 deletions packages/patrol/example/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ if (flutterVersionName == null) {

android {
compileSdkVersion 34
ndkVersion flutter.ndkVersion
ndkVersion = "25.1.8937393"

namespace "pl.leancode.patrol.example"

Expand All @@ -46,6 +46,7 @@ android {
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
coreLibraryDesugaringEnabled true
}

kotlinOptions {
Expand All @@ -62,7 +63,7 @@ android {
targetSdkVersion 33
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
testInstrumentationRunner "pl.leancode.patrol.PatrolJUnitRunner"
testInstrumentationRunner "pl.leancode.patrol.LambdatestPatrolJUnitRunner"
testInstrumentationRunnerArguments clearPackageData: "true"
}

Expand All @@ -83,4 +84,5 @@ flutter {

dependencies {
androidTestUtil 'androidx.test:orchestrator:1.4.2'
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:2.0.3'
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import pl.leancode.patrol.PatrolJUnitRunner;
import pl.leancode.patrol.LambdatestPatrolJUnitRunner;


@RunWith(Parameterized.class)
public class MainActivityTest {
@Parameters(name = "{0}")
public static Object[] testCases() {
PatrolJUnitRunner instrumentation = (PatrolJUnitRunner) InstrumentationRegistry.getInstrumentation();
LambdatestPatrolJUnitRunner instrumentation = (LambdatestPatrolJUnitRunner) InstrumentationRegistry.getInstrumentation();
instrumentation.setUp(MainActivity.class);
instrumentation.waitForPatrolAppService();
return instrumentation.listDartTests();
Expand All @@ -25,7 +27,7 @@ public MainActivityTest(String dartTestName) {

@Test
public void runDartTest() {
PatrolJUnitRunner instrumentation = (PatrolJUnitRunner) InstrumentationRegistry.getInstrumentation();
LambdatestPatrolJUnitRunner instrumentation = (LambdatestPatrolJUnitRunner) InstrumentationRegistry.getInstrumentation();
instrumentation.runDartTest(dartTestName);
}
}
2 changes: 1 addition & 1 deletion packages/patrol/example/android/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
org.gradle.jvmargs=-Xmx1536M
org.gradle.jvmargs=-Xmx4g -XX:MaxPermSize=1g -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
android.useAndroidX=true
android.enableJetifier=true
2 changes: 1 addition & 1 deletion packages/patrol/example/android/settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pluginManagement {

plugins {
id "dev.flutter.flutter-plugin-loader"
id "com.android.application" version "8.1.2" apply false
id "com.android.application" version "8.3.2" apply false
id "com.google.gms.google-services" version "4.4.0" apply false
id "org.jetbrains.kotlin.android" version "1.9.20" apply false
}
Expand Down

0 comments on commit 5b5065d

Please sign in to comment.