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

Failed to find element while scrolling #4662

Open
2 tasks done
ersefuril opened this issue Dec 17, 2024 · 0 comments
Open
2 tasks done

Failed to find element while scrolling #4662

ersefuril opened this issue Dec 17, 2024 · 0 comments

Comments

@ersefuril
Copy link

ersefuril commented Dec 17, 2024

What happened?

Hey,

The test is pretty basic : I'm scrolling in a list (FlashList) until if find a specific element (with a unique testID).
Detox is just scrolling endlessly, event if the specific element is clearly visible and throw a timeout.
My tests are randomly failing on my CI machine (I could not reproduce it on my local machine). I didn't have any issues so far with scroll.

Here is a video where the test is supposed to scroll until the Summer box element is visible (i've cut the video since I can only post a 10mb file here) :

detox2.mov

What was the expected behaviour?

Scroll in a list until the specific element is visible.

Was it tested on latest Detox?

  • I have tested this issue on the latest Detox release and it still reproduces.

Did your test throw out a timeout?

Help us reproduce this issue!

Here are some utility functions :

export async function launchApp() {
  await device.launchApp({
    newInstance: true,
    permissions: {
      notifications: "YES",
      location: "always",
      camera: "YES",
      photos: "YES",
      userTracking: "YES",
    },
  });
}

 export async function waitForElementToBeVisible(
  element: Detox.IndexableNativeElement,
  timeout = 30_000,
) {
  return waitFor(element).toBeVisible().withTimeout(timeout);
}

export function scrollDownToElement(
  id: string | RegExp,
  listId: string,
  options?: {
    scrollPixelsAmount: number;
    startPositionX?: number;
    startPositionY?: number;
  },
) {
  return waitFor(elementById(id))
    .toBeVisible()
    .whileElement(by.id(listId))
    .scroll(
      options?.scrollPixelsAmount || 250,
      "down",
      options?.startPositionX || NaN,
      options?.startPositionY || NaN,
    );
}

Here is my utility Flows :

export const Flows = {
  HomeScreen: {
    async waitUntilVisible() {
      const homeListId = "HomeScreen.List.public";
      const homeList = elementById(homeListId);
      await waitForElementToBeVisible(homeList, 60_000);
    },

    async goToSale(saleId: string, saleName: string) {
      const homeListId = "HomeScreen.List.public";
      // Find sale on home screen
      const _saleId = `Public.${saleId}`;
      const sale = elementById(_saleId);
      // this is the part where the timeout occurs
      await scrollDownToElement(_saleId, homeListId, {
        scrollPixelsAmount: 600,
      });
      await waitForElementToBeVisible(sale);
      await sale.tap();
    },
  }
}

And here is the test :

describe("SaleScreen", () => {
  beforeEach(async () => {
    await launchApp();
  });

  describe("Monoproduct", () => {
    it("should display sale mono product", async () => {
      await Flows.HomeScreen.waitUntilVisible();
      await Flows.HomeScreen.goToSale(
        SALES.monoproduct.saleId,
        SALES.monoproduct.saleName,
      );
      await expect(elementById("ProductContent.Subtitle")).toExist();
    });
  });
});

In what environment did this happen?

Detox version:
React Native version:
Has Fabric (React Native's new rendering system) enabled: (yes/no)
Node version:
Device model:
iOS version:
macOS version:
Xcode version:
Test-runner (select one): jest / other

Detox logs

Detox logs
• Run loop "Main Run Loop" is awake.
• Run loop "JS Run Loop" is awake.
09:14:25.451 detox[49382] i The app has not responded to the network requests below:
  (id = 5) invoke: {"type":"action","action":"scroll","params":[600,"down",null,null],"predicate":{"type":"id","value":"HomeScreen.List.public","isRegex":false},"while":{"type":"expectation","predicate":{"type":"id","value":"Public.2268cbf4e1a143bcb9295037f","isRegex":false},"expectation":"toBeVisible"}}

That might be the reason why the test "SaleScreen Monoproduct should display sale mono product" has timed out.

09:14:25.451 detox[49382] i SaleScreen > Monoproduct: should display sale mono product [FAIL]

FAIL tests/SaleScreen.test.ts (168.795 s)
  SaleScreen
    Monoproduct
      ✕ should display sale mono product (157511 ms)

  ● SaleScreen › Monoproduct › should display sale mono product

    thrown: "Exceeded timeout of 120000 ms for a test.
    Add a timeout value to this test to increase the timeout, if this is a long-running test. See https://jestjs.io/docs/api#testname-fn-timeout."

      15 |
      16 |   describe("Monoproduct", () => {
    > 17 |     it("should display sale mono product", async () => {
         |     ^
      18 |       await Flows.HomeScreen.waitUntilVisible();
      19 |       await Flows.HomeScreen.goToSale(
      20 |         SALES.monoproduct.saleId,

      at it (tests/SaleScreen.test.ts:17:5)
      at describe (tests/SaleScreen.test.ts:16:3)
      at Object.describe (tests/SaleScreen.test.ts:11:1)

Device logs

Device logs
paste your device.log here!

More data, please!

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant