wix / Detox

Gray box end-to-end testing and automation framework for mobile apps
https://wix.github.io/Detox/
MIT License
11.15k stars 1.92k forks source link

The event "Network Request" is taking place with object -ios #3443

Closed chamile closed 2 years ago

chamile commented 2 years ago

Description

I have a Sign-in button that it calls an API. So whan I run await element(by.text('Sign in')).tap();

it navigates to the corresponding page after calling the API request but the test hangs and waits without completing the test.

image

Code

/* eslint-disable no-undef */
const { execSync } = require('child_process');

const OPTIONS = {
  timeout: 10000,
  killSignal: 'SIGKILL',
};
describe('screenshot', () => {
  beforeAll(async () => {
    await device.launchApp();
  });

  beforeEach(async () => {
    await device.reloadReactNative();
  });

  it('should take screenshot', async () => {
    const fileName = 'screenshot.png';

    if (device.getPlatform() === 'android') {
      execSync(`adb shel screencap /sdcard/${fileName}`);
      execSync(
        `adb pull /sdcard/${fileName} $(pwd)/android/fastlane/metadata/android/en-US/images/phoneScreenshots`
      );
    } else {
      execSync(
        `xcrun simctl io booted screenshot $(pwd)/fastlane/screenshots/screenshot.png`,
        OPTIONS
      );
      await element(by.text('Show more options')).tap();
      execSync(
        `xcrun simctl io booted screenshot $(pwd)/fastlane/screenshots/screenshot1.png`,
        OPTIONS
      );
      await element(by.text('Username & Password')).tap();
      execSync(
        `xcrun simctl io booted screenshot $(pwd)/fastlane/screenshots/screenshot2.png`,
        OPTIONS
      );
      await element(by.id('testID-userName')).typeText('test');
      await element(by.id('testID-password')).typeText('test');
      execSync(
        `xcrun simctl io booted screenshot $(pwd)/fastlane/screenshots/screenshot3.png`,
        OPTIONS
      );
      await element(by.text('Sign in')).tap();
    }
  });
});

Your environment

Detox version: 19.7.1 React Native version: 0.62.2 Node version: v16.11.1 Device model: iOS version: 13 macOS version: 11.6 Xcode version: 13.0 Test-runner jest-circus

d4vidi commented 2 years ago

@chamile you need to look into why that network request doesn't get replied to.

On a different matter, have you considered using Detox's API for taking screenshots?

github-actions[bot] commented 2 years ago

This issue appears to be a general usage or support question. In order to get help, please either ask a question on Stack Overflow with the detox tag, or simply join our Discord. Feel free to post your Stack Overflow question here for more visibility! We'll take a look at it ASAP. For more information about our policy on issues, refer to this discussion.

mgithubmessier commented 1 year ago

Damn, I'm running into this same issue, @chamile you ever figure this one out?

johanndeswardt commented 1 year ago

I'm also having issues with this.

detoxURLBlacklistRegex and setURLBlacklist do not seem to actually do anything. My tests are not running because synchronization is being prevented because of in-flight requests to Launch Darkly.

asafkorem commented 1 year ago

@johanndeswardt Could you please copy here the setURLBlacklist call you've tried?

asafkorem commented 1 year ago

or the launch-app command with the detoxURLBlacklistRegex argument

OrLevy23 commented 1 year ago

Hey, i've just came across this issue while trying to implement detox on our app

image
The event "Network Request" is taking place with object: "URL: “https://clientstream.launchdarkly.com/meval/****”".
• Run loop "Main Run Loop" is awake.

any ideas on how to solve it?

menttys commented 1 year ago

Exactly the same issue as @OrLevy23, any findings about it?

NicholasBoccuzzi commented 1 year ago

@OrLevy23 @menttys -- did either of you figure this out using a Launch Darkly link?

d4vidi commented 1 year ago

@OrLevy23 @NicholasBoccuzzi @menttys @chamile Please allow for testing out this new release with a related fix - https://github.com/wix/Detox/releases/tag/20.3.0

GittyAjay commented 1 year ago

I am still getting this error in the updated detox version ("detox": "^20.5.0")

The app is busy with the following tasks: • Run loop "Main Run Loop" is awake. • The event "Network Request" is taking place with object: "URL: “https://api-dev.gigflex.com:8088/socket/347/oxxy2uxi/xhr_streaming?t=1679374217817”". • There are 1 work items pending on the dispatch queue: "Main Queue ()". • The event "Network Request" is taking place with object: "URL: “https://api-dev.gigflex.com:8088/socket/501/o2tr5ber/xhr_streaming?t=1679374218301”".

`import { device } from 'detox'; describe('App Test', () => {

beforeAll(async () => {
    await device.launchApp();
});

beforeEach(async () => {
    await device.reloadReactNative();
});

it('should have login screen', async () => {

    await expect(element(by.id('login-container'))).toBeVisible();
});

});

`

and it ends with error

FAIL e2e/starter.test.js (124.849 s) App Test ✕ should have login screen (2 ms)

● App Test › should have login screen

thrown: "Exceeded timeout of 120000 ms for a hook.
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."

  2 | describe('App Test', () => {
  3 |
> 4 |     beforeAll(async () => {
    |     ^
  5 |         await device.launchApp();
  6 |     });
  7 |

  at beforeAll (e2e/starter.test.js:4:5)
  at Object.describe (e2e/starter.test.js:2:1)

10:22:08.821 detox[8542] E Command failed with exit code = 1: jest --config e2e/jest.config.js

Does anyone have any idea how can i resolve this? @d4vidi @mgithubmessier @menttys @OrLevy23 @chamile

nikolal commented 1 year ago

I have the same issue:

detoxURLBlacklistRegex and setURLBlacklist do not seem to actually do anything.

The event "Network Request" is taking place with object: "URL: “https://data.emb-api.com/v1/log/events”".

I tried:

await device.setURLBlacklist(['.*data.emb-api.com.*'])

and

beforeAll(async () => {
  await device.launchApp({
    launchArgs: {
      detoxURLBlacklistRegex: getDetoxURLBlacklistRegexFromDomains(domains),
    },
  })
})

const domains = [
  'data.emb-api.com'
]

const getDetoxURLBlacklistRegexFromDomains = domains =>
  '(' + domains.map(domain => `\\".*${domain}.*\\"`).join(',') + ')'

"detox": "^20.6.0",

gmferraz commented 1 year ago

Same issue as @OrLevy23. Any news?

vm-agnislav commented 1 year ago

We have the same issue with LaunchDarkly on the latest detox version. Any updates on it? @d4vidi

KaterinaUK commented 1 year ago

@d4vidi Can I please ask to reopen this issue? Many people still have the same problem! Even after trying what was suggested.

zfolwick commented 9 months ago

I just had this same issue:

• The event "Network Request" is taking place with object: "URL: “https://clients3.google.com/generate_204?_=1701807425591”".

I rarely restart my simulators, so running ps -ef | grep detox showed a process that appeared to have gone stale. I killed the process with kill 42843 and re-ran the tests and that seemed to have fixed it. See below (note the "??" indicating even the OS has forgotten how long it's been around).

Screenshot 2023-12-05 at 12 21 18 PM
SwetaTanwar commented 6 months ago

I was able to make it work by using detoxURLBlacklistRegex in launchArgs. Make sure to properly pass the url

beforeAll(async () => {
    await device.launchApp({
      newInstance: true,
      launchArgs: {
        detoxURLBlacklistRegex:
          '\\("^https://yourURL.com/*"\\)',
      },
    });
});
yusinto commented 4 months ago

We use this internally and should work:

  beforeAll(async () => {
    await device.launchApp({
      newInstance: true,
      launchArgs: {
        detoxURLBlacklistRegex: '\\("^https://clientstream.launchdarkly.com/meval"\\)',
      },
    });
  });
dominictobias commented 4 months ago

We use this internally and should work:

  beforeAll(async () => {
    await device.launchApp({
      newInstance: true,
      launchArgs: {
        detoxURLBlacklistRegex: '\\("^https://clientstream.launchdarkly.com/meval"\\)',
      },
    });
  });

Life saver. I don't get how they made LD network requests so problematic. They also break Android entirely at least on the simulator :/