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

Introduce restricted support in RN .58+ for Android #1416

Closed
wants to merge 3 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
4 changes: 2 additions & 2 deletions detox/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ buildscript {
ext.isOfficialDetoxLib = true
ext.kotlinVersion = '1.3.0'
ext.detoxKotlinVerion = ext.kotlinVersion
ext.buildToolsVersion = '27.0.3'
ext.dokkaVersion = '0.9.18'
ext.buildToolsVersion = '28.0.3'

repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.4'
classpath 'com.android.tools.build:gradle:3.3.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
classpath "org.jetbrains.dokka:dokka-gradle-plugin:$dokkaVersion"
}
Expand Down
6 changes: 3 additions & 3 deletions detox/android/detox/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ apply plugin: 'kotlin-android-extensions'

def _ext = rootProject.ext

def _compileSdkVersion = _ext.has('compileSdkVersion') ? _ext.compileSdkVersion : 25
def _buildToolsVersion = _ext.has('buildToolsVersion') ? _ext.buildToolsVersion : '27.0.3'
def _compileSdkVersion = _ext.has('compileSdkVersion') ? _ext.compileSdkVersion : 28
def _buildToolsVersion = _ext.has('buildToolsVersion') ? _ext.buildToolsVersion : '28.0.3'
def _minSdkVersion = _ext.has('minSdkVersion') ? _ext.minSdkVersion : 18
def _targetSdkVersion = _ext.has('targetSdkVersion') ? _ext.targetSdkVersion : 25
def _targetSdkVersion = _ext.has('targetSdkVersion') ? _ext.targetSdkVersion : 28
def _kotlinVersion = _ext.has('detoxKotlinVersion') ? _ext.detoxKotlinVersion : '1.2.0'
def _kotlinStdlib = _ext.has('detoxKotlinStdlib') ? _ext.detoxKotlinStdlib : 'kotlin-stdlib-jdk8'

Expand Down
4 changes: 2 additions & 2 deletions detox/android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Wed Dec 20 14:09:27 IST 2017
#Sun May 26 15:32:06 IDT 2019
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-all.zip
2 changes: 1 addition & 1 deletion detox/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"jest": "24.6.x",
"mockdate": "^2.0.1",
"prettier": "1.7.0",
"react-native": "0.56.0",
"react-native": "0.59.8",
"wtfnode": "^0.8.0"
},
"dependencies": {
Expand Down
6 changes: 3 additions & 3 deletions detox/test/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ apply plugin: 'com.android.application'
apply from: "../../node_modules/react-native/react.gradle"

android {
compileSdkVersion 27
compileSdkVersion 28

defaultConfig {
applicationId "com.wix.detox.test"
minSdkVersion 18
targetSdkVersion 26
targetSdkVersion 28
versionCode 1
versionName "1.0"
ndk {
Expand Down Expand Up @@ -63,7 +63,7 @@ android {
}

dependencies {
implementation "com.android.support:appcompat-v7:27.1.1"
implementation "com.android.support:appcompat-v7:28.0.0"

fromSourceImplementation(project(path: ":ReactAndroid"))
// noinspection GradleDynamicVersion
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.example;

import android.os.Bundle;
import android.test.suitebuilder.annotation.LargeTest;

import androidx.test.filters.LargeTest;
import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.rule.ActivityTestRule;
Expand Down
5 changes: 1 addition & 4 deletions detox/test/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,13 @@
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>

<uses-sdk
android:minSdkVersion="16"
android:targetSdkVersion="22" />

<application
android:name=".MainApplication"
android:allowBackup="true"
android:label="@string/app_name"
android:icon="@mipmap/ic_launcher"
android:theme="@style/AppTheme"
android:usesCleartextTraffic="true"
>

<!--
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,4 @@ public void onCreate() {
super.onCreate();
SoLoader.init(this, /* native exopackage */ false);
}

}
5 changes: 3 additions & 2 deletions detox/test/android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
buildscript {
ext.kotlinVersion = '1.3.0'
ext.buildToolsVersion = '27.0.3'
ext.detoxKotlinVerion = ext.kotlinVersion
ext.buildToolsVersion = '28.0.3'

repositories {
google()
Expand All @@ -9,7 +10,7 @@ buildscript {
}

dependencies {
classpath 'com.android.tools.build:gradle:3.1.4'
classpath 'com.android.tools.build:gradle:3.3.2'
classpath 'de.undercouch:gradle-download-task:3.4.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
}
Expand Down
1 change: 0 additions & 1 deletion detox/test/android/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,3 @@
# org.gradle.parallel=true

android.useDeprecatedNdk=true
android.enableAapt2=false
4 changes: 2 additions & 2 deletions detox/test/android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Tue Jun 20 12:00:16 IDT 2017
#Tue May 21 17:08:37 IDT 2019
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-all.zip
6 changes: 4 additions & 2 deletions detox/test/e2e/03.actions.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const custom = require('./utils/custom-it');

describe('Actions', () => {
beforeEach(async () => {
await device.reloadReactNative();
Expand Down Expand Up @@ -61,7 +63,7 @@ describe('Actions', () => {
});

// directions: 'up'/'down'/'left'/'right'
it('should scroll for a small amount in direction', async () => {
custom.it.withFailureIf.android.rn58OrNewer('should scroll for a small amount in direction', async () => {
await expect(element(by.text('Text1'))).toBeVisible();
await expect(element(by.text('Text4'))).toBeNotVisible();
await expect(element(by.id('ScrollView161'))).toBeVisible();
Expand All @@ -73,7 +75,7 @@ describe('Actions', () => {
await expect(element(by.text('Text4'))).toBeNotVisible();
});

it('should scroll for a large amount in direction', async () => {
custom.it.withFailureIf.android.rn58OrNewer('should scroll for a large amount in direction', async () => {
await expect(element(by.text('Text6'))).toBeNotVisible();
await element(by.id('ScrollView161')).scroll(220, 'down');
await expect(element(by.text('Text6'))).toBeVisible();
Expand Down
57 changes: 57 additions & 0 deletions detox/test/e2e/03.fs-scroll-actions.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/**
* A mini suite providing an alternative to tests failing due to issues found in RN 58+ on Android (see
* https://github.com/facebook/react-native/issues/23870).
* It basically runs similar use cases -- all of which involve visibility and scrolling, but in a
* setup where they _can_ pass, so as to assert that the core Detox functionality (waitFor(), scroll())
* is valid nevertheless.
*/

describe('Fullscreen scrolling Actions', () => {
beforeEach(async () => {
await device.reloadReactNative();
await element(by.text('Scroll-Actions')).tap();
});

it('should scroll for a small amount in direction', async () => {
await expect(scrollViewDriver.element()).toBeVisible();
await expect(scrollViewDriver.firstItem()).toBeVisible();
await expect(scrollViewDriver.lastItem()).toBeNotVisible();

await scrollViewDriver.scrollBy(60);
await expect(scrollViewDriver.firstItem()).toBeNotVisible();
await expect(scrollViewDriver.secondItem()).toBeVisible();
await scrollViewDriver.scrollBy(-60);
await expect(scrollViewDriver.firstItem()).toBeVisible();
await expect(scrollViewDriver.lastItem()).toBeNotVisible();
});

it('should scroll for a large amount in direction', async () => {
await expect(scrollViewDriver.element()).toBeVisible();
await expect(scrollViewDriver.firstItem()).toBeVisible();
await expect(scrollViewDriver.lastItem()).toBeNotVisible();

try {
await scrollViewDriver.scrollBy(1000);
} catch (error) {
console.log('Expected error caught: Scrolled the list down to its very end');
}
await expect(scrollViewDriver.firstItem()).toBeNotVisible();
await expect(scrollViewDriver.lastItem()).toBeVisible();
});

it('should find element by scrolling until it is visible', async () => {
await expect(scrollViewDriver.lastItem()).toBeNotVisible();
await waitFor(scrollViewDriver.lastItem()).toBeVisible().whileElement(scrollViewDriver.viewFilter()).scroll(200, 'down');
await expect(scrollViewDriver.lastItem()).toBeVisible();
});
});

const scrollViewDriver = {
viewFilter: () => by.id('FSScrollActions.scrollView'),
element: () => element(scrollViewDriver.viewFilter()),
listItem: (index) => element(by.text(`Text${index}`)),
firstItem: () => scrollViewDriver.listItem(1),
secondItem: () => scrollViewDriver.listItem(2),
lastItem: () => scrollViewDriver.listItem(20),
scrollBy: (amount) => scrollViewDriver.element().scroll(Math.abs(amount), (amount > 0 ? 'down' : 'up')),
};
7 changes: 4 additions & 3 deletions detox/test/e2e/05.waitfor.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const custom = require('./utils/custom-it');

describe('WaitFor', () => {
beforeEach(async() => {
await device.reloadReactNative();
Expand All @@ -11,18 +13,17 @@ describe('WaitFor', () => {
await expect(element(by.id('createdAndVisibleText'))).toExist();
});

it('should wait until an element is removed', async() => {
it('should wait until an element is removed', async () => {
await expect(element(by.id('deletedFromHierarchyText'))).toBeVisible();
await element(by.id('GoButton')).tap();
await waitFor(element(by.id('deletedFromHierarchyText'))).toBeNotVisible().withTimeout(20000);
await expect(element(by.id('deletedFromHierarchyText'))).toBeNotVisible();
});

it('should find element by scrolling until it is visible', async() => {
custom.it.withFailureIf.android.rn58OrNewer('should find element by scrolling until it is visible', async () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the point of this if we know it will fail anyway? We will be running the RN59 suite from now on, on both iOS and Android. Why not just close it off for Android until we have a proper fix?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is so we'd know when (if) they decide to get it fixed.

await expect(element(by.text('Text5'))).toBeNotVisible();
await element(by.id('GoButton')).tap();
await waitFor(element(by.text('Text5'))).toBeVisible().whileElement(by.id('ScrollView')).scroll(50, 'down');
await expect(element(by.text('Text5'))).toBeVisible();
});

});
40 changes: 40 additions & 0 deletions detox/test/e2e/utils/custom-it.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
const _ = require('lodash');
const rnMinorVer = require('./rn-consts').rnVersion.minor;

const _it = {
withFailureIf: {
android: {
rn58OrNewer: (spec, specFn) => runOrExpectFailByPredicates(spec, specFn, platformIs('android'), rnVerAtLeast(58)),
}
},
};

function runOrExpectFailByPredicates(spec, specFn, ...predicateFuncs) {
it(spec, async function() {
if (allPredicatesTrue(predicateFuncs)) {
await expectSpecFail(specFn);
} else {
await runSpec(specFn);
}
});
}

const platformIs = (platform) => () => (device.getPlatform() === platform);
const rnVerAtLeast = (rnVer) => () => (rnMinorVer >= rnVer);
const allPredicatesTrue = (predicateFuncs) => _.reduce(predicateFuncs, (result, predicate) => (result && predicate()), true);

async function expectSpecFail(specFn) {
try {
await runSpec(specFn);
} catch (e) {
console.log('Successfully caught an expected error:', e);
return;
}
throw new Error('Ran a spec expecting an error, but no error was thrown');
}

const runSpec = (specFn) => specFn();

module.exports = {
it: _it,
};
15 changes: 15 additions & 0 deletions detox/test/e2e/utils/rn-consts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const rnVersion = (function parseRNVersion() {
const packageJson = require('react-native/package.json');
const raw = packageJson.version;
const [major, minor, patch] = raw.split('.');
return {
major,
minor,
patch,
raw,
};
})();

module.exports = {
rnVersion,
};
4 changes: 2 additions & 2 deletions detox/test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
},
"dependencies": {
"moment": "^2.24.0",
"react": "16.4.1",
"react-native": "0.56.0"
"react": "16.8.3",
"react-native": "0.59.8"
},
"devDependencies": {
"@babel/core": "^7.4.5",
Expand Down
25 changes: 25 additions & 0 deletions detox/test/src/Screens/ScrollActionsScreen.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import React, { Component } from 'react';
import {
Text,
View,
ScrollView,
} from 'react-native';

export default class ScrollActionsScreen extends Component {

render() {
return (
<View style={{ flex: 1, justifyContent: 'flex-start', borderColor: '#c0c0c0', borderWidth: 1, backgroundColor: '#f8f8ff' }}>
<ScrollView testID='FSScrollActions.scrollView'>
{
Array.from({length: 20}, (_, index) => this.renderItem(index + 1))
}
</ScrollView>
</View>
);
}

renderItem(id) {
return <Text key={`listItem.${id}`} style={{ height: 30, backgroundColor: '#e8e8f8', padding: 5, margin: 10 }}>{`Text${id}`}</Text>;
}
}
2 changes: 2 additions & 0 deletions detox/test/src/Screens/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import SanityScreen from './SanityScreen';
import MatchersScreen from './MatchersScreen';
import ActionsScreen from './ActionsScreen';
import ScrollActionsScreen from './ScrollActionsScreen';
import AssertionsScreen from './AssertionsScreen';
import WaitForScreen from './WaitForScreen';
import StressScreen from './StressScreen';
Expand All @@ -20,6 +21,7 @@ export {
SanityScreen,
MatchersScreen,
ActionsScreen,
ScrollActionsScreen,
AssertionsScreen,
WaitForScreen,
StressScreen,
Expand Down
1 change: 1 addition & 0 deletions detox/test/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ class example extends Component {
{this.renderScreenButton('Sanity', Screens.SanityScreen)}
{this.renderScreenButton('Matchers', Screens.MatchersScreen)}
{this.renderScreenButton('Actions', Screens.ActionsScreen)}
{this.renderScreenButton('Scroll-Actions', Screens.ScrollActionsScreen)}
{this.renderScreenButton('Assertions', Screens.AssertionsScreen)}
{this.renderScreenButton('WaitFor', Screens.WaitForScreen)}
{this.renderScreenButton('Stress', Screens.StressScreen)}
Expand Down
3 changes: 3 additions & 0 deletions scripts/ci.android.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#!/bin/bash -e

# Approve unapproved SDK licenses
("yes | $ANDROID_HOME/tools/bin/sdkmanager --licenses")

source $(dirname "$0")/ci.sh

pushd detox/android
Expand Down