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

Replace Jest runner with Wdio runner E2E #41218

Open
wants to merge 87 commits into
base: main
Choose a base branch
from

Conversation

Othinn
Copy link

@Othinn Othinn commented Oct 27, 2023

Summary:

Due to the high flakiness of e2e tests, we suggested changing the Jest runner to Wdio runner, which should help us reduce the flakiness and increase the usefulness of the tests through better logs.

Changelog:

  • Changed test runner from Jest to Wdio with Mocha assertion library. Because of using Mocha, I changed the Jest test block to Mochas it and changed the arrow functions to regular functions (in Mocha, the arrow function is discouraged from using https://mochajs.org/#arrow-functions)
  • All tests are moved to component folders(naming convention of folders and tests to be decided)
  • Moved steps to separate it for better visibility on results
  • As a temporal solution, I've created separate conf files for ios and Android
  • Added spec reporter. After we decide about result storing, we can change to, eg. Allure
  • Appium is added to services, which means that we don't start the appium server by a terminal, and Appium logs are displayed in a terminal while tests are running
  • Updated CircleCI jobs

Test Plan:

@facebook-github-bot
Copy link
Contributor

Hi @Othinn!

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 cla@meta.com. Thanks!

@analysis-bot
Copy link

analysis-bot commented Oct 27, 2023

Platform Engine Arch Size (bytes) Diff
android hermes arm64-v8a 16,777,794 -173,275
android hermes armeabi-v7a n/a --
android hermes x86 n/a --
android hermes x86_64 n/a --
android jsc arm64-v8a 20,165,571 -169,275
android jsc armeabi-v7a n/a --
android jsc x86 n/a --
android jsc x86_64 n/a --

Base commit: 96ed119
Branch: main

elementIsFound = await driver.$(locator).isDisplayed();
while (!elementIsFound) {
elementIsFound = await $(locator).isDisplayed();
while (!(await elementIsFound)) {
driver.touchPerform([
{
action: 'press',

Choose a reason for hiding this comment

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

I would suggest changing this scroll logic completely. Taking the window size and performing mathematical operations on it to determine touches is prone to error. Here's a better way:

    await browser.waitUntil(
      async () => {
        await driver.execute('mobile: scroll', { direction: 'down' });
        return await $(locator).isDisplayed();
      },
    );

Copy link
Author

Choose a reason for hiding this comment

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

I've tried to change scroll logic with your or similar solutions, but after testing, the current implementation is less flak, at least in the local environment.

@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 Oct 30, 2023
@github-actions
Copy link

github-actions bot commented Oct 30, 2023

Fails
🚫

📋 Verify Changelog Format - See Changelog format

Generated by 🚫 dangerJS against 7c311bd

@facebook-github-bot facebook-github-bot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label Oct 30, 2023

const cancelText = 'Your application has been cancelled!';

describe('Test is checking cancel button', function () {

Choose a reason for hiding this comment

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

Nit (optional recommendation, up to you): describe() should explain the feature as a whole being tested. Thinking about it from improving the debugging experience, I think the description should be:

"Testing Cancel Button Functionality"

This tells the engineer exactly which feature is under test.

const cancelText = 'Your application has been cancelled!';

describe('Test is checking cancel button', function () {
it('Should view properly submit cancel text', async function () {

Choose a reason for hiding this comment

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

Nit: Improve test name. An engineer debugging this should know exactly what the test does by reading the name. After reading this, I'm not sure what this test is doing - I have to read the code to figure that out.

An example of a better name:

"Press Cancel Button - Validate {Correct Action}" but replace the {} with what you expect to happen

describe('Test is checking cancel button', function () {
it('Should view properly submit cancel text', async function () {
expect(
await ComponentsScreen.checkButtonComponentIsDisplayed(),

Choose a reason for hiding this comment

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

I'm wondering if this should be in a before hook? Or it's own test? It looks like this is handling setting up the app to get the correct state, which doesn't correlate to the test name.

Making sure each test is has a defined function is important for debugging purposes (and code readability).

Rather than having the following structure:

it("Testing cancel button")
// Setup app
// Test Cancel Button

We can organize as:

it('Setup Cancel Button Testing')
// Setup app to test cancel button

it('Test cancel button')
// Test cancel button

@@ -171,6 +171,8 @@ jobs:
(yarn test-e2e-ios 2>&1 | tee /tmp/test_log) || true
- store_artifacts:
path: /tmp/test_log
- store_artifacts:
path: ~/react-native/packages/rn-tester-e2e/reports

Choose a reason for hiding this comment

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

You can also include the error screenshots here. That way, the engineer can see a screenshot of the failure.

});

it('Should click on the Activity Indicator component', async () => {
await ComponentsScreen.clickActivityIndicatorComponent();

Choose a reason for hiding this comment

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

Every test should have an assert (or else, what is it doing?).

Does this test have a purpose?

context,
{error, result, duration, passed, retries},
) {
if (!passed) {
Copy link

@samuelfreiberg samuelfreiberg Apr 8, 2024

Choose a reason for hiding this comment

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

Nit (Optional):

Before checking if the test passed, I added a small snippet of code that I found useful when debugging through logs. It can give you a quick method of searching for the results of a specific test in a long log file:

const resultString = results.passed ? 'Passed' : 'Failed';
console.log(``\nTest Case: "${test.description}".\nResult: "${resultString}".\nDuration: "${(results.duration/600).toFixed(2)}s". \n``);

type PlatformsReference = {
ios: string,
android: string,
};

class Utils {
async checkElementExistence(locator: string): Promise<boolean> {
await driver.$(locator).waitForDisplayed();
return driver.$(locator).isDisplayed();
await $(locator).waitForDisplayed();
Copy link

@samuelfreiberg samuelfreiberg Apr 8, 2024

Choose a reason for hiding this comment

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

Nit: In all these helper methods, I suggest utilizing the errorMsg parameter in waitForDisplayed(). You can pass in the specific locator string so the error message is specific. If not, it will be confusing when debugging to see where it failed and which component.

For example,
await $(locator).waitForDisplayed({ timeout: 15000, timeoutMsg: "The element with locator=" + locator + " was not found"});

Choose a reason for hiding this comment

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

It helps debugging a ton

await driver.$(locator).waitForDisplayed();
return driver.$(locator).isDisplayed();
await $(locator).waitForDisplayed();
return $(locator).isDisplayed();

Choose a reason for hiding this comment

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

You can just return await $(locator).waitForDisplayed();. Such as return await $(locator).waitForDisplayed();.

waitForDisplayed throws an error if it fails, or returns true if it succeeds. Adding return $(locator).isDisplayed(); is unnecessary and will decrease perf by adding another API call.

@react-native-bot
Copy link
Collaborator

This PR is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days.

@react-native-bot react-native-bot added the Stale There has been a lack of activity on this issue and it may be closed soon. label Oct 6, 2024
@thymikee
Copy link
Contributor

thymikee commented Oct 7, 2024

@Othinn any chance you could rebase that to main and migrate to GitHub Actions?

@react-native-bot react-native-bot removed the Stale There has been a lack of activity on this issue and it may be closed soon. label Oct 8, 2024
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. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants