当前位置: 首页 > 知识库问答 >
问题:

Firefox不能使用selenium网格

芮宇航
2023-03-14

我想用配置在多台机器中的多个Firefox浏览器执行并行测试。

提前道谢。

Firefox版本:60.0.1
Selenium Firefox驱动程序:3.7.1
Geckdriver版本:v0.19.0

        System.setProperty("webdriver.gecko.driver","C:\\Fm2\\Try_Browsers\\Browsers\\drivers\\geckodriver_19.exe");
        WebDriver driver = new FirefoxDriver();
        driver.get("https://www.google.com/");
        driver.close();     

我在不同bat文件中设置了网格和节点:
HUb设置:
java-jar selenium-server-standalone-3.1.0.jar-port 4444-role HUb
节点设置:
java-dwebdriver.gecko.driver=./geckodriver_19.exe-jar selenium-server-standalone-3.1.0.jar-port 5557-role node-hub http://localhost:4444/grid/register-browser“browsername=firefox,maxinstances=10,platform=any

    System.setProperty("webdriver.gecko.driver","C:\\Fm2\\Try_Browsers\\Browsers\\drivers\\geckodriver.exe");
    DesiredCapabilities cap = DesiredCapabilities.firefox();
    cap.setBrowserName("firefox"); 
    cap.setPlatform(Platform.ANY);              
    WebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), cap);   
    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
    driver.get("https://www.google.com/");
    driver.close(); 
Exception in thread "main" org.openqa.selenium.SessionNotCreatedException: Unable to create new remote session. desired capabilities = Capabilities [{acceptInsecureCerts=true, browserName=firefox, moz:firefoxOptions=org.openqa.selenium.firefox.FirefoxOptions@21fa0ed7, version=, platform=ANY, firefox_profile=org.openqa.selenium.firefox.FirefoxProfile@49991a02}], required capabilities = Capabilities [{}]
        Build info: version: '3.1.0', revision: '86a5d70', time: '2017-02-16 07:57:44 -0800'
        System info: host: 'LAPTOP-9JJJC37G', ip: '192.168.100.205', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_151'
        Driver info: driver.version: FirefoxDriver
        Command duration or timeout: 9.72 seconds
            at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
            at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
            at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
            at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
            at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:214)
            at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:166)
            at org.openqa.selenium.remote.JsonWireProtocolResponse.lambda$new$0(JsonWireProtocolResponse.java:53)
            at org.openqa.selenium.remote.JsonWireProtocolResponse.lambda$getResponseFunction$2(JsonWireProtocolResponse.java:91)
            at org.openqa.selenium.remote.ProtocolHandshake.lambda$createSession$0(ProtocolHandshake.java:123)
            at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
            at java.util.Spliterators$ArraySpliterator.tryAdvance(Spliterators.java:958)
            at java.util.stream.ReferencePipeline.forEachWithCancel(ReferencePipeline.java:126)
            at java.util.stream.AbstractPipeline.copyIntoWithCancel(AbstractPipeline.java:498)
            at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:485)
            at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
            at java.util.stream.FindOps$FindOp.evaluateSequential(FindOps.java:152)
            at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
            at java.util.stream.ReferencePipeline.findFirst(ReferencePipeline.java:464)
            at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:126)
            at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:73)
            at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:142)
            at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:600)
            at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:219)
            at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:142)
            at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:155)
            at Browsers.callBrowsers.sFireFox(callBrowsers.java:45)
            at Browsers.callBrowsers.main(callBrowsers.java:27)
18:16:02.462 INFO - Executing: [new session: Capabilities [{acceptInsecureCerts=true, browserName=firefox, version=, platform=ANY}]])
18:16:02.488 INFO - Creating a new session for Capabilities [{acceptInsecureCerts=true, browserName=firefox, version=, platform=ANY}]
1531124162793   geckodriver     INFO    geckodriver 0.19.1
1531124162811   geckodriver     INFO    Listening on 127.0.0.1:13887
1531124163451   mozrunner::runner       INFO    Running command: "C:\\Program Files\\Mozilla Firefox\\firefox.exe" "-marionette" "-profile" "C:\\Users\\Viki\\AppData\\Local\\Temp\\rust_mozprofile.TtfJrIS5pIAk"
Unable to read VR Path Registry from C:\Users\Viki\AppData\Local\openvr\openvrpaths.vrpath
Unable to read VR Path Registry from C:\Users\Viki\AppData\Local\openvr\openvrpaths.vrpath
Unable to read VR Path Registry from C:\Users\Viki\AppData\Local\openvr\openvrpaths.vrpath
Unable to read VR Path Registry from C:\Users\Viki\AppData\Local\openvr\openvrpaths.vrpath
Unable to read VR Path Registry from C:\Users\Viki\AppData\Local\openvr\openvrpaths.vrpath
1531124171024   Marionette      INFO    Listening on port 50055
18:16:11.966 WARN - Exception thrown
java.util.concurrent.ExecutionException: org.openqa.selenium.WebDriverException: java.lang.reflect.InvocationTargetException
Build info: version: '3.1.0', revision: '86a5d70', time: '2017-02-16 07:57:44 -0800'
System info: host: 'LAPTOP-9XXXC39G', ip: '122.148.110.105', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_151'
Driver info: driver.version: unknown
        at java.util.concurrent.FutureTask.report(FutureTask.java:122)
        at java.util.concurrent.FutureTask.get(FutureTask.java:192)
        at org.openqa.selenium.remote.server.DefaultSession.execute(DefaultSession.java:183)
        at org.openqa.selenium.remote.server.DefaultSession.<init>(DefaultSession.java:119)
        at org.openqa.selenium.remote.server.DefaultSession.createSession(DefaultSession.java:95)
        at org.openqa.selenium.remote.server.DefaultDriverSessions.newSession(DefaultDriverSessions.java:131)
        at org.openqa.selenium.remote.server.handler.NewSession.handle(NewSession.java:59)
        at org.openqa.selenium.remote.server.handler.NewSession.handle(NewSession.java:36)
        at org.openqa.selenium.remote.server.rest.ResultConfig.handle(ResultConfig.java:111)
        at org.openqa.selenium.remote.server.JsonHttpCommandHandler.handleRequest(JsonHttpCommandHandler.java:189)
        at org.openqa.selenium.remote.server.DriverServlet.handleRequest(DriverServlet.java:222)
        at org.openqa.selenium.remote.server.DriverServlet.doPost(DriverServlet.java:184)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
        at org.openqa.selenium.remote.server.DriverServlet.service(DriverServlet.java:150)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
        at org.seleniumhq.jetty9.servlet.ServletHolder.handle(ServletHolder.java:808)
        at org.seleniumhq.jetty9.servlet.ServletHandler.doHandle(ServletHandler.java:587)
        at org.seleniumhq.jetty9.server.handler.ContextHandler.doHandle(ContextHandler.java:1127)
        at org.seleniumhq.jetty9.servlet.ServletHandler.doScope(ServletHandler.java:515)
        at org.seleniumhq.jetty9.server.handler.ContextHandler.doScope(ContextHandler.java:1061)
        at org.seleniumhq.jetty9.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
        at org.seleniumhq.jetty9.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)
        at org.seleniumhq.jetty9.server.Server.handle(Server.java:499)
        at org.seleniumhq.jetty9.server.HttpChannel.handle(HttpChannel.java:310)
        at org.seleniumhq.jetty9.server.HttpConnection.onFillable(HttpConnection.java:257)
        at org.seleniumhq.jetty9.io.AbstractConnection$2.run(AbstractConnection.java:540)
        at org.seleniumhq.jetty9.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:635)
        at org.seleniumhq.jetty9.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:555)
        at java.lang.Thread.run(Thread.java:748)

共有1个答案

诸葛利
2023-03-14

我看到有几件事会导致你的错误。首先,3.1.0版本已经很旧了,您应该使用3.14.0,而且geckodriver已经有了0.21.0版本。对于der最新的现实,请参见这里:seleniumhq Secound,您应该使用FirefoxOptions作为远程驱动程序(UrlToHub,FirefoxOptions)的传输参数,并预先将您所需的功能合并到FirefoxOptions中。我看到的最后一个问题是,您使用http://localhost:4444/wd/hub作为URL。当您启动集线器时,您将看到一个要在控制台中注册的URL,而该URL不在您的IP池中,您也应该使用该URL。要启动集线器,您只需要命令行命令:cd pathtoseleniumstandaloneserverfolder,start命令是:java-jar selenium-standalone- .jar-role hub 端口“4444”是默认的

然后您将看到连接RemoteWebDriver()的正确URL。它看起来是这样的:

c:usr\Downloads>java -jar "selenium-server-standalone-3.14.0.jar" -role hub
12:56:40.723 INFO [GridLauncherV3.launch] - Selenium build info: version: '3.14.0', revision: 'aacccce0'
12:56:40.725 INFO [GridLauncherV3$2.launch] - Launching Selenium Grid hub on port 4444
2018-09-07 12:56:41.063:INFO::main: Logging initialized @588ms to org.seleniumhq.jetty9.util.log.StdErrLog
12:56:41.447 INFO [Hub.start] - Selenium Grid hub is up and running
12:56:41.448 INFO [Hub.start] - Nodes should register to http://192.168.56.1:4444/grid/register/
12:56:41.448 INFO [Hub.start] - Clients should connect to http://192.168.56.1:4444/wd/hub

最后一行是RemoteWebDriver()的可连接URL

现在让我们以以下内容开始节点:

java -Dwebdirver.gecko.driver="PathToYourFirefoxDriver" -jar selenium-standalone-server-<versio>.jar -role node -hub http:UrlToHub:port/grid/register

看看这个例子:

    public WebDriver getWebDriver(final DesiredCapabilities desiredCapabilities) {
        FirefoxOptions firefoxOptions;

        DesiredCapabilities capabilities = new DesiredCapabilities()
        capabilities.merge(desiredCapabilities);
        capabilities.setPlatform(Platform.ANY);
        capabilities.setBrowserName("firefox");
        firefoxOptionHelper.merge(capabilities);

       try {
            WebDriver webDriver = new RemoteWebDriver(new URL(this.gridHubUrl), firefoxOptions);
            return webDriver;
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
        return null;
    }

希望能有所帮助。

 类似资料:
  • 我在使用火狐和WebDriver时得到了错误。 在45000 ms后,无法在端口7055上连接到主机127.0.0.1 Firefox版本:45.0 Selenium:2.50.1 Windows 10 64位 有人有类似的问题吗?或者有什么想法解决这个问题。它在chrome上工作得很好,但在firefox上没有一个URL被加载

  • 我正在使用selenium测试我们的网站。当我构建项目时,有一个例外:- OpenQA。硒。WebDriverException:未能在45000毫秒内启动套接字。试图连接到以下地址:127.0.0.1:7055,问题来自代码 有人知道如何解决这个问题吗?

  • 为了我的研究,我在firefox中做了一些源代码修改并自己构建。为了自动化测试,我选择使用Selenium,但不幸的是,我新构建的Firefox似乎不支持Selenium。 我做了以下工作: Firefox确实会打开并且响应迅速(我可以在搜索栏中输入一个网站)。但过了一段时间,python脚本崩溃,出现以下错误消息: 我在谷歌搜索了那个错误消息,并且大多数解决方案都建议我应该更新Selenium,

  • 我在使用Firefox和WebDriver时出错了。 Firefox版本:28.0 Selenium-Java-2.37.0 Selenium-Server-Standalone-2.53.0 Windows 7/64位 有人得到类似的问题或任何想法是什么解决这个问题。它在Chrome上工作得很好,但在Firefox上,没有一个URL被加载。

  • 如果Selenium不提供这样的功能,是否有其他工具允许我定义一个由Firefox执行的脚本并获得类似的结果?

  • 问题内容: 我想以编程方式指示Firefox访问URL列表(例如,在文本文件中定义),然后将每个URL保存到磁盘或打印该页面。 我知道Selenium提供了捕获页面截图的功能,但是我想知道是否可以使用浏览器的本机保存和打印功能。 如果Selenium不提供此类功能,是否可以使用其他任何工具来定义要由Firefox执行的 脚本 并获得相似的结果? 问题答案: 可以绕过“打印”对话框,在firefox