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.
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.