diff --git a/packages/patrol/android/src/main/LambdatestPatrolJUnitRunner.java b/packages/patrol/android/src/main/LambdatestPatrolJUnitRunner.java new file mode 100644 index 000000000..8ea819599 --- /dev/null +++ b/packages/patrol/android/src/main/LambdatestPatrolJUnitRunner.java @@ -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 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; + } +} diff --git a/packages/patrol/example/android/app/build.gradle b/packages/patrol/example/android/app/build.gradle index f5de74ea7..e363c0063 100644 --- a/packages/patrol/example/android/app/build.gradle +++ b/packages/patrol/example/android/app/build.gradle @@ -25,7 +25,7 @@ if (flutterVersionName == null) { android { compileSdkVersion 34 - ndkVersion flutter.ndkVersion + ndkVersion = "25.1.8937393" namespace "pl.leancode.patrol.example" @@ -46,6 +46,7 @@ android { compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 + coreLibraryDesugaringEnabled true } kotlinOptions { @@ -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" } @@ -83,4 +84,5 @@ flutter { dependencies { androidTestUtil 'androidx.test:orchestrator:1.4.2' + coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:2.0.3' } diff --git a/packages/patrol/example/android/app/src/androidTest/java/pl/leancode/patrol/example/MainActivityTest.java b/packages/patrol/example/android/app/src/androidTest/java/pl/leancode/patrol/example/MainActivityTest.java index 675e46464..90f22cf97 100644 --- a/packages/patrol/example/android/app/src/androidTest/java/pl/leancode/patrol/example/MainActivityTest.java +++ b/packages/patrol/example/android/app/src/androidTest/java/pl/leancode/patrol/example/MainActivityTest.java @@ -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(); @@ -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); } } diff --git a/packages/patrol/example/android/gradle.properties b/packages/patrol/example/android/gradle.properties index 94adc3a3f..7ae58a921 100644 --- a/packages/patrol/example/android/gradle.properties +++ b/packages/patrol/example/android/gradle.properties @@ -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 diff --git a/packages/patrol/example/android/settings.gradle b/packages/patrol/example/android/settings.gradle index f08a60d92..8739f2403 100644 --- a/packages/patrol/example/android/settings.gradle +++ b/packages/patrol/example/android/settings.gradle @@ -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 }