Files
react-native/packages/rn-tester-e2e/tests/helpers/utils.js
T
Elżbieta Berger aa2a0c1115 New RNtester e2e tests (#39117)
Summary:
The motivation was to create more e2e tests that test other components in the RNTester app.
The list of components that have been tested is below:

| Component|Test is added|Platform|
| :---        |    :----:   |---: |
|DrawerLayoutAndroid|NO|Android|
|ActivityIndicator|YES|iOS & Android|
|Button|YES|iOS & Android|
|FlatList|YES|iOS & Android|
|Image|NO|iOS & Android|
|JSResponderHandler|YES|iOS & Android|
|InputAccessoryView|NO|iOS|
|KeyboardAvoidingView|YES|iOS & Android|
|Modal|YES|iOS & Android|
|New App Screen|YES|iOS & Android|
|Pressable|YES|iOS & Android|
|RefreshControl|YES|iOS & Android|
|ScrollView|NO|iOS & Android|
|ScrollViewSimpleExample|YES|iOS & Android|
|SafeAreaView|NO|iOS|
|ScrollViewAnimated|NO|iOS & Android|
|ScrollViewIndicatorInsets|NO|iOS|
|SectionList|NO|iOS & Android|
|StatusBar|NO|iOS & Android|
|SwipeableCard|NO|iOS & Android|
|Switch|NO|iOS & Android|
|Text|NO|iOS & Android|
|TextInput|NO|iOS & Android|
|Touchable* and onPress|NO|iOS & Android|
|TextInputs with key prop|NO|Android|
|TransparentHitTestExample|NO|iOS|
|View|NO|iOS & Android|
|New Architecture Examples|NO|iOS & Android|
|Performance Comparison Examples|NO|iOS & Android|

## Changelog:

[General] [Added] - Added next component tests for RNTester

Pull Request resolved: https://github.com/facebook/react-native/pull/39117

Test Plan:
Follow Readme file.

## Test Result:

For iOS platform:<br>
![Screenshot 2023-08-22 at 18 08 28](https://github.com/facebook/react-native/assets/19895261/c9d0ef78-ae31-487f-aa53-4c299fefef6a)

For Android platform:<br>
![Screenshot 2023-08-22 at 18 13 47](https://github.com/facebook/react-native/assets/19895261/db661c95-1cf9-4e1a-b02f-4a6141313719)

Reviewed By: yungsters

Differential Revision: D48828525

Pulled By: cipolleschi

fbshipit-source-id: dfe7cc9871666a6b5c0704a207ca1eeb65f50114
2023-09-01 03:24:30 -07:00

95 lines
2.3 KiB
JavaScript

/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
* @format
*/
import {driver} from '../../jest.setup';
type PlatformsReference = {
ios: string,
android: string,
};
class Utils {
async checkElementExistence(locator: string): Promise<boolean> {
await driver.$(locator).waitForDisplayed();
return driver.$(locator).isDisplayed();
}
async clickElement(locator: string): Promise<void> {
await driver.$(locator).waitForDisplayed();
await driver.$(locator).click();
}
async getElementText(locator: string): Promise<string> {
await driver.$(locator).waitForDisplayed();
return driver.$(locator).getText();
}
platformSelect(platforms: PlatformsReference): string {
// if something goes wrong, we fallback to ios. But it should never happent, the process will fail way earlier.
return platforms[process?.env?.E2E_DEVICE || 'ios'];
}
async scrollToElement(locator: string): Promise<void> {
let {width, height} = await driver.getWindowSize();
let elementIsFound;
try {
elementIsFound = await driver.$(locator).isDisplayed();
while (!elementIsFound) {
driver.touchPerform([
{
action: 'press',
options: {
x: width / 2,
y: height / 2,
},
},
{
action: 'wait',
options: {
ms: 1000,
},
},
{
action: 'moveTo',
options: {
x: width / 2,
y: height / 10,
},
},
{
action: 'release',
},
]);
elementIsFound = await driver.$(locator).isDisplayed();
}
} catch (err) {
console.log('Element is not found');
}
}
}
export const iOSLabel = (label: string): string => {
return `[label="${label}"]`;
};
export const iOSName = (name: string): string => {
return `[name="${name}"]`;
};
export const androidWidget = (
type: string,
selector: string,
id: string,
): string => {
return `//android.widget.${type}[@${selector}="${id}"]`;
};
export const UtilsSingleton: Utils = new Utils();