Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix and update end to end tests for Android #23958

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 39 additions & 44 deletions scripts/android-e2e-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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..."
Expand All @@ -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() {
Expand All @@ -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")]',
)
);
});
});
20 changes: 14 additions & 6 deletions scripts/run-ci-e2e-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);
}
Expand Down