Selenium网格不适用于菜鸟示例

时间:2017-08-24 13:21:21

标签: selenium selenium-grid

我无法让Selenium网格正常工作。我在下方提供了屏幕截图来帮助。任何人都可以看到什么是错的?我几乎放弃了,看看那些我在下面尝试过的教程/文章/视频应该有效,但事实并非如此。任何人都可以建议吗? 感谢

更新

在这个简短的YouTube视频https://www.youtube.com/watch?v=zhWhhDnR1Bg

中观看问题

服务器jar文件位置

Selenium server standalone location

启动selenium服务器的命令

starting the server

启动服务器后

C# exception

问题更新

An exception of type 'OpenQA.Selenium.WebDriverException' occurred in WebDriver.dll but was not handled in user code

Additional information: Unexpected error. System.Net.WebException: Unable to connect to the remote server ---> System.Net.Sockets.SocketException: The requested address is not valid in its context 0.0.0.0:4444

at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress)

at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Exception& exception)

--- End of inner exception stack trace ---

at System.Net.HttpWebRequest.GetRequestStream(TransportContext& context)
at System.Net.HttpWebRequest.GetRequestStream()
at OpenQA.Selenium.Remote.HttpCommandExecutor.Execute(Command commandToExecute)
at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)

新的控制台应用

启动selenium hub和节点后执行此新代码会引发异常:

static void Main(string[] args)
{
    var url = new Uri("http://10.6.122.49:4444/wd/hub");

    var driver = new RemoteWebDriver(url, new FirefoxOptions());  // This line throws an exception

    driver.Navigate().GoToUrl("http://www.google.com");

 }

尽管错误仍然存​​在,但已尝试过以下操作

Environment.SetEnvironmentVariable("webdriver.gecko.driver", @"D:\geckodriver.exe");

尝试使用curl命令后

$ curl -i -H“接受:application / json”-X POST -d'{“desiredCapabilities”:{“bro   %总收到百分比%Xferd平均速度时间时间当前时间                                  Dload上载总左转速度   0 0 0 0 0 0 0 0 - : - : - - : - : - - : - : - 0HT 日期:2017年9月29日星期五15:27:00 GMT 到期日:1970年1月1日星期四00:00:00 GMT 缓存控制:无缓存 Content-Type:application / json; charset = utf-8 服务器:码头(9.4.3.v20170317) 内容长度:5374

{“state”:“unknown error”,“sessionId”:null,“hCode”:11474323,“value”:{“localizedMee从https://github.com/mozilla/geckodriver/releases下载”,“cause”:null,java.lang .StackTraceElement “},{” 文件名 “:” DriverService.java “ ”nativeMethod“:faDriverService.java”, “nativeMethod”:假的, “方法名”: “访问$ 100”, “类名”: “”: “findDefaultExecutable” , “类名”: “org.openqa.selenium.firefox.GeckoDriverSelenium.remote.service.DriverService $生成器”, “hCode”:778286220, “行号”:330,44, “行号”:207, “下课”:” java.lang.StackTraceElement中 “},{” 文件名 “:” FirefoxDeName “:” FirefoxDriver.java “ ”nativeMethod“:假, ”方法名“: ”“, ”classNamssName“: ”sun.reflect.NativeConstructorAccessorImpl“,” hCode “:513928194” lineNumbeumber “: - 1,” 类 “:” java.lang.StackTraceElement中 “},{” 文件名 “:NULL,” nativeMethod “veMethod”:假, “方法名”: “的newInstance”, “类名” : “java.lang.reflect.Constr.openqa.selenium.remote.server.FirefoxDriverProvider”, “hCode”:380089702, “lineNumriverProvider”, “hCode”: - 616843603, “行号”:63, “阶级”:“的java .lang.StackTraceENumbe r“:60,”class“:”java.lang.StackTraceElement“},{”fileName“:”DefaultSession.ja100 5423 100 5374 100 49 42992 392 - : - : - - : - : - - : - : - 48854m​​ed“:false,”methodName“:”run“,”className“:”java.util.concurrent.FutureTask“,”hCodeaultSession $ 1“,”hCode“: - 255143467,”lineNumber“ :176, “阶级”: “java.lang.StackTraceeElement”},{ “文件名”:空, “nativeMethod”:假的, “方法名”: “运行”, “类名” :: “的java.lang.Thread”, “hCode”:1432591020, “行号”: - 1, “下课”:“java.lang.StackTkodriver。最新版本可以从https://github.com/mozilla/g

下载

1 个答案:

答案 0 :(得分:0)

错误The requested address is not valid in its context表示IP地址可能无效。我发现是The requested address is not valid in its context when i try to listen a port

在您启动集线器的命令提示符中,您会注意到这样一行Nodes should register to http://10.6.122.49:4444

在测试中,您可以尝试使用IP 10.6.122.49而不是localhost来实例化RemoteWebDriver。

我希望你已经启动了节点并让它自己注册到集线器。

在某些机器上(特别是在MAC中),我注意到有时候localhost无法正常工作,您还需要将机器名称添加到/etc/hosts文件中[此可能适用于您的问题也可能不适用]

我还建议你看一下我创建的这个教程(或书,你可以随意调用它),它可以帮助你使用Grid和它的设置,除了很多其他的东西,你想知道Grid。见here

相关问题