在 C# 和 SpecFlow 中创建 RemoteWebDriver 实例的问题
Issue creating RemoteWebDriver instance in C# and SpecFlow
我正在用头撞墙尝试在我的 selenium C# 项目中使用 RemoteWebDriver 实例。每当我 运行 我的测试我得到 'Object reference not set to an instance of an object'
我用以下内容启动了我的中心...
java -jar "C:\Selenium Grid\selenium-server-standalone-3.4.0.jar" -role hub
使用以下内容启动我的节点...
java -Dwebdriver.chrome.driver=C:\WebDrivers\chromedriver.exe -jar "C:\Selenium Grid\selenium-server-standalone-3.4.0.jar" -role webdriver -hub http://10.0.75.1:4444/grid/register -browser browserName=chrome,platform=WINDOWS -port 5557
Hub 主页....
然后我在单元测试文件中有以下代码....
[Binding]
public sealed class Hooks {
private readonly IObjectContainer _objectContainer;
private IWebDriver _driver;
private PersonDetails _personDetails;
public Hooks(IObjectContainer objectContainer) {
_objectContainer = objectContainer;
}
[BeforeScenario]
public void BeforeScenario()
{
//_driver = new ChromeDriver();
var capabilities = new DesiredCapabilities();
capabilities.SetCapability(CapabilityType.BrowserName, "chrome");
capabilities.SetCapability(CapabilityType.Version, "53.0");
capabilities.SetCapability(CapabilityType.Platform, "Windows 10");
_driver = new RemoteWebDriver(new Uri("http://localhost:4444/wd/hub"),capabilities, TimeSpan.FromSeconds(600));
_objectContainer.RegisterInstanceAs<IWebDriver>(_driver);
_personDetails = new PersonDetails {
Name = "Barry",
Age = 25
};
_objectContainer.RegisterInstanceAs<PersonDetails>(_personDetails);
}
[AfterScenario]
public void AfterScenario()
{
_driver.Quit();
}
}
一直在这条线上摔倒
_driver = new RemoteWebDriver(new Uri("http://localhost:4444/wd/hub"),capabilities, TimeSpan.FromSeconds(600));
出现以下错误...
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, TimeSpan commandTimeout)
at SeleniumLoadable.Step_Definitions.Hooks.BeforeScenario() in C:\Users\matty\OneDrive\Visual Studio Projects\SeleniumLoadable\SeleniumLoadable\Step Definitions\Hooks.cs:line 33
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.FireEvents(HookType bindingEvent)
at TechTalk.SpecFlow.Infrastructure.TestExecutionEngine.OnScenarioStart(ScenarioInfo scenarioInfo)
at TechTalk.SpecFlow.TestRunner.OnScenarioStart(ScenarioInfo scenarioInfo)
at SeleniumLoadable.Features.ParallelFeature.ScenarioSetup(ScenarioInfo scenarioInfo)
at SeleniumLoadable.Features.ParallelFeature.AddMoreNumbers() in C:\Users\matty\OneDrive\Visual Studio Projects\SeleniumLoadable\SeleniumLoadable\Features\Parallel.feature:line 7
--TearDown
at SeleniumLoadable.Step_Definitions.Hooks.AfterScenario() in C:\Users\matty\OneDrive\Visual Studio Projects\SeleniumLoadable\SeleniumLoadable\Step Definitions\Hooks.cs:line 46
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.FireEvents(HookType bindingEvent)
at TechTalk.SpecFlow.Infrastructure.TestExecutionEngine.OnScenarioEnd()
at TechTalk.SpecFlow.TestRunner.OnScenarioEnd()
at SeleniumLoadable.Features.ParallelFeature.ScenarioTearDown()
Result Message:
System.InvalidOperationException :
TearDown : System.NullReferenceException : Object reference not set to an instance of an object.
有人知道我做错了什么吗?
好的,这是更新:
硒 3.4.0-Java:
https://github.com/SeleniumHQ/selenium/issues/3946
硒 3.4.0-C#:
https://github.com/SeleniumHQ/selenium/issues/3939
c# nuget 版本 3.4.0 中的远程 WebDriver 实例
https://github.com/SeleniumHQ/selenium/issues/3929
希望这些信息对您有所帮助:)
我正在用头撞墙尝试在我的 selenium C# 项目中使用 RemoteWebDriver 实例。每当我 运行 我的测试我得到 'Object reference not set to an instance of an object'
我用以下内容启动了我的中心...
java -jar "C:\Selenium Grid\selenium-server-standalone-3.4.0.jar" -role hub
使用以下内容启动我的节点...
java -Dwebdriver.chrome.driver=C:\WebDrivers\chromedriver.exe -jar "C:\Selenium Grid\selenium-server-standalone-3.4.0.jar" -role webdriver -hub http://10.0.75.1:4444/grid/register -browser browserName=chrome,platform=WINDOWS -port 5557
Hub 主页....
然后我在单元测试文件中有以下代码....
[Binding]
public sealed class Hooks {
private readonly IObjectContainer _objectContainer;
private IWebDriver _driver;
private PersonDetails _personDetails;
public Hooks(IObjectContainer objectContainer) {
_objectContainer = objectContainer;
}
[BeforeScenario]
public void BeforeScenario()
{
//_driver = new ChromeDriver();
var capabilities = new DesiredCapabilities();
capabilities.SetCapability(CapabilityType.BrowserName, "chrome");
capabilities.SetCapability(CapabilityType.Version, "53.0");
capabilities.SetCapability(CapabilityType.Platform, "Windows 10");
_driver = new RemoteWebDriver(new Uri("http://localhost:4444/wd/hub"),capabilities, TimeSpan.FromSeconds(600));
_objectContainer.RegisterInstanceAs<IWebDriver>(_driver);
_personDetails = new PersonDetails {
Name = "Barry",
Age = 25
};
_objectContainer.RegisterInstanceAs<PersonDetails>(_personDetails);
}
[AfterScenario]
public void AfterScenario()
{
_driver.Quit();
}
}
一直在这条线上摔倒
_driver = new RemoteWebDriver(new Uri("http://localhost:4444/wd/hub"),capabilities, TimeSpan.FromSeconds(600));
出现以下错误...
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, TimeSpan commandTimeout)
at SeleniumLoadable.Step_Definitions.Hooks.BeforeScenario() in C:\Users\matty\OneDrive\Visual Studio Projects\SeleniumLoadable\SeleniumLoadable\Step Definitions\Hooks.cs:line 33
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.FireEvents(HookType bindingEvent)
at TechTalk.SpecFlow.Infrastructure.TestExecutionEngine.OnScenarioStart(ScenarioInfo scenarioInfo)
at TechTalk.SpecFlow.TestRunner.OnScenarioStart(ScenarioInfo scenarioInfo)
at SeleniumLoadable.Features.ParallelFeature.ScenarioSetup(ScenarioInfo scenarioInfo)
at SeleniumLoadable.Features.ParallelFeature.AddMoreNumbers() in C:\Users\matty\OneDrive\Visual Studio Projects\SeleniumLoadable\SeleniumLoadable\Features\Parallel.feature:line 7
--TearDown
at SeleniumLoadable.Step_Definitions.Hooks.AfterScenario() in C:\Users\matty\OneDrive\Visual Studio Projects\SeleniumLoadable\SeleniumLoadable\Step Definitions\Hooks.cs:line 46
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.FireEvents(HookType bindingEvent)
at TechTalk.SpecFlow.Infrastructure.TestExecutionEngine.OnScenarioEnd()
at TechTalk.SpecFlow.TestRunner.OnScenarioEnd()
at SeleniumLoadable.Features.ParallelFeature.ScenarioTearDown()
Result Message:
System.InvalidOperationException :
TearDown : System.NullReferenceException : Object reference not set to an instance of an object.
有人知道我做错了什么吗?
好的,这是更新:
硒 3.4.0-Java: https://github.com/SeleniumHQ/selenium/issues/3946
硒 3.4.0-C#: https://github.com/SeleniumHQ/selenium/issues/3939
c# nuget 版本 3.4.0 中的远程 WebDriver 实例 https://github.com/SeleniumHQ/selenium/issues/3929
希望这些信息对您有所帮助:)