0

So I have this automation test which I want to run against a local physical device to test the concept. The test is a C#/Selenium script thus

The device is a Galaxy Tab S 10 and UDB debugging is enabled and this device can be seen in Windows Explorer enter image description here And in Android Studio thus enter image description here

Device name is Tab, model number SM-T805 and Android version is 5.0.2

Now when I try to connect to the device in Visual Studio with this code

            var options = new ChromeOptions();
            options.PlatformName = "Android";
            options.AddAdditionalChromeOption("deviceName", "Tab");
            options.AddAdditionalChromeOption("PlatformName", "Android");
            options.AddAdditionalChromeOption("platformVersion", "5.0.2");
            options.AddAdditionalChromeOption("isRealMobile", true);
            options.AddAdditionalChromeOption("network", false);
            Uri url = new Uri("http://127.0.0.1:5037/wd/hub");
            _driver = new RemoteWebDriver(url, options);

I get this error

OpenQA.Selenium.WebDriverException: 'An unknown exception was encountered sending an HTTP request to the remote WebDriver server for URL http://127.0.0.1:5037/wd/hub/session. The exception message was: An error occurred while sending the request.'

So my first thought is, am I using the correct port (5037) and how do I confirm what port the tab is listening on?

Apart from that has anyone got any ideas what I am doing wrong please? Thanks in advance….

This is the call stack

TestApp.Regression.dll!TheTest.Hooks.BeforeTheMobileFeature(string title, string osver, string device, string browser, string deviceOrientation) Line 91    C#
 TestApp.Regression.dll!TheTest.Hooks.BeforeFeatureTabA7(TechTalk.SpecFlow.FeatureContext featureContext) Line 52   C#
    [Native to Managed Transition]  
    [Managed to Native Transition]  
    System.Private.CoreLib.dll!System.Delegate.DynamicInvokeImpl(object[] args) Unknown
    TechTalk.SpecFlow.dll!TechTalk.SpecFlow.Bindings.SynchronousBindingDelegateInvoker.InvokeBindingDelegateSync(System.Delegate bindingDelegate, object[] invokeArgs)  Unknown
    TechTalk.SpecFlow.dll!TechTalk.SpecFlow.Bindings.SynchronousBindingDelegateInvoker.InvokeDelegateSynchronously(System.Delegate bindingDelegate, object[] invokeArgs)    Unknown
    TechTalk.SpecFlow.dll!TechTalk.SpecFlow.Bindings.BindingInvoker.InvokeBinding(TechTalk.SpecFlow.Bindings.IBinding binding, TechTalk.SpecFlow.Infrastructure.IContextManager contextManager, object[] arguments, TechTalk.SpecFlow.Tracing.ITestTracer testTracer, out System.TimeSpan duration) Unknown
    TechTalk.SpecFlow.dll!TechTalk.SpecFlow.Infrastructure.TestExecutionEngine.InvokeHook(TechTalk.SpecFlow.Bindings.IBindingInvoker invoker, TechTalk.SpecFlow.Bindings.IHookBinding hookBinding, TechTalk.SpecFlow.Bindings.HookType hookType)    Unknown
    TechTalk.SpecFlow.dll!TechTalk.SpecFlow.Infrastructure.TestExecutionEngine.FireEvents(TechTalk.SpecFlow.Bindings.HookType hookType) Unknown
    TechTalk.SpecFlow.dll!TechTalk.SpecFlow.Infrastructure.TestExecutionEngine.OnFeatureStart(TechTalk.SpecFlow.FeatureInfo featureInfo)    Unknown
    TechTalk.SpecFlow.dll!TechTalk.SpecFlow.TestRunner.OnFeatureStart(TechTalk.SpecFlow.FeatureInfo featureInfo)    Unknown
    TestApp.Regression.dll!TestApp.Regression.Features.GalaxyTab7Feature.FeatureSetup(Microsoft.VisualStudio.TestTools.UnitTesting.TestContext testContext) Unknown
    [Native to Managed Transition]  
    [Managed to Native Transition]  
    Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.dll!Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Extensions.MethodInfoExtensions.InvokeAsSynchronousTask(System.Reflection.MethodInfo methodInfo, object classInstance, object[] parameters)   Unknown
    Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.dll!Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Execution.TestClassInfo.RunClassInitialize(Microsoft.VisualStudio.TestTools.UnitTesting.TestContext testContext)  Unknown
    Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.dll!Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Execution.TestMethodRunner.Execute()  Unknown
    Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.dll!Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Execution.UnitTestRunner.RunSingleTest(Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.ObjectModel.TestMethod testMethod, System.Collections.Generic.IDictionary<string, object> testContextProperties)    Unknown
    Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.dll!Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Execution.TestExecutionManager.ExecuteTestsWithTestRunner(System.Collections.Generic.IEnumerable<Microsoft.VisualStudio.TestPlatform.ObjectModel.TestCase> tests, Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter.IRunContext runContext, Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter.ITestExecutionRecorder testExecutionRecorder, string source, System.Collections.Generic.IDictionary<string, object> sourceLevelParameters, Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Execution.UnitTestRunner testRunner)  Unknown
    Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.dll!Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Execution.TestExecutionManager.ExecuteTestsInSource(System.Collections.Generic.IEnumerable<Microsoft.VisualStudio.TestPlatform.ObjectModel.TestCase> tests, Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter.IRunContext runContext, Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter.IFrameworkHandle frameworkHandle, string source, bool isDeploymentDone)   Unknown
    Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.dll!Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Execution.TestExecutionManager.ExecuteTests(System.Collections.Generic.IEnumerable<Microsoft.VisualStudio.TestPlatform.ObjectModel.TestCase> tests, Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter.IRunContext runContext, Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter.IFrameworkHandle frameworkHandle, bool isDeploymentDone)  Unknown
    Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.dll!Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Execution.TestExecutionManager.RunTests(System.Collections.Generic.IEnumerable<Microsoft.VisualStudio.TestPlatform.ObjectModel.TestCase> tests, Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter.IRunContext runContext, Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter.IFrameworkHandle frameworkHandle, Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.TestRunCancellationToken runCancellationToken)   Unknown
    Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.dll!Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.MSTestExecutor.RunTests(System.Collections.Generic.IEnumerable<Microsoft.VisualStudio.TestPlatform.ObjectModel.TestCase> tests, Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter.IRunContext runContext, Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter.IFrameworkHandle frameworkHandle) Unknown
    Microsoft.TestPlatform.CrossPlatEngine.dll!Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Execution.RunTestsWithTests.InvokeExecutor(Microsoft.VisualStudio.TestPlatform.Common.ExtensionFramework.Utilities.LazyExtension<Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter.ITestExecutor, Microsoft.VisualStudio.TestPlatform.Common.Interfaces.ITestExecutorCapabilities> executor, System.Tuple<System.Uri, string> executorUri, Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Adapter.RunContext runContext, Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter.IFrameworkHandle frameworkHandle)    Unknown
    Microsoft.TestPlatform.CrossPlatEngine.dll!Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Execution.BaseRunTests.RunTestInternalWithExecutors(System.Collections.Generic.IEnumerable<System.Tuple<System.Uri, string>> executorUriExtensionMap, long totalTests)   Unknown
    Microsoft.TestPlatform.CrossPlatEngine.dll!Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Execution.BaseRunTests.RunTestsInternal()    Unknown
    Microsoft.TestPlatform.CrossPlatEngine.dll!Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Execution.BaseRunTests.RunTests()    Unknown
    Microsoft.TestPlatform.CrossPlatEngine.dll!Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Execution.ExecutionManager.StartTestRun(System.Collections.Generic.IEnumerable<Microsoft.VisualStudio.TestPlatform.ObjectModel.TestCase> tests, string package, string runSettings, Microsoft.VisualStudio.TestPlatform.ObjectModel.Engine.ClientProtocol.TestExecutionContext testExecutionContext, Microsoft.VisualStudio.TestPlatform.ObjectModel.Engine.ITestCaseEventsHandler testCaseEventsHandler, Microsoft.VisualStudio.TestPlatform.ObjectModel.Client.IInternalTestRunEventsHandler runEventsHandler) Unknown
    Microsoft.TestPlatform.CrossPlatEngine.dll!Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.TestRequestHandler.OnMessageReceived.AnonymousMethod__4() Unknown
    Microsoft.TestPlatform.CrossPlatEngine.dll!Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.TestRequestHandler..ctor.AnonymousMethod__30_2(System.Action action)  Unknown
    Microsoft.TestPlatform.CoreUtilities.dll!Microsoft.VisualStudio.TestPlatform.Utilities.JobQueue<System.Action>.SafeProcessJob(System.Action job)    Unknown
    Microsoft.TestPlatform.CoreUtilities.dll!Microsoft.VisualStudio.TestPlatform.Utilities.JobQueue<System.Action>.BackgroundJobProcessor(string threadName)    Unknown
    Microsoft.TestPlatform.CoreUtilities.dll!Microsoft.VisualStudio.TestPlatform.Utilities.JobQueue<System.__Canon>..ctor.AnonymousMethod__16_0()   Unknown
    System.Private.CoreLib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state)   Unknown
    System.Private.CoreLib.dll!System.Threading.Tasks.Task.ExecuteWithThreadLocal(ref System.Threading.Tasks.Task currentTaskSlot, System.Threading.Thread threadPoolThread)    Unknown
kaliiiiiiiii
  • 925
  • 1
  • 2
  • 21
Kev
  • 121
  • 3
  • 20
  • The call stack is in reverse order with first row the last thing that happens and the last row the first thing that happens. So you are getting error due to threadPoolThread Unknown. When you make a connection a Connection Pool is created. It looks like your connection is not completing. Normally with a HTTP you send a request and then get back a response. You are not getting any response since the connection is not completing. This can mean a few thing 1) Server not working 2) Route to server is not working 3) You are sending HTTP and server want HTTPS. – jdweng Mar 04 '23 at 21:17
  • To see if server is running from cmd.exe >NetStat -A which will give a list of UDP and TCP ports. Check for TCP port 5037. HTTP uses TCP for transport layer. Port 127.0.0.1 is the loopback port. Every Ethernet device requires a loopback IP. So you are trying to connect to the loopback on your local machine. I'm not familiar with the syntax "/wd/hub". Looks like it is the driver name and must match the name of the driver. See : https://stackoverflow.com/questions/51997192/what-is-wd-hub-while-creating-an-instance-of-androiddriver-through-appium – jdweng Mar 04 '23 at 21:23
  • Thanks @jdweng I will look at that, anyone else got anything? – Kev Mar 06 '23 at 21:25

1 Answers1

1

For python, the following script works for me:

from selenium import webdriver

options = webdriver.ChromeOptions()

options.add_experimental_option('androidPackage', 'com.android.chrome')

driver = webdriver.Chrome(options=options)

resource

Seems to me like you're missing the specification of the android package in your code.

answer provides a approach as following:

ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.AddAdditionalCapability("androidPackage", "com.android.chrome");

driver = new RemoteWebDriver(new Uri("http://seleniumhubaddress:4444/wd/hub"), chromeOptions.ToCapabilities());

maybe post helps you:)

Note: I didn't test it, since I never worked with C#, if it doesn't work, feel free to comment and I'll edit my answer.

kaliiiiiiiii
  • 925
  • 1
  • 2
  • 21
  • Sorry for the late response kaliiiiiiiii, I have tried that but still the same issue – Kev Mar 10 '23 at 08:54