gpt4 book ai didi

java - geb geckodriver 无法正常工作(启动多个浏览器窗口)

转载 作者:行者123 更新时间:2023-11-30 07:47:16 26 4
gpt4 key购买 nike

我想在多个浏览器中使用 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>

`

最佳答案

我在尝试使用 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 版本。你可以检查这个。

关于java - geb geckodriver 无法正常工作(启动多个浏览器窗口),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49969902/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com