A exception with a null response was thrown sending an HTTP request to the remote WebDriver server
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"));
}
}
}
This is a bug, which I have a fix for. I need to run tests and make PR.
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?
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?
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!
Any update on this? I'm also encountering this issue. Thanks!
I could no longer reproduce this. Please try v4+ available via nuget, and comment If issue still exists
I'm using Appium Driver 4.1.1 but still the issue persists.
I have updated to latest version - 4.1.1 and the issue still persists. Kindly help me.
@coolvasanth Can you post gists of your, reproduction code, stack trace and appium logs?
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 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
@Svrkota-S Can you please try with appium web driver v5 beta? If this issue still repro, I'll take a look
Closed since no response.