Forum Xamarin Test Cloud (Read Only)

HttpRequestException: workaround, solution, or open feature request for this exception?

When I run our test suite locally using a physical device I often see this exception when running Android tests.

    Message: SetUp : System.Net.Http.HttpRequestException : An error occurred while sending the request.
      ----> System.Net.WebException : The underlying connection was closed: The connection was closed unexpectedly.

This causes the test to fail before it's able to perform the first action. What's strange is when I run the entire suite a few tests might fail with this exception, but the prior or following test will pass with no issues, then this exception won't resurface for a few more tests. This is especially frustrating when some test fixtures are set up to test data or settings persisting between tests in the same fixture.

We have our build servers set up to run UI tests incrementally (nightly and per pull request via GitHub integration) and it's frustrating to see failed tests that have nothing to do with the performance of our app or test scripts.

My question:

Does anyone have a workaround for this issue, or a feature request that's seeing some attention? The closest related issue I've seen on the forums is from Emmanuel Huna with a corresponding feature request as well, but it hasn't seen much attention since he posted it.

Device specific information:

This issue occurs on my Windows vm (Windows 10 & VS 2017) and my primary Mac install (Sierra & VS for Mac)

Doesn't seem to be device specific as it happens on Emulators and physical devices (Android 5, 6, 7) on a variety of make and model phones.


  • LewisKLewisK USUniversity ✭✭
    edited October 2017

    Just clarifying is this when the UI Test sends the instructions to the device or when the device attempts to send a network request?

    If you are using network calls is it possible to use a fake/mock service. UI Tests generally shouldn't require network calls as then that's more of an integration test. Quite alot of work but then the tests would be far more reliable and faster since you don't have to wait for response.

  • jgcook935jgcook935 USMember ✭✭

    Hey Lewis, thanks for replying. This is when I'm running the UI tests so the UI test is sending instructions to the device. More often than not, I can retry the same test on the same device directly after this exception is thrown and the UI test will send the instructions with no issues. I can post the whole stacktrace if you think that would help :smile:

  • LewisKLewisK USUniversity ✭✭
    edited October 2017

    Are you running the latest UITest packages etc?
    If android make sure you have the internet permission and check monitor/logcat for errors.

  • jgcook935jgcook935 USMember ✭✭

    We're currently running 2.1.3, but this error has occurred on every version of Xamarin UI test we've used thus far. We have internet permissions enabled, but I'll try to find some other errors to bring to this thread.

  • jgcook935jgcook935 USMember ✭✭

    I've confirmed this issue also occurs on Xamarin.UITest 2.1.4. Does anyone else have any ideas on how to fix this?

  • wend0rlinwend0rlin DEMember ✭✭

    I had the same problem, my current solution is using Xamarin.UITest 1.3.8, this NuGet package works fine!

  • PeterSimonsPeterSimons GBMember ✭✭

    We have this problem too and have had it since we started using ui test, we're using uitest 2.2.2 I was in contact with support about it but the trail went dead

Sign In or Register to comment.