我最近接手了一个项目,该项目在其自动化框架中使用BrowserStack进行移动测试。我们使用的代理出现故障,所以我不得不将系统代理更改为工作代理,我不确定它们是否相关,但这是有道理的。
我以前更改过代理并且没有任何问题,所以不确定为什么现在会发生这种情况。将 C# 与硒一起使用,所有浏览器都会出错。我对框架的浏览器堆栈方面不太了解,因为第一次使用它。
Result StackTrace:
at OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse)
at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
at OpenQA.Selenium.Remote.RemoteWebDriver.StartSession(ICapabilities desiredCapabilities)
at OpenQA.Selenium.Remote.RemoteWebDriver..ctor(ICommandExecutor commandExecutor, ICapabilities desiredCapabilities)
at OpenQA.Selenium.Remote.RemoteWebDriver..ctor(Uri remoteAddress, ICapabilities desiredCapabilities)
at Framework.CoreUtilities.CustomRemoteWebDriver..ctor(Uri remoteAddress, ICapabilities desiredCapabilities) in FrameworkDriverMethodsCustomRemoteWebDriver.cs:line 12
at Framework.CoreUtilities.BrowserStackDriverUtility.Init(String profile, String environment) in FrameworkDriverMethodsBrowserStackDriverUtility.cs:line 43
at Tests.CoreUtilities.DriverMethods.EnvironmentHooks.BrowserStackHooks.SelectBrowserStackDriver() in FrameworkDriverMethodsEnvironmentHooksBrowserStackHooks.cs:line 29
at Tests.CoreUtilities.DriverMethods.EnvHooks.BeforeScenarioLocal() in FrameworkEnvHooks.cs:line 43
at lambda_method(Closure , IContextManager )
at TechTalk.SpecFlow.Bindings.BindingInvoker.InvokeBinding(IBinding binding, IContextManager contextManager, Object[] arguments, ITestTracer testTracer, TimeSpan& duration)
at TechTalk.SpecFlow.Infrastructure.TestExecutionEngine.InvokeHook(IBindingInvoker invoker, IHookBinding hookBinding, HookType hookType)
at TechTalk.SpecFlow.Infrastructure.TestExecutionEngine.FireEvents(HookType hookType)
at TechTalk.SpecFlow.Infrastructure.TestExecutionEngine.FireScenarioEvents(HookType bindingEvent)
at TechTalk.SpecFlow.Infrastructure.TestExecutionEngine.OnScenarioStart(ScenarioInfo scenarioInfo)
at TechTalk.SpecFlow.TestRunner.OnScenarioStart(ScenarioInfo scenarioInfo)
at Tests.Features.Sprint3.S03_SNO3519_View_All_Bills_MOBILEFeature.ScenarioSetup(ScenarioInfo scenarioInfo) in TestsFeaturesSprint3S03_SNO3519_View_all_bills_MOBILE.feature.cs:line 0
at Tests.Features.Sprint3.S03_SNO3519_View_All_Bills_MOBILEFeature.TC5_TC6_TC7_Verify_The_Functionality_Of_The_Dropdown_Filter_On_The_All_My_Bills_Page(String email, String password, String accountNumber, String accountType, String[] exampleTags) in TestsFeaturesSprint3S03_SNO3519_View_all_bills_MOBILE.feature:line 10
--TearDown
at BoDi.ObjectContainer.TypeRegistration.Resolve(ObjectContainer container, RegistrationKey keyToResolve, ResolutionList resolutionPath)
at BoDi.ObjectContainer.ResolveObject(RegistrationKey keyToResolve, ResolutionList resolutionPath)
at BoDi.ObjectContainer.Resolve(Type typeToResolve, ResolutionList resolutionPath, String name)
at BoDi.ObjectContainer.<>c__DisplayClass55_0.<ResolveArguments>b__0(ParameterInfo p)
at System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext()
at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
at BoDi.ObjectContainer.ResolveArguments(IEnumerable`1 parameters, RegistrationKey keyToResolve, ResolutionList resolutionPath)
at BoDi.ObjectContainer.CreateObject(Type type, ResolutionList resolutionPath, RegistrationKey keyToResolve)
at BoDi.ObjectContainer.TypeRegistration.Resolve(ObjectContainer container, RegistrationKey keyToResolve, ResolutionList resolutionPath)
at BoDi.ObjectContainer.ResolveObject(RegistrationKey keyToResolve, ResolutionList resolutionPath)
at BoDi.ObjectContainer.Resolve(Type typeToResolve, ResolutionList resolutionPath, String name)
at BoDi.ObjectContainer.Resolve(Type typeToResolve, String name)
at TechTalk.SpecFlow.Infrastructure.TestObjectResolver.ResolveBindingInstance(Type bindingType, IObjectContainer container)
at TechTalk.SpecFlow.ScenarioContext.GetBindingInstance(Type bindingType)
at Tests.CoreUtilities.DriverMethods.EnvHooks.AfterEachFeature() in FrameworkEnvHooks.cs:line 83
at lambda_method(Closure , IContextManager )
at TechTalk.SpecFlow.Bindings.BindingInvoker.InvokeBinding(IBinding binding, IContextManager contextManager, Object[] arguments, ITestTracer testTracer, TimeSpan& duration)
at TechTalk.SpecFlow.Infrastructure.TestExecutionEngine.InvokeHook(IBindingInvoker invoker, IHookBinding hookBinding, HookType hookType)
at TechTalk.SpecFlow.Infrastructure.TestExecutionEngine.FireEvents(HookType hookType)
at TechTalk.SpecFlow.Infrastructure.TestExecutionEngine.FireScenarioEvents(HookType bindingEvent)
at TechTalk.SpecFlow.Infrastructure.TestExecutionEngine.OnScenarioEnd()
at TechTalk.SpecFlow.TestRunner.OnScenarioEnd()
at Tests.Features.Sprint3.S03_SNO3519_View_All_Bills_MOBILEFeature.ScenarioTearDown() in TestsFeaturesSprint3S03_SNO3519_View_all_bills_MOBILE.feature.cs:line 0
Result Message:
OpenQA.Selenium.WebDriverException : Unexpected error. <HEAD><TITLE>Authorization Required</TITLE></HEAD>
<BODY BGCOLOR="white" FGCOLOR="black"><H1>Authorization Required</H1><HR>
<FONT FACE="Helvetica,Arial"><B>
Description: Authorization is required for access to this proxy</B></FONT>
<HR>
<!-- default "Authorization Required" response (401) -->
</BODY>
TearDown : BoDi.ObjectContainerException : Interface cannot be resolved: OpenQA.Selenium.IWebDriver (resolution path: Framework.SeleniumContext)
这似乎是特定于 selenium 语言绑定如何生成有效负载以及浏览器堆栈如何在其末尾解析它的问题。
根据您共享的错误消息,很可能在解析请求有效负载时,浏览器堆栈无法找到您的用户名和访问密钥
您可以按照下面提到的步骤进行调试:
-
将线路驱动程序 = new RemoteWebDriver(new Uri("https://hub-cloud.browserstack.com/wd/hub/"(, options(更改为 driver = new RemoteWebDriver( 新 Uri("http://localhost:4444/wd/hub/"(, 选项 );.您不需要在本地启动硒独立罐。
-
启动一个在 localhost:4444 上读取流量的代理。(如果需要,您可以使用基于节点的实现来实现相同的内容。这是一个这样的实现:https://gist.github.com/hanikhan/f817bd64b063129cb78dc7ed0b66fdb7(
-
观察您正在使用的 Selenium 客户端绑定生成的请求有效负载(您提到的 v3.14(。例如,我的基于 java 的 selenium 客户端在只传递浏览器时生成这个 是 desiredcapabitlies {"desiredCapabilities
":{"browserName":"Chrome"},"capabilities":{"firstMatch":[{"browserName":"Chrome"}]}} -
现在降级你的硒绑定(到它正在工作的版本(并观察它生成的有效载荷。
检查客户端绑定是否使用严格的检查,因此某些必需的功能会在您的终端被丢弃。
如果这是真的,那么您将需要执行以下操作:
- 提出 Selenium C# 绑定的问题,以删除对案例的严格检查