-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enhance Android E2E workflow with Test Butler integration and configu…
…ration updates
- Loading branch information
Showing
10 changed files
with
135 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
...app/src/androidTest/java/com/iterable.reactnativesdk.example/DetoxTestAppJUnitRunner.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package iterable.reactnativesdk.example; | ||
|
||
import android.os.Bundle; | ||
|
||
import com.linkedin.android.testbutler.TestButler; | ||
|
||
import androidx.test.runner.AndroidJUnitRunner; | ||
|
||
public class DetoxTestAppJUnitRunner extends AndroidJUnitRunner { | ||
@Override | ||
public void onStart() { | ||
TestButler.setup(getTargetContext()); | ||
super.onStart(); | ||
} | ||
|
||
@Override | ||
public void finish(int resultCode, Bundle results) { | ||
TestButler.teardown(getTargetContext()); | ||
super.finish(resultCode, results); | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
...android/app/src/androidTest/java/com/iterable.reactnativesdk.example/TestButlerProbe.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package iterable.reactnativesdk.example; | ||
|
||
import android.content.pm.PackageManager; | ||
import android.util.Log; | ||
import android.view.Surface; | ||
|
||
import com.linkedin.android.testbutler.TestButler; | ||
|
||
import androidx.test.platform.app.InstrumentationRegistry; | ||
|
||
class TestButlerProbe { | ||
|
||
private static final String LOG_TAG = TestButlerProbe.class.getSimpleName(); | ||
private static final String TEST_BUTLER_PACKAGE_NAME = "com.linkedin.android.testbutler"; | ||
|
||
private TestButlerProbe() { | ||
} | ||
|
||
static void assertReadyIfInstalled() { | ||
Log.i(LOG_TAG, "Test butler service verification started..."); | ||
|
||
if (!isTestButlerServiceInstalled()) { | ||
Log.w(LOG_TAG, "Test butler not installed on device - skipping verification"); | ||
return; | ||
} | ||
|
||
assertTestButlerServiceReady(); | ||
Log.i(LOG_TAG, "Test butler service is up and running!"); | ||
} | ||
|
||
static private boolean isTestButlerServiceInstalled() { | ||
try { | ||
PackageManager pm = InstrumentationRegistry.getInstrumentation().getTargetContext().getPackageManager(); | ||
pm.getPackageInfo(TEST_BUTLER_PACKAGE_NAME, 0); | ||
return true; | ||
} catch (PackageManager.NameNotFoundException e) { | ||
return false; | ||
} | ||
} | ||
|
||
static private void assertTestButlerServiceReady() { | ||
try { | ||
// This has no effect if test-butler is running. However, if it is not, then unlike TestButler.setup(), it would hard-fail. | ||
TestButler.setRotation(Surface.ROTATION_0); | ||
} catch (Exception e) { | ||
throw new RuntimeException("Test butler service is NOT ready!", e); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { execSync } from 'child_process'; | ||
|
||
import { pathExists, ensureDir } from 'fs-extra'; | ||
|
||
import { resolveConfig } from 'detox/internals'; | ||
import { globalSetup } from 'detox/runners/jest'; | ||
|
||
export default async function customGlobalSetup() { | ||
const config = await resolveConfig(); | ||
if (config.device.type === 'android.emulator') { | ||
await downloadTestButlerAPK(); | ||
} | ||
|
||
await globalSetup(); | ||
} | ||
|
||
async function downloadTestButlerAPK() { | ||
const version = '2.2.1'; | ||
const artifactUrl = `https://repo1.maven.org/maven2/com/linkedin/testbutler/test-butler-app/${version}/test-butler-app-${version}.apk`; | ||
const filePath = `cache/test-butler-app.apk`; | ||
|
||
await ensureDir('cache'); | ||
if (!(await pathExists(filePath))) { | ||
console.log(`\nDownloading Test-Butler APK v${version}...`); | ||
execSync(`curl -f -o ${filePath} ${artifactUrl}`); | ||
} | ||
} | ||
|
||
module.exports = customGlobalSetup; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { device } from 'detox'; | ||
|
||
// eslint-disable-next-line no-undef | ||
beforeAll(async () => { | ||
await device.launchApp({ | ||
/** | ||
* Uncomment the following lines to enable verbose logging of | ||
* synchronization issues. | ||
* See: https://wix.github.io/Detox/docs/next/troubleshooting/synchronization | ||
*/ | ||
// launchArgs: { | ||
// DTXEnableVerboseSyncSystem: 'YES', | ||
// DTXEnableVerboseSyncResources: 'YES', | ||
// }, | ||
newInstance: true, | ||
}); | ||
}); |