-
Notifications
You must be signed in to change notification settings - Fork 24.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix and update end to end tests for Android (#23958)
Summary: This PRs makes an attempt at fixing the set up of the Android end to end tests, and the tests themselves. The end goal is to re-enable the tests on CircleCI (see #23561 for more details). The goal of this PR is to the end to end tests to a working state. Better tests can be added at a later point. I changed the tests using the menu button. These tests made something silently crash/hang, after which it was no longer possible to get an element or even get the source. A fix for this needs further investigation. Also, I enabled the tests in the CircleCI config, however CircleCI is currently failing on them with the following error: ``` info Running /opt/android/platform-tools/adb -s emulator-5554 reverse tcp:8081 tcp:8081 error: closed info Could not run adb reverse: Command failed: /opt/android/platform-tools/adb -s emulator-5554 reverse tcp:8081 tcp:8081 info Starting the app on emulator-5554 (/opt/android/platform-tools/adb -s emulator-5554 shell am start -n com.endtoendtest/com.endtoendtest.MainActivity)... Starting: Intent { cmp=com.endtoendtest/.MainActivity } Too long with no output (exceeded 10m0s) ``` Some help here would be appreciated. An alternative is to not enable the tests yet on CircleCI in this PR. [Android] [fixed] - Fix and update end to end tests for Android Pull Request resolved: #23958 Differential Revision: D14502884 Pulled By: hramos fbshipit-source-id: 4316c3fd817451d332e64a10d88389b74a60d3dd
- Loading branch information
1 parent
43d3313
commit bce1e6f
Showing
2 changed files
with
53 additions
and
50 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,15 +11,15 @@ | |
* | ||
* | ||
* To set up: | ||
* - npm install --save-dev appium@1.5.1 [email protected] wd@0.3.11 [email protected] [email protected] | ||
* - npm install --save-dev appium@1.11.1 [email protected] wd@1.11.1 [email protected] [email protected] | ||
* - cp <this file> <to app installation path> | ||
* - keytool -genkey -v -keystore android/keystores/debug.keystore -storepass android -alias androiddebugkey -keypass android -dname "CN=Android Debug,O=Android,C=US | ||
* - keytool -genkey -v -keystore android/app/debug.keystore -storepass android -alias androiddebugkey -keypass android -keyalg RSA -keysize 2048 -validity 10000 -dname "CN=Android Debug,O=Android,C=US" | ||
* | ||
* To run this test: | ||
* - npm start | ||
* - node node_modules/.bin/appium | ||
* - (cd android && ./gradlew :app:copyDownloadableDepsToLibs) | ||
* - buck build android/app | ||
* - react-native run-android | ||
* - node ../node_modules/.bin/_mocha ../android-e2e-test.js | ||
* | ||
* @format | ||
|
@@ -77,7 +77,7 @@ describe('Android Test App', function() { | |
const desired = { | ||
platformName: 'Android', | ||
deviceName: 'Android Emulator', | ||
app: path.resolve('buck-out/gen/android/app/app.apk'), | ||
app: path.resolve('android/app/build/outputs/apk/debug/app-debug.apk'), | ||
}; | ||
|
||
// React Native in dev mode often starts with Red Box "Can't fibd variable __fbBatchedBridge..." | ||
|
@@ -89,12 +89,12 @@ describe('Android Test App', function() { | |
.then( | ||
elem => { | ||
elem.click(); | ||
driver.sleep(2000); | ||
}, | ||
err => { | ||
// ignoring if Reload JS button can't be located | ||
}, | ||
) | ||
.setImplicitWaitTimeout(150000); | ||
); | ||
}); | ||
|
||
after(function() { | ||
|
@@ -104,59 +104,54 @@ describe('Android Test App', function() { | |
return driver.quit(); | ||
}); | ||
|
||
it('should have Hot Module Reloading working', function() { | ||
const androidAppCode = fs.readFileSync('index.js', 'utf-8'); | ||
it('should display new content after a refresh', function() { | ||
const androidAppCode = fs.readFileSync('App.js', 'utf-8'); | ||
let intervalToUpdate; | ||
return ( | ||
driver | ||
.waitForElementByXPath( | ||
'//android.widget.TextView[starts-with(@text, "Welcome to React Native!")]', | ||
) | ||
// http://developer.android.com/reference/android/view/KeyEvent.html#KEYCODE_MENU | ||
.pressDeviceKey(82) | ||
.elementByXPath( | ||
'//android.widget.TextView[starts-with(@text, "Enable Hot Reloading")]', | ||
) | ||
.click() | ||
.waitForElementByXPath( | ||
'//android.widget.TextView[starts-with(@text, "Welcome to React Native!")]', | ||
) | ||
.then(() => { | ||
let iteration = 0; | ||
// CI environment can be quite slow and we can't guarantee that it can consistently motice a file change | ||
// so we change the file every few seconds just in case | ||
intervalToUpdate = setInterval(() => { | ||
fs.writeFileSync( | ||
'index.js', | ||
androidAppCode.replace( | ||
'Welcome to React Native!', | ||
'Welcome to React Native with HMR!' + iteration, | ||
), | ||
'utf-8', | ||
); | ||
}, 3000); | ||
fs.writeFileSync( | ||
'App.js', | ||
androidAppCode.replace( | ||
'Welcome to React Native!', | ||
'Welcome to React Native! Reloaded', | ||
), | ||
'utf-8', | ||
); | ||
}) | ||
.sleep(1000) | ||
// http://developer.android.com/reference/android/view/KeyEvent.html#KEYCODE_MENU | ||
.pressDeviceKey(46) | ||
.pressDeviceKey(46) | ||
.sleep(2000) | ||
.waitForElementByXPath( | ||
'//android.widget.TextView[starts-with(@text, "Welcome to React Native with HMR!")]', | ||
'//android.widget.TextView[starts-with(@text, "Welcome to React Native! Reloaded")]', | ||
) | ||
.finally(() => { | ||
clearInterval(intervalToUpdate); | ||
fs.writeFileSync('index.js', androidAppCode, 'utf-8'); | ||
fs.writeFileSync('App.js', androidAppCode, 'utf-8'); | ||
driver | ||
.pressDeviceKey(46) | ||
.pressDeviceKey(46) | ||
.sleep(2000); | ||
}) | ||
); | ||
}); | ||
|
||
it('should have Debug In Chrome working', function() { | ||
// http://developer.android.com/reference/android/view/KeyEvent.html#KEYCODE_MENU | ||
return driver | ||
.waitForElementByXPath( | ||
'//android.widget.TextView[starts-with(@text, "Welcome to React Native!")]', | ||
) | ||
.pressDeviceKey(82) | ||
.elementByXPath('//android.widget.TextView[starts-with(@text, "Debug")]') | ||
.click() | ||
.waitForElementByXPath( | ||
'//android.widget.TextView[starts-with(@text, "Welcome to React Native!")]', | ||
); | ||
it('should have the menu available', function() { | ||
return ( | ||
driver | ||
.waitForElementByXPath( | ||
'//android.widget.TextView[starts-with(@text, "Welcome to React Native!")]', | ||
) | ||
// http://developer.android.com/reference/android/view/KeyEvent.html#KEYCODE_MENU | ||
.pressDeviceKey(82) | ||
.waitForElementByXPath( | ||
'//android.widget.TextView[starts-with(@text, "Toggle Inspector")]', | ||
) | ||
); | ||
}); | ||
}); |
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 |
---|---|---|
|
@@ -107,7 +107,7 @@ try { | |
tryExecNTimes( | ||
() => | ||
exec( | ||
'yarn add --dev appium@1.5.1 [email protected] wd@0.3.11 [email protected] [email protected]', | ||
'yarn add --dev appium@1.11.1 [email protected] wd@1.11.1 [email protected] [email protected]', | ||
{silent: true}, | ||
).code, | ||
numberOfRetries, | ||
|
@@ -123,17 +123,25 @@ try { | |
echo('Downloading Maven deps'); | ||
exec('./gradlew :app:copyDownloadableDepsToLibs'); | ||
cd('..'); | ||
exec( | ||
'keytool -genkey -v -keystore android/keystores/debug.keystore -storepass android -alias androiddebugkey -keypass android -dname "CN=Android Debug,O=Android,C=US"', | ||
); | ||
|
||
exec('rm android/app/debug.keystore'); | ||
if ( | ||
exec( | ||
'keytool -genkey -v -keystore android/app/debug.keystore -storepass android -alias androiddebugkey -keypass android -keyalg RSA -keysize 2048 -validity 10000 -dname "CN=Android Debug,O=Android,C=US"', | ||
).code | ||
) { | ||
echo('Key could not be generated'); | ||
exitCode = 1; | ||
throw Error(exitCode); | ||
} | ||
|
||
echo(`Starting appium server, ${APPIUM_PID}`); | ||
const appiumProcess = spawn('node', ['./node_modules/.bin/appium']); | ||
APPIUM_PID = appiumProcess.pid; | ||
|
||
echo('Building the app'); | ||
if (exec('buck build android/app').code) { | ||
echo('could not execute Buck build, is it installed and in PATH?'); | ||
if (exec('react-native run-android').code) { | ||
echo('could not execute react-native run-android'); | ||
exitCode = 1; | ||
throw Error(exitCode); | ||
} | ||
|