Skip to content

Conversation

adzironman
Copy link

@adzironman adzironman commented Jan 13, 2023

please check out this one first ➡️ #35016

Summary

The motivation is to create an e2e testing solution for the rn-tester default app. With cooperation with Callstack developers, we are trying to make a working tool. This PR is adding configuration for the BDD approach with cucumber.
Next steps:

  • integrate with devices' cloud
  • build an app automatically

Changelog

[General] [Added] - Added first working configuration for e2e testing with Appium, Jest and Cucumber

Test Plan

Follow Readme File

Comparison of work for approach with and without Cucumber

In a clean jest+wdio setup, test scenarios are written in one file:
image

In order to use the BDD approach you need to do a few additional steps in comparison to jest+wdio solution implemented here.

Additional steps:

  1. Add .feature file with test scenarios written in Gherkin syntax

image

2. Add a runner file
  • call appropriate methods in the same order as the steps in the feature file. This is a drawback of that solution.

image

  • implement methods(used by gherking steps) that will be used only in that feature. Steps shared between features can be implemented in common_steps file

Videos

  • Android:
final_andorid.mp4
  • iOS:
final_ios.mp4

@facebook-github-bot
Copy link
Contributor

Hi @adzironman!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at [email protected]. Thanks!

@github-actions
Copy link

github-actions bot commented Jan 13, 2023

Warnings
⚠️ 🔒 package.json - Changes were made to package.json. This will require a manual import by a Facebook employee.

Generated by 🚫 dangerJS against b3d21be

@react-native-bot react-native-bot added the No CLA Authors need to sign the CLA before a PR can be reviewed. label Jan 14, 2023
@mohit23x
Copy link

This Appium setup is cool, we made a babel plugin to find elements with testID, do check if it's useful in this setup. https://www.npmjs.com/package/babel-plugin-format-testid

@facebook-github-bot
Copy link
Contributor

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jan 16, 2023
@react-native-bot react-native-bot removed the No CLA Authors need to sign the CLA before a PR can be reviewed. label Jan 16, 2023
@react-native-bot react-native-bot added the Type: Enhancement A new feature or enhancement of an existing feature. label Jan 16, 2023
@adzironman adzironman marked this pull request as ready for review January 16, 2023 12:11
Copy link
Contributor

@cipolleschi cipolleschi left a comment

Choose a reason for hiding this comment

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

I left a couple of comments that are iOS specific. A part from that, great work!

A question out of ignorance: if we have to implement and call the JS methods, can we get rid of Gerkin? It looks a repetition of the test description and they could go out of sync easily (or become maintenance burden). If we have JS methods with descriptive names, we can use a code-as-documentation approach and simplify the setup.
Do you think that it is possible? (Another approach could be to generate the Gerkin file from the JS one)

Comment on lines +26 to +30
If you are M1 mac user:
1. Install ffi package `gem install ffi -v '1.15.5' --source 'https://rubygems.org/'`
2. Install pods with new architecture, e.g. using JSC `USE_HERMES=0 arch -x86_64 pod install`
3. Open the generated `RNTesterPods.xcworkspace`.
4. Build the app.
Copy link
Contributor

Choose a reason for hiding this comment

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

This should not be required anymore.

3. Open the generated `RNTesterPods.xcworkspace`.
4. Build the app.

Find the **RNTester.app** in `~/Library/Developer/Xcode/DerivedData/RNTesterPods-{id}/Build/Products/Debug-iphonesimulator` and move the app to the following directory `/react-native/packages/rn-tester-e2e/apps`
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can use xcodebuild from the command line and tell it to generate the app in some specific folder: above listing 8 and 9

Copy link
Contributor

@NickGerleman NickGerleman left a comment

Choose a reason for hiding this comment

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

Leaving some very superficial feedback. This will need some cleanup I think.

More generally, I would try to think of the scenarios we want to test E2E, and what we need more than this to be able to accomplish it.

The basis here lets the test runner navigate, check for existence of controls/text. But I think the more valuable bits are understanding the impact a props, etc has on the native component. Either visually via screenshot testing, or via approaches like snapshotting the native component tree.

With the screen objects, I would try to settle on some pattern. E.g. an object per RNTester page, if we are going to have them. Though unless we solve the problem of engineers adding to the screen object when adding RNTester examples, we should not assume these will be kept up to date.

I also expect that Appium may balloon the number of dependencies we have and are caching. Please keep an eye out for its effect on the lockfile, especially for anything which will immediately come back as a security bit.

import { beforeEach, afterEach, jest } from '@jest/globals';


jest.setTimeout(40000);
Copy link
Contributor

Choose a reason for hiding this comment

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

This contradicts the timeout we set in the config?

host: 'localhost',
port: 4723,
waitforTimeout: 30000,
logLevel: 'silent',
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
logLevel: 'silent',
logLevel: 'error',

"private": true,
"keywords": [],
"author": "",
"license": "ISC",
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
"license": "ISC",
"license": "MIT",

"@babel/eslint-parser": "^7.19.1",
"@babel/runtime": "^7.12.5",
"@react-native-community/eslint-config": "^2.0.0",
"appium": "^2.0.0-beta.40",
Copy link
Contributor

Choose a reason for hiding this comment

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

Not seeing reflected in yarn lockfile. Could we yarn install (also so we can see how many deps added)

"jest-cucumber": "^3.0.1",
"jest-html-reporter": "^3.7.0",
"metro-react-native-babel-preset": "^0.70.3",
"react-test-renderer": "18.0.0",
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems unused?


buttonComponentElement = Utils.platformSelect({
ios: '[label="Button Simple React Native button component."]',
android: '~Button Simple React Native button component.',
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we search by test id instead of string?

class ButtonComponentScreen {

buttonScreenElement = Utils.platformSelect({
ios: '[label="Button"]',
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we search by test id instead of any string? Also means we can remove this per-platform bits.

// Common steps reusable between different features
export const userIsOnMainScreen = (given) => {
given('User is on the main screen', async () => {
await driver.pause(2000);
Copy link
Contributor

Choose a reason for hiding this comment

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

Harcoded waits like this should be avoided

@@ -0,0 +1,19 @@
Feature: Button component screen
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we really need cucumber, if we don't use it anywhere else.

await driver.$(locator).waitForDisplayed();
return driver.$(locator).getText();
}

Copy link
Contributor

Choose a reason for hiding this comment

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

All of these should be formatted/linted, have copyright headers.

@kelset
Copy link
Contributor

kelset commented Jan 16, 2023

@NickGerleman @cipolleschi please ignore this PR for now, this is part 2 of #35786 but the team is still working on them both (you'll see that a good part of your comments I've already covered in the other PR).

I'll ping you once this 2nd PR should be looked at ;)

@kelset kelset marked this pull request as draft January 20, 2023 13:25
@kelset
Copy link
Contributor

kelset commented Feb 23, 2023

let's close this one in favour of #36267, things have changed enough that adding cucumber will need (if we decide to do it) much further down the line

@kelset kelset closed this Feb 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Type: Enhancement A new feature or enhancement of an existing feature.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants