dotnet-client icon indicating copy to clipboard operation
dotnet-client copied to clipboard

A exception with a null response was thrown sending an HTTP request to the remote WebDriver server

Open Svrkota-S opened this issue 7 years ago • 11 comments

Description

Hi everyone, I'm trying to test Android app, but I currently have a problem I cannot resolve. This is the error I'm getting:

OpenQA.Selenium.WebDriverException: 'A exception with a null response was thrown sending an HTTP request to the remote WebDriver server for URL http://127.0.0.1:4723/wd/hub/session/590325fa-f414-47fe-bb52-be04e585cb97/elements. The status of the exception was SendFailure, and the message was: The underlying connection was closed: An unexpected error occurred on a send.'

Environment

Appium version: 1.8 Appium.WebDriver version: v3.0.0.2 Selenium.WebDriver version: 3.11 Selenium.Support version: 3.11 Emulator: Oreo 8.0 - API 26

Details

What's interesting is that sometimes one or both test succeed, but it happens rarely.

Code To Reproduce Issue [ Good To Have ]

using System;
    using Microsoft.VisualStudio.TestTools.UnitTesting;
    using OpenQA.Selenium.Appium.Service;
    using OpenQA.Selenium.Appium.Android;
    using OpenQA.Selenium.Appium.Service.Options;
    using System.IO;
    using OpenQA.Selenium.Remote;
    using OpenQA.Selenium.Appium.Enums;
    using OpenQA.Selenium.Support.UI;
    using OpenQA.Selenium.Appium;
    using System.Collections.ObjectModel;
    using OpenQA.Selenium;
    using System.Linq;

    namespace UnitTestProject1
    {
        [TestClass]
        public class UnitTest1
        {
            private static AndroidDriver<AndroidElement> _driver;

            [ClassInitialize]
            public static void ClassInitialize(TestContext context)
            {
                var args = new OptionCollector().AddArguments(GeneralOptionList.PreLaunch());;
                var desiredCaps = new DesiredCapabilities();
                desiredCaps.SetCapability(MobileCapabilityType.DeviceName, "MyDevice");
                desiredCaps.SetCapability(MobileCapabilityType.PlatformName, "Android");
                desiredCaps.SetCapability(MobileCapabilityType.PlatformVersion, "8.0");
                desiredCaps.SetCapability(MobileCapabilityType.App, @"C:\Users\User\Documents\Visual Studio 2017\Projects\UnitTestProject1\UnitTestProject1\bin\Debug\Resources\WikipediaSample.apk");
                _driver = new AndroidDriver<AndroidElement>(new Uri("http://127.0.0.1:4723/wd/hub"), desiredCaps);
            }

            [TestInitialize]
            public void TestInitialize()
            {
                if (_driver != null)
                {
                    _driver.ResetApp();
                }
            }

            [ClassCleanup]
            public static void ClassCleanup()
            {
                _driver.CloseApp();
            }

            [TestMethod]
            public void Test1()
            {
                AndroidElement searchElement = (AndroidElement)new WebDriverWait(_driver, TimeSpan.FromSeconds(30)).Until(
                    ExpectedConditions.ElementToBeClickable(MobileBy.AccessibilityId("Search Wikipedia"))
                );
                searchElement.Click();
                AndroidElement insertTextElement = (AndroidElement)new WebDriverWait(_driver, TimeSpan.FromSeconds(30)).Until(
                    ExpectedConditions.ElementToBeClickable(MobileBy.Id("org.wikipedia.alpha:id/search_src_text"))
                );
                insertTextElement.SendKeys("Serbia");
                System.Threading.Thread.Sleep(5000);

                ReadOnlyCollection<AndroidElement> results = _driver.FindElements(By.ClassName("android.widget.TextView"));
                Assert.IsTrue(results.ElementAt(1).Text.Equals("Serbia"));
            }

            [TestMethod]
            public void Test2()
            {
                AndroidElement searchElement = (AndroidElement)new WebDriverWait(_driver, TimeSpan.FromSeconds(30)).Until(
                    ExpectedConditions.ElementToBeClickable(MobileBy.AccessibilityId("Search Wikipedia"))
                );
                searchElement.Click();
                AndroidElement insertTextElement = (AndroidElement)new WebDriverWait(_driver, TimeSpan.FromSeconds(30)).Until(
                    ExpectedConditions.ElementToBeClickable(MobileBy.Id("org.wikipedia.alpha:id/search_src_text"))
                );
                insertTextElement.SendKeys("USA");
                System.Threading.Thread.Sleep(5000);

                ReadOnlyCollection<AndroidElement> results = _driver.FindElements(By.ClassName("android.widget.TextView"));
                Assert.IsTrue(results.ElementAt(1).Text.Equals("United States"));
            }
        }
    }

Svrkota-S avatar Nov 01 '18 11:11 Svrkota-S

This is a bug, which I have a fix for. I need to run tests and make PR.

laolubenson avatar Nov 01 '18 12:11 laolubenson

This is a bug, which I have a fix for. I need to run tests and make PR.

Hi, is there any progress on this fix?

OrestFi avatar Jan 28 '19 13:01 OrestFi

This is a bug, which I have a fix for. I need to run tests and make PR.

Hi, is there any progress on this fix?

ArmyMedalMei avatar Jan 29 '19 11:01 ArmyMedalMei

Adding in my own "any movement on this?" It would be very, very nice to not have to make allowance for this random failure anymore!

ElDuderino250 avatar Apr 16 '19 20:04 ElDuderino250

Any update on this? I'm also encountering this issue. Thanks!

srcd4 avatar Jun 07 '19 17:06 srcd4

I could no longer reproduce this. Please try v4+ available via nuget, and comment If issue still exists

laolubenson avatar Dec 11 '19 23:12 laolubenson

I'm using Appium Driver 4.1.1 but still the issue persists.

coolvasanth avatar Apr 07 '20 08:04 coolvasanth

I have updated to latest version - 4.1.1 and the issue still persists. Kindly help me.

coolvasanth avatar Apr 07 '20 08:04 coolvasanth

@coolvasanth Can you post gists of your, reproduction code, stack trace and appium logs?

laolubenson avatar Apr 07 '20 08:04 laolubenson

Hi I have added Appium log in this Gist. I have added log only when I'm getting above error.

Environment Information:

Platform: Android Appium Version: 1.15.1 (Desktop software) App development platform: Ionic (Version 4) Testing Framework: BDD (Behavioral driven development) Chrome Driver: 2.33

Scenario: Above error is not common. Sometimes it works fine, but most of the time it fails. If I'm running many cases at a time then randomly one or two will pass. And most will fail.

coolvasanth avatar Apr 07 '20 12:04 coolvasanth

@coolvasanth Sorry, I didn't get a notification for your reply. Your log highlights that there were no web views available.See line 4-6. I can't tell what operation you were trying to perform at that point or before

laolubenson avatar Nov 16 '20 11:11 laolubenson

@Svrkota-S Can you please try with appium web driver v5 beta? If this issue still repro, I'll take a look

Dor-bl avatar Nov 19 '22 08:11 Dor-bl

Closed since no response.

Dor-bl avatar Dec 17 '22 13:12 Dor-bl