Skip to content

Commit

Permalink
test: [android] run tests on the first emulator in your list (#8305)
Browse files Browse the repository at this point in the history
## **Description**

The objective of this pull request is to enable engineers to execute
tests on emulators that are created on their local machines, instead of
relying on a predefined emulator. This enhancement aims to decrease the
cognitive load involved in running end-to-end (e2e) tests locally.

## **Related issues**

Fixes:

## **Manual testing steps**

1. Go to this page...
2.
3.

## **Screenshots/Recordings**

<!-- If applicable, add screenshots and/or recordings to visualize the
before and after of your change. -->

### **Before**

<!-- [screenshots/recordings] -->

### **After**
Smoke test run:
https://app.bitrise.io/app/be69d4368ee7e86d/pipelines/296e5072-9e8e-479e-9807-ba833640cf2b
Regression test run: 

## **Pre-merge author checklist**

- [ ] I’ve followed [MetaMask Coding
Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/CODING_GUIDELINES.md).
- [ ] I've clearly explained what problem this PR is solving and how it
is solved.
- [ ] I've linked related issues
- [ ] I've included manual testing steps
- [ ] I've included screenshots/recordings if applicable
- [ ] I’ve included tests if applicable
- [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [ ] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.
- [ ] I’ve properly set the pull request status:
  - [ ] In case it's not yet "ready for review", I've set it to "draft".
- [ ] In case it's "ready for review", I've changed it from "draft" to
"non-draft".

## **Pre-merge reviewer checklist**

- [ ] I've manually tested the PR (e.g. pull and build branch, run the
app, test code being changed).
- [ ] I confirm that this PR addresses all acceptance criteria described
in the ticket it closes and includes the necessary testing evidence such
as recordings and or screenshots.
  • Loading branch information
cortisiko authored Jan 24, 2024
1 parent 01c4a1a commit 4f5b0ef
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 25 deletions.
45 changes: 24 additions & 21 deletions .detoxrc.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,24 @@
/** @type {Detox.DetoxConfig} */
const { execSync } = require('child_process');

const getAvailableAVDs = (() => {
try {
// Run the command to list available AVDs
const outputList = execSync("emulator -list-avds").toString();

// Parse the output and return an array of AVD names
const avdNames = outputList.trim().split("\n");

// return avdNames
return avdNames;
} catch (error) {
console.error(
"Revisit the command to get the error list. It seems incorrect:",
error.message,
);
return [];
}
})();

module.exports = {
testRunner: {
args: {
Expand Down Expand Up @@ -33,22 +53,16 @@ module.exports = {
device: 'ios.simulator',
app: 'ios.release',
},
// because e2e run on debug mode in bitrise
'android.emu.bitrise.debug': {
device: 'android.bitrise.emulator',
app: 'android.bitrise.debug',
},

'android.emu.debug': {
device: 'android.emulator',
app: 'android.debug',
},
'android.emu.release': {
device: 'android.bitrise.emulator',
device: 'android.emulator',
app: 'android.release',
},
'android.emu.release.qa': {
device: 'android.bitrise.emulator',
device: 'android.emulator',
app: 'android.qa',
},
},
Expand All @@ -59,16 +73,10 @@ module.exports = {
type: 'iPhone 13 Pro',
},
},
'android.bitrise.emulator': {
type: 'android.emulator',
device: {
avdName: 'emulator',
},
},
'android.emulator': {
type: 'android.emulator',
device: {
avdName: 'Pixel_5_API_30',
avdName: getAvailableAVDs[0],
},
},
},
Expand All @@ -84,11 +92,6 @@ module.exports = {
'ios/build/Build/Products/Release-iphonesimulator/MetaMask.app',
build: "METAMASK_BUILD_TYPE='main' METAMASK_ENVIRONMENT='production' yarn build:ios:release:e2e",
},
'android.bitrise.debug': {
type: 'android.apk',
binaryPath: 'android/app/build/outputs/apk/prod/debug/app-prod-debug.apk',
build: 'yarn start:android:e2e',
},
'android.debug': {
type: 'android.apk',
binaryPath: 'android/app/build/outputs/apk/prod/debug/app-prod-debug.apk',
Expand Down
4 changes: 2 additions & 2 deletions e2e/pages/Onboarding/MetaMetricsOptInView.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ class MetaMetricsOptIn {
}

async tapAgreeButton() {
await Gestures.swipe(this.optInMetricsContent, 'up', 'slow', 0.6);
await Gestures.swipe(this.optInMetricsContent, 'up', 'fast', 0.9);
await Gestures.waitAndTap(this.iAgreeButton);
}

async tapNoThanksButton() {
await Gestures.swipe(this.optInMetricsContent, 'up', 'slow', 0.6);
await Gestures.swipe(this.optInMetricsContent, 'up', 'fast', 0.9);
await Gestures.waitAndTap(this.noThanksButton);
}
}
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@
"test:e2e:ios:bitrise:run": "IS_TEST='true' detox test -c ios.sim.debug",
"test:e2e:ios:debug:single": "detox test -c ios.sim.debug",
"test:e2e:android:debug": "IS_TEST='true' detox build -c android.emu.debug && detox test -c android.emu.debug",
"test:e2e:android:bitrise:build": "IS_TEST='true' detox build -c android.emu.bitrise.debug",
"test:e2e:android:bitrise:run": "IS_TEST='true' detox test -c android.emu.bitrise.debug --headless",
"test:e2e:android:bitrise:build": "IS_TEST='true' detox build -c android.emu.debug",
"test:e2e:android:bitrise:run": "IS_TEST='true' detox test -c android.emu.debug --headless",
"test:e2e:android:debug:single": "detox test -c android.emu.debug",
"test:e2e:android": "detox build -c android.emu.release && detox test -c android.emu.release --record-videos failing",
"test:e2e:android:qa": "detox build -c android.emu.release.qa && detox test -c android.emu.release.qa --record-videos failing",
Expand Down

0 comments on commit 4f5b0ef

Please sign in to comment.