【问题标题】:geb geckodriver not working properly (launching multiple browser window)geb geckodriver 无法正常工作(启动多个浏览器窗口)
【发布时间】:2018-10-02 20:08:28
【问题描述】:

我想将 geb 与多个浏览器一起使用,特别是与 firefox 一起使用。但是我让firefox在不插入url的情况下启动多个窗口,最终失败。但是,我对 chrome 没有任何问题。 Chrome 运行良好。我正在使用 firefox 57.0.4(32 位)、geckodriver 0.20.1 和 selenium 3.11.0。

这就是我在 GebConfig.groovy 文件中对 firefox(geckodriver) 进行配置的方式。

driver = {
        System.setProperty("webdriver.gecko.driver", "C:\\Data\\selenium\\geckodriver.exe")
        DesiredCapabilities capabilities = DesiredCapabilities.firefox()
        capabilities.setCapability("marionette", true);
         new FirefoxDriver(capabilities)
     }

我也试过这样的简单配置:

driver="org.openqa.selenium.firefox.FirefoxDriver"

在崩溃之前,它们都打开了多个新窗口,特别是 9 个新的 Firefox 窗口都失败了。下面是堆栈跟踪。

1524422284063   geckodriver INFO    geckodriver 0.20.1
1524422284107   geckodriver INFO    Listening on 127.0.0.1:23600
1524422284801   mozrunner::runner   INFO    Running command: "C:\\Program 
Files (x86)\\Mozilla Firefox\\firefox.exe" "-marionette" "-profile" 
"C:\\Users\\My user 
name\\AppData\\Local\\Temp\\rust_mozprofile.t9ACOIsvj903"
1524422286509   Marionette  INFO    Enabled via --marionette
[Parent 5248, Gecko_IOThread] WARNING: pipe error: 109: file 
z:/build/build/src/ipc/chromium/src/chrome/common/ipc_channel_win.cc, line 
346
[Child 6128, Chrome_ChildThread] WARNING: pipe error: 109: file 
z:/build/build/src/ipc/chromium/src/chrome/common/ipc_channel_win.cc, line 
346
[Child 6128, Chrome_ChildThread] WARNING: pipe error: 109: file 
z:/build/build/src/ipc/chromium/src/chrome/common/ipc_channel_win.cc, line 
346
1524422290031   Marionette  INFO    Listening on port 53659
1524422290543   Marionette  DEBUG   Register listener.js for window 
4294967297
1524422291404   geckodriver INFO    geckodriver 0.20.1
1524422291444   geckodriver INFO    Listening on 127.0.0.1:37977
1524422291888   mozrunner::runner   INFO    Running command: "C:\\Program 
Files (x86)\\Mozilla Firefox\\firefox.exe" "-marionette" "-profile" 
"C:\\Users\\My user 
name\\AppData\\Local\\Temp\\rust_mozprofile.TDpwyZXqxyTB"
1524422293344   Marionette  INFO    Enabled via --marionette
[Parent 9756, Gecko_IOThread] WARNING: pipe error: 109: file 
z:/build/build/src/ipc/chromium/src/chrome/common/ipc_channel_win.cc, line 
346
1524422296749   Marionette  INFO    Listening on port 60160
1524422297189   Marionette  DEBUG   Register listener.js for window 
4294967297
1524422298143   geckodriver INFO    geckodriver 0.20.1
1524422298191   geckodriver INFO    Listening on 127.0.0.1:32782
1524422298377   mozrunner::runner   INFO    Running command: "C:\\Program 
Files (x86)\\Mozilla Firefox\\firefox.exe" "-marionette" "-profile" 
"C:\\Users\\My user 
name\\AppData\\Local\\Temp\\rust_mozprofile.yBcRA1dKXoGT"
1524422299521   Marionette  INFO    Enabled via --marionette
[Child 16340, Chrome_ChildThread] WARNING: pipe error: 109: file 
z:/build/build/src/ipc/chromium/src/chrome/common/ipc_channel_win.cc, line 
346
1524422302872   Marionette  INFO    Listening on port 63356
1524422303045   Marionette  DEBUG   Register listener.js for window 
4294967297
1524422303852   geckodriver INFO    geckodriver 0.20.1
1524422303895   geckodriver INFO    Listening on 127.0.0.1:19586
1524422304228   mozrunner::runner   INFO    Running command: "C:\\Program  
Files (x86)\\Mozilla Firefox\\firefox.exe" "-marionette" "-profile" 
"C:\\Users\\My user 
name\\AppData\\Local\\Temp\\rust_mozprofile.9ev5FY0xc1i7"
1524422305543   Marionette  INFO    Enabled via --marionette
[GFX1-]: Could not get a DXGI adapter
[GFX1-]: Could not get a DXGI adapter
[Child 14868, Chrome_ChildThread] WARNING: pipe error: 109: file 
z:/build/build/src/ipc/chromium/src/chrome/common/ipc_channel_win.cc, line 
346
[Child 14868, Chrome_ChildThread] WARNING: pipe error: 109: file 
z:/build/build/src/ipc/chromium/src/chrome/common/ipc_channel_win.cc, line 
346
1524422310032   Marionette  INFO    Listening on port 64844
[GFX1-]: Could not get a DXGI adapter
1524422310604   Marionette  DEBUG   Register listener.js for window 
4294967297
1524422321813   geckodriver INFO    geckodriver 0.20.1
1524422321858   geckodriver INFO    Listening on 127.0.0.1:26836
1524422322191   mozrunner::runner   INFO    Running command: "C:\\Program 
Files (x86)\\Mozilla Firefox\\firefox.exe" "-marionette" "-profile" 
"C:\\Users\\My user 
name\\AppData\\Local\\Temp\\rust_mozprofile.ibDRBSonhkXz"
1524422323777   Marionette  INFO    Enabled via --marionette
[GFX1-]: Could not get a DXGI adapter
[GFX1-]: ClientLayerManager::BeginTransaction with IPC channel down. GPU 
process may have died.
[Parent 10436, Gecko_IOThread] WARNING: pipe error: 109: file 
z:/build/build/src/ipc/chromium/src/chrome/common/ipc_channel_win.cc, line 
346
[Child 16792, Chrome_ChildThread] WARNING: pipe error: 109: file 
z:/build/build/src/ipc/chromium/src/chrome/common/ipc_channel_win.cc, line 
346
[Child 16792, Chrome_ChildThread] WARNING: pipe error: 109: file 
z:/build/build/src/ipc/chromium/src/chrome/common/ipc_channel_win.cc, line 
346
[GFX1-]: Could not get a DXGI adapter
1524422327647   Marionette  INFO    Listening on port 49671
1524422327909   Marionette  DEBUG   Register listener.js for window 
4294967297
[GFX1-]: Could not get a DXGI adapter
1524422328854   geckodriver INFO    geckodriver 0.20.1
1524422328899   geckodriver INFO    Listening on 127.0.0.1:41041
1524422329094   mozrunner::runner   INFO    Running command: "C:\\Program 
Files (x86)\\Mozilla Firefox\\firefox.exe" "-marionette" "-profile" 
"C:\\Users\\My user 
name\\AppData\\Local\\Temp\\rust_mozprofile.nF37Bcb1rsbM"
1524422330408   Marionette  INFO    Enabled via --marionette
[Parent 10360, Gecko_IOThread] WARNING: pipe error: 109: file 
z:/build/build/src/ipc/chromium/src/chrome/common/ipc_channel_win.cc, line 
346
[Child 12412, Chrome_ChildThread] WARNING: pipe error: 109: file 
z:/build/build/src/ipc/chromium/src/chrome/common/ipc_channel_win.cc, line 
346
[Child 12412, Chrome_ChildThread] WARNING: pipe error: 109: file 
z:/build/build/src/ipc/chromium/src/chrome/common/ipc_channel_win.cc, line 
346
1524422335433   Marionette  INFO    Listening on port 55596
1524422335714   Marionette  DEBUG   Register listener.js for window 
4294967297
1524422336611   geckodriver INFO    geckodriver 0.20.1
1524422336657   geckodriver INFO    Listening on 127.0.0.1:44307
1524422337007   mozrunner::runner   INFO    Running command: "C:\\Program 
Files (x86)\\Mozilla Firefox\\firefox.exe" "-marionette" "-profile" 
"C:\\Users\\My user 
name\\AppData\\Local\\Temp\\rust_mozprofile.BZK9Y7YfOaPw"
1524422338399   Marionette  INFO    Enabled via --marionette
[Child 5860, Chrome_ChildThread] WARNING: pipe error: 109: file 
z:/build/build/src/ipc/chromium/src/chrome/common/ipc_channel_win.cc, line 
346
[Child 5860, Chrome_ChildThread] WARNING: pipe error: 109: file 
z:/build/build/src/ipc/chromium/src/chrome/common/ipc_channel_win.cc, line 
346
1524422348219   Marionette  INFO    Listening on port 65437
1524422348734   Marionette  DEBUG   Register listener.js for window 
4294967297
1524422350248   geckodriver INFO    geckodriver 0.20.1
1524422350322   geckodriver INFO    Listening on 127.0.0.1:36341
1524422350716   mozrunner::runner   INFO    Running command: "C:\\Program 
Files (x86)\\Mozilla Firefox\\firefox.exe" "-marionette" "-profile" 
"C:\\Users\\My user 
name\\AppData\\Local\\Temp\\rust_mozprofile.WMfmoDbCDTAT"
1524422353025   Marionette  INFO    Enabled via --marionette
[Child 10468, Chrome_ChildThread] WARNING: pipe error: 109: file 
z:/build/build/src/ipc/chromium/src/chrome/common/ipc_channel_win.cc, line 
346
[Child 10468, Chrome_ChildThread] WARNING: pipe error: 109: file 
z:/build/build/src/ipc/chromium/src/chrome/common/ipc_channel_win.cc, line 
346
1524422358314   Marionette  INFO    Listening on port 56794
1524422358557   Marionette  DEBUG   Register listener.js for window 
4294967297
1524422359719   geckodriver INFO    geckodriver 0.20.1
1524422359781   geckodriver INFO    Listening on 127.0.0.1:29271
1524422360457   mozrunner::runner   INFO    Running command: "C:\\Program 
Files (x86)\\Mozilla Firefox\\firefox.exe" "-marionette" "-profile" 
"C:\\Users\\My user 
name\\AppData\\Local\\Temp\\rust_mozprofile.L8VJnzbpCkrK"
1524422362362   Marionette  INFO    Enabled via --marionette
[Parent 6760, Gecko_IOThread] WARNING: pipe error: 109: file 
z:/build/build/src/ipc/chromium/src/chrome/common/ipc_channel_win.cc, line 
346
1524422368470   Marionette  INFO    Listening on port 54188
1524422368810   Marionette  DEBUG   Register listener.js for window 
4294967297
Tests run: 6, Failures: 0, Errors: 6, Skipped: 0, Time elapsed: 102.379 sec 
<<< FAILURE! - in MyTestSuite
mytestfunction(MyTestSuite)  Time elapsed: 29.182 sec  <<< ERROR!
geb.driver.DriverCreationException: failed to create driver from callback ' 
script1524422266628441905114$_run_closure1@2643ed03'
at MyTestSuite.mytestfunction(MyTestSuite.groovy:25)
Caused by: org.openqa.selenium.SessionNotCreatedException: 
Unable to create new remote session. desired capabilities = Capabilities 
[{marionette=true, browserName=firefox, moz:firefoxOptions= 
{binary=Optional.empty, args=[], legacy=null, logLevel=null, prefs={}, 
profile=null}, version=, platform=ANY}], required capabilities = 
Capabilities [{moz:firefoxOptions={binary=Optional.empty, args=[], 
legacy=null, logLevel=null, prefs={}, profile=null}}]
Build info: version: '3.3.1', revision: '5234b325d5', time: '2017-03-10 
09:10:29 +0000'
System info: host: 'Hostname', ip: 'xxx.xxx.xx.xx', os.name: 'Windows 7', 
os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_144'
Driver info: driver.version: FirefoxDriver

我现在很困惑,因为到目前为止论坛上所有可能的解决方案都不起作用。

这是 GebConfig.groovy 文件:

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxOptions;
import org.openqa.selenium.os.ExecutableFinder
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;

 reportsDir = "target/geb-reports"
 driver = null

    driver = {
    System.setProperty("webdriver.gecko.driver", "D:\\eclipse-jee-workspace\\geb-example-maven\\drivers\\geckodriver.exe")
    DesiredCapabilities capabilities = DesiredCapabilities.firefox()
    capabilities.setCapability("marionette", true);
    new FirefoxDriver(capabilities)
 }




baseUrl = "http://gebish.org"

这是 GebishOrgSpec .groovy 文件

import geb.spock.GebSpec

class GebishOrgSpec extends GebSpec {

def "can get to the current Book of Geb"() {
    when:
    to GebishOrgHomePage

    and:
    manualsMenu.open()

    then:
    manualsMenu.links[0].text().startsWith("current")

    when:
    manualsMenu.links[0].click()

    then:
    at TheBookOfGebPage
  }
}

这是 GebishOrgHomePage.groovy 文件

  import geb.Page

  class GebishOrgHomePage extends Page {

   static at = { title == "Geb - Very Groovy Browser Automation" }

 static content = {
    manualsMenu { module(ManualsMenuModule) }
 }

}

这里是 ManualsMenuModule.groovy

import geb.Module

 class ManualsMenuModule extends Module {
  static content = {
    toggle { $("div.menu a.manuals") }
    linksContainer { $("#manuals-menu") }
    links { linksContainer.find("a") }
}

void open() {
    toggle.click()
    waitFor { !linksContainer.hasClass("animating") }
 }
}

这是 TheBookOfGebPage.groovy

import geb.Page

class TheBookOfGebPage extends Page {

static at = { title.startsWith("The Book Of Geb") }
}

这里是pom

<?xml version="1.0"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0                       
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.gebish.example</groupId>
<artifactId>geb-maven-example</artifactId>
<packaging>jar</packaging>
<version>1</version>
 <name>Geb Maven Example</name>
 <url>http://gebish.org</url>
 <properties>
 <gebVersion>1.1.1</gebVersion>
 <seleniumVersion>3.3.1</seleniumVersion>
 <groovyVersion>2.4.11</groovyVersion>
 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
 <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
 </properties>
 <dependencies>
 <dependency>
  <groupId>org.codehaus.groovy</groupId>
  <artifactId>groovy-all</artifactId>
  <version>${groovyVersion}</version>
 </dependency>
 <dependency>
  <groupId>junit</groupId>
  <artifactId>junit</artifactId>
  <version>4.12</version>
  <scope>test</scope>
 </dependency>

 <dependency>
    <groupId>com.opencsv</groupId>
    <artifactId>opencsv</artifactId>
    <version>4.1</version>
 </dependency>
 <!-- https://mvnrepository.com/artifact/org.apache.poi/poi -->
 <dependency>
     <groupId>org.apache.poi</groupId>
     <artifactId>poi</artifactId>
     <version>3.9</version>
  </dependency>
  <!-- https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml -->
  <dependency>
    <groupId>org.apache.poi</groupId>
    <artifactId>poi-ooxml</artifactId>
    <version>3.9</version>
 </dependency>
 <!-- https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml-schemas -->

 <dependency>
    <groupId>org.apache.poi</groupId>
    <artifactId>poi-ooxml-schemas</artifactId>
    <version>3.9</version>
 </dependency>

 <!-- https://mvnrepository.com/artifact/org.apache.xmlbeans/xmlbeans -->
 <dependency>
    <groupId>org.apache.xmlbeans</groupId>
    <artifactId>xmlbeans</artifactId>
    <version>2.6.0</version>
 </dependency>






 <dependency>
  <groupId>org.spockframework</groupId>
  <artifactId>spock-core</artifactId>
  <version>1.0-groovy-2.4</version>
  <scope>test</scope>
  <exclusions>
    <exclusion>
      <groupId>org.codehaus.groovy</groupId>
      <artifactId>groovy-all</artifactId>
    </exclusion>
  </exclusions>
 </dependency>
 <dependency>
  <groupId>org.gebish</groupId>
  <artifactId>geb-spock</artifactId>
  <version>${gebVersion}</version>
  <scope>test</scope>
 </dependency>
 <dependency>
  <groupId>org.seleniumhq.selenium</groupId>
  <artifactId>selenium-chrome-driver</artifactId>
  <version>${seleniumVersion}</version>
  <scope>test</scope>
 </dependency>
 <!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-remote-driver -->
 <dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-firefox-driver</artifactId>
    <version>${seleniumVersion}</version>
    <scope>test</scope>
 </dependency>
 <!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-ie-driver -->
 <dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-ie-driver</artifactId>
    <version>${seleniumVersion}</version>
    <scope>test</scope>
 </dependency>


 <dependency>
  <groupId>org.apache.commons</groupId>
  <artifactId>commons-lang3</artifactId>
  <version>3.5</version>
  <scope>test</scope>
 </dependency>
</dependencies>
<build>
<plugins>
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.19</version>
    <configuration>
      <includes>
        <include>*Spec.*</include>
      </includes>
      <systemPropertyVariables>
        <geb.build.reportsDir>target/test-reports/geb</geb.build.reportsDir>
      </systemPropertyVariables>
    </configuration>
  </plugin>
    <plugin>
    <groupId>com.rimerosolutions.maven.plugins</groupId>
    <artifactId>wrapper-maven-plugin</artifactId>
    <version>0.0.4</version>
    <configuration>
      <mavenVersion>3.3.3</mavenVersion>
    </configuration>
  </plugin>
  <plugin>
    <groupId>org.codehaus.gmaven</groupId>
    <artifactId>gmaven-plugin</artifactId>
    <version>1.5</version>
    <executions>
      <execution>
        <goals>
          <goal>testCompile</goal>
        </goals>
      </execution>
    </executions>
    <dependencies>
      <dependency>
        <groupId>org.codehaus.groovy</groupId>
        <artifactId>groovy-all</artifactId>
        <version>${groovyVersion}</version>
      </dependency>
    </dependencies>
  </plugin>
  <plugin>
  <groupId>com.github.webdriverextensions</groupId>
  <artifactId>webdriverextensions-maven-plugin</artifactId>
  <version>3.1.1</version>
  <executions>
    <execution>
      <goals>
        <goal>install-drivers</goal>
      </goals>
    </execution>
  </executions>
  <configuration>
    <drivers>
      <driver>
        <name>chromedriver</name>
        <version>2.36</version>
        <platform>windows</platform>
      </driver>
      <!-- <driver>
        <name>chromedriver</name>
        <version>2.36</version>
        <platform>windows</platform>
      </driver>-->
     <!-- <driver>
        <name>geckodriver</name>
        <version>0.14.0</version>
        <platform>windows</platform>
      </driver>-->
      <driver>
        <name>geckodriver</name>
        <version>0.20.1</version>
        <platform>windows</platform>
      </driver>
    </drivers>

  </configuration>
  </plugin>
</plugins>
<pluginManagement>
    <plugins>
        <!--This plugin's configuration is used to store Eclipse m2e 
settings only. It has no influence on the Maven build itself.-->
        <plugin>
            <groupId>org.eclipse.m2e</groupId>
            <artifactId>lifecycle-mapping</artifactId>
            <version>1.0.0</version>
            <configuration>
                <lifecycleMappingMetadata>
                    <pluginExecutions>
                        <pluginExecution>
                            <pluginExecutionFilter>
                                <groupId>
                                    com.github.webdriverextensions
                                </groupId>
                                <artifactId>
                                    webdriverextensions-maven-plugin
                                </artifactId>
                                <versionRange>
                                    [3.1.1,)
                                </versionRange>
                                <goals>
                                    <goal>install-drivers</goal>
                                </goals>
                            </pluginExecutionFilter>
                            <action>
                                <ignore></ignore>
                            </action>
                        </pluginExecution>
                        <pluginExecution>
                            <pluginExecutionFilter>
                                <groupId>
                                    org.codehaus.gmaven
                                </groupId>
                                <artifactId>
                                    gmaven-plugin
                                </artifactId>
                                <versionRange>[1.5,)</versionRange>
                                <goals>
                                    <goal>testCompile</goal>
                                </goals>
                            </pluginExecutionFilter>
                            <action>
                                <ignore></ignore>
                            </action>
                        </pluginExecution>
                    </pluginExecutions>
                </lifecycleMappingMetadata>
            </configuration>
        </plugin>
    </plugins>
</pluginManagement>

`

【问题讨论】:

    标签: java selenium-webdriver groovy automated-tests geb


    【解决方案1】:

    我在尝试使用 x64 驱动程序时遇到了类似的问题。每个版本 > 0.14.0 都会显示此症状(4 个空的浏览器窗口,4 个需要手动杀死的 geckodriver.exe 实例)。一旦我将我的项目恢复到 0.14.0,一切都像魅力一样再次运行,即使使用当前的 FF Quantum 59.0.2(64 位)。

    当然,这不是解决方案,而是解决方法。 Geckodriver是否有相应的票我不知道。我还没查。


    更新:我仍在使用 Selenium 3.0.1。也许这就是为什么我不能使用从未使用过的 Geckodriver 版本的原因,因为在 release page 上它说对于驱动程序版本 0.15,您至少需要 Selenium 3.3。但是正如您所说,您使用的是 Selenium 3.11,这应该不是问题。甚至 Geckodriver 0.19.0 也只需要 Selenium 3.5。但也许您的 Maven 设置存在缺陷,并且它以某种方式引入了较旧的 Selenium 版本。你可以检查一下。

    【讨论】:

    • 我同意 kriegaex 的观点,这很可能是某种 WebDriver + geckodriver + FF 版本不兼容。我会首先尝试将您的 FF 升级到最新版本,如果这没有帮助,我将开始降级 WebDriver 和 geckodriver。我可以确认本地 FF 56.0.2、WebDriver 3.6.0 和 geckodriver 0.19.0 的组合对我有用。
    • 不幸的是我仍然有同样的问题。使用 selenium 3.0.1 和 geckodriver 0.14.0 我有一个窗口打开了一段时间,但 url 没有填写,大约 30 分钟后打开了新窗口。
    • 那么请提供一个完整的、最小的项目(MCVE),包括。 Maven 构建,以便我可以重现您的问题。 GitHub会很好。顺便说一句,如果可以的话,您也可以尝试 64 位而不是 32 位。这是我目前可以看到的我们的设置之间的差异。但是现在说代码真的会更好,而不仅仅是散文。这是 StackOverflow。谢谢。
    • 我在使用 Internet Explorer 时遇到了同样的问题。
    • 感谢 MCVE。我可以像在我自己​​的项目中一样使用 0.20 驱动程序重现问题,这并不奇怪。但对我来说,如果 (a) 我将 Gecko 驱动程序从 0.20.1 更改为 0.14.0 并且 (b)将 GebConfig 中的驱动程序名称从“geckodriver.exe”更改为“geckodriver-windows-64bit.exe”。也许你忘记了这一点,总是将你的测试指向一个重命名的驱动程序有问题的版本,而不是 Maven 下载的驱动程序。
    猜你喜欢
    • 1970-01-01
    • 2023-03-09
    • 1970-01-01
    • 2012-03-09
    • 2018-06-15
    • 1970-01-01
    • 1970-01-01
    • 2015-11-14
    • 2013-07-25
    相关资源
    最近更新 更多