How can my Android app, running on android emulator, can ping a service running locally on my host?

Within a ReactNative android application, I want to detect a running appium service (an end to end server) so my app knows that it is currently running e2e.

From within my android emulator, to reach my localhost, considering Android emulator use localhost for it’s own network interface, I have read that android developer use 10.0.2.2 to reach the host localhost.

This is what I have tried:


// iOS/Android e2e test run on Emulator/Simulator with an Appium server
let isE2e: boolean | null = null

export async function getIsE2e() {
  if (env.ENV === 'production') {
    isE2e = false
  }
  if (isE2e === true || isE2e === false) {
    return isE2e
  }
  try {
    const response = await fetch('http://10.0.2.2/status', {
      mode: 'cors',
      headers: new Headers({
        accept: 'application/json',
      }),
    })
    isE2e = response.ok
  } catch (error) {
    isE2e = false
  }
  return isE2e
}

I have the following error:

TypeError: Network request failed

I expect to have the following JSON result:

{"value":{"build":{"version":"2.0.0-beta.46","git-sha":"258938ef66a2a49a4a400554a6dce890226ae34c","built":"2020-03-05 23:13:56 -0800"}}}

I do not use any proxy, this is the configuration:


The appium server listen on 0.0.0.0:4723:

tcp        0      0 0.0.0.0:4723            0.0.0.0:*               LISTEN      26721/node          

It work fine if I want to reach another service such as a running webpack dev server running on 0.0.0.0:3000

tcp        0      0 0.0.0.0:3000            0.0.0.0:*               LISTEN      30217/node               

Why can’t I contact the appium service ?

It appears you must allow clear text traffic from 10.0.2.2: https://medium.com/livefront/how-to-connect-your-android-emulator-to-a-local-web-service-47c380bff350

I understood it was an issue only with android app, since chrome android was able to contact the website, just android app failed to it.

I still believe this is a “workaround” but appium should think about adding an equivalent to navigator.webdriver