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

无法用特定语言在geb spock中使用selenium 3.3.1启动firefox浏览器

阴高刚
2023-03-14
/*
    This is the Geb configuration file.

    See: http://www.gebish.org/manual/current/configuration.html
*/


import com.gargoylesoftware.htmlunit.BrowserVersion
import com.gargoylesoftware.htmlunit.WebClient
import org.openqa.selenium.Platform
import org.openqa.selenium.WebDriver
import org.openqa.selenium.chrome.ChromeDriver
import org.openqa.selenium.chrome.ChromeOptions
import org.openqa.selenium.firefox.FirefoxDriver
import org.openqa.selenium.firefox.FirefoxOptions
import org.openqa.selenium.firefox.FirefoxProfile
import org.openqa.selenium.htmlunit.HtmlUnitDriver
import org.openqa.selenium.ie.InternetExplorerDriver
import org.openqa.selenium.remote.CapabilityType
import org.openqa.selenium.remote.DesiredCapabilities
import org.openqa.selenium.remote.RemoteWebDriver

import java.util.logging.Level
import java.util.logging.Logger
/*
1) For testing on different browsers, On Edit Configurations provide VM Options = -ea -Dgeb.env=<BROWSER_NAME>
2) For testing from command prompt by using maven command, run the command :
   mvn -Dgeb.env=<BROWSER_NAME> -Dtest=<TEST_CASE_NAME_WITHOUT_EXTENSION > test

Note: <BROWSER_NAME> = "firefox" or "chrome" or "ie" or "htmlunit"
      <TEST_CASE_NAME_WITHOUT_EXTENSION> example: eSuite_MP_CON_09_Zoek_in_kennisbank_PDC                        */

//FUNCTIONAL SETTINGS
def final DEFAULT_BROWSER = "firefox"                            //"chrome" or "firefox" or "ie" or "htmlunit"
def final BASE_URL = "https://india.westernunion.com/WUCOMWEB/signInAction.do?method=load"

def final DEFAULT_LANGUAGE = "nl"                                       //"en" or "nl"
def final REPORT_DIR = 'target/reports'
def final DEFAULT_DOWNLOAD_PATH = "C://Users/IEUser/Downloads/"
def final USERNAMEAPP = "Testbeheerder" //was "Beheerder"
def final PASSWORDAPP = "March@2017" //was "Jan@2017"



//TECHNICAL SETTINGS
def final WAITFOR_TIMEOUT = 50
def final WAITFOR_RETRY = 0.5
def final WAIT_AT_KEYWORD_AT = true
def final WAIT_TIME = 1000


def browser = System.getProperty("geb.env")
//Default browser
if (!correctBrowser(browser)) {
    browser = DEFAULT_BROWSER
}

def envLang = System.getProperty("geb.env.lang")
//Default language
if (!correctLanguage(envLang)) {
    envLang = DEFAULT_LANGUAGE
}

System.setProperty("geb.env.lang", envLang)
System.setProperty("geb.build.baseUrl", BASE_URL);
System.setProperty("geb.build.beheer.baseUrl", BASE_URL_BEHEER);
System.setProperty("geb.build.loket.baseUrl", BASE_URL_LOKET);
System.setProperty("geb.wait.time", WAIT_TIME.toString());
System.setProperty("geb.download.path", DEFAULT_DOWNLOAD_PATH);
System.setProperty("usernameapp", USERNAMEAPP);
System.setProperty("passwordapp", PASSWORDAPP);
System.setProperty("penguinusername", PENGUINUSERNAME);
System.setProperty("penguinpassword", PENGUINPASSWORD);

System.setProperty("geb.env", browser)

System.setProperty("USERNAME", USERNAME);
System.setProperty("DATABASE", DATABASE);
System.setProperty("HOSTNAME", HOSTNAME);
System.setProperty("PGPASSWORD", PGPASSWORD);

if (Platform.LINUX.equals(Platform.getCurrent())) {
    System.setProperty("webdriver.chrome.driver", "src/test/resources/drivers/chromedriver-2.15-linux64");
} else {
    System.setProperty("webdriver.chrome.driver", "src/test/resources/drivers/chromedriver.exe");
    //System.setProperty("webdriver.chrome.driver", "src/test/resources/drivers/chromedriver-2.15_win32.exe");
}
//System.setProperty("webdriver.ie.driver", "src/test/resources/drivers/IEDriverServer-2.45.0_Win32_.exe");
System.setProperty("webdriver.ie.driver", "src/test/resources/drivers/IEDriverServer.exe");
System.setProperty("webdriver.gecko.driver", "src/test/resources/drivers/geckodriver.exe");

environments {

    driver = { getDriver(browser, envLang) }

}

/**
 * Returns the browser specific WebDriver
 * @param browser Browser name
 * @return WebDriver
 */
private WebDriver getDriver(def browser, def language) {

    if ("chrome".equalsIgnoreCase(browser)) {

        DesiredCapabilities chromeCapabilities = DesiredCapabilities.chrome();
        ChromeOptions chromeOptions = new ChromeOptions();
        chromeOptions.addArguments("--start-maximized");
        Map<String, Object> prefs = new HashMap<String, Object>();
        prefs.put("intl.accept_languages", language);
        chromeOptions.setExperimentalOption("prefs", prefs);
        chromeCapabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions)
        def chromeDriver = new ChromeDriver(chromeCapabilities)
        chromeDriver.manage().window().maximize()
        chromeDriver

    } else if ("firefox".equalsIgnoreCase(browser)) {

    // Case 1: which was working earlier
        FirefoxProfile profile = new FirefoxProfile()
        profile.setPreference("intl.accept_languages", language)
        def firefoxDriver = new FirefoxDriver(profile)
        firefoxDriver.manage().window().maximize()
        firefoxDriver

        // Case 2 : 
        /*FirefoxOptions options = new FirefoxOptions().setLogLevel(Level.OFF)
        def firefoxDriver = new FirefoxDriver(options)
        firefoxDriver.manage().window().maximize()
        firefoxDriver*/

        // Case 3 : 
        /*DesiredCapabilities capabilities = DesiredCapabilities.firefox();
        capabilities.setCapability("marionette", true);
        def firefoxDriver = new RemoteWebDriver(capabilities);
        firefoxDriver.manage().window().maximize()
        firefoxDriver*/


    } else if ("ie".equalsIgnoreCase(browser)) {

        /**
         * For InternetExplorer: In order to set the browser language to 'EN' or 'NL',
         *  Go to, Settings -> Internet Options -> General ->
         *  - Click on the button 'Languages'
         *  - In the Language text box,
         *    Add the desired language "Dutch (Netherlands) [nl-NL]" or "English (United States) [en-US]"
         *    and move it up by clicking 'Move up' button
         *
         */
        DesiredCapabilities ieCapabilities = DesiredCapabilities.internetExplorer()
        ieCapabilities.setCapability(InternetExplorerDriver.ENABLE_PERSISTENT_HOVERING, false)
        ieCapabilities.setCapability(InternetExplorerDriver.REQUIRE_WINDOW_FOCUS, false)
        ieCapabilities.setCapability(InternetExplorerDriver.UNEXPECTED_ALERT_BEHAVIOR, true)
        ieCapabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true)
        ieCapabilities.setCapability(CapabilityType.HAS_NATIVE_EVENTS, true)
        ieCapabilities.setCapability(InternetExplorerDriver.ENABLE_ELEMENT_CACHE_CLEANUP, true);
        ieCapabilities.setCapability(InternetExplorerDriver.IE_ENSURE_CLEAN_SESSION, true);
        ieCapabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true)
        ieCapabilities.setJavascriptEnabled(true);
        def ieDriver = new InternetExplorerDriver(ieCapabilities)
        ieDriver.manage().window().maximize()
        ieDriver

    } else if ("htmlunit".equalsIgnoreCase(browser)) {

        WebDriver htmlUnitDriver = new HtmlUnitDriver() {
            protected WebClient modifyWebClient(WebClient client) {
                client = new WebClient(BrowserVersion.CHROME);
                client.getOptions().setUseInsecureSSL(true);
                client.getOptions().setThrowExceptionOnScriptError(false);
                return client;
            }
        };
        BrowserVersion.CHROME.setBrowserLanguage(language.toString())
        // Turn off htmlunit warnings
        Logger.getLogger("com.gargoylesoftware.htmlunit").setLevel(Level.OFF);
        Logger.getLogger("org.apache.http").setLevel(Level.OFF);
        htmlUnitDriver.setJavascriptEnabled(true);
        htmlUnitDriver.manage().window().maximize()
        htmlUnitDriver

    }

}

/**
 * Checks if the browser name provided is the correct one
 * @param browser Browser name
 * @return boolean
 */
private boolean correctBrowser(def browser) {
    boolean result = true;
    if (null == browser || (!"chrome".equalsIgnoreCase(browser) && !"firefox".equalsIgnoreCase(browser) && !"ie".equalsIgnoreCase(browser) && !"htmlunit".equalsIgnoreCase(browser))) {
        result = false;
    }
    return result;
}

/**
 * Check if the language provided is the correct one
 * @param lang Language
 * @return boolean
 */
private boolean correctLanguage(def lang) {
    boolean result = true;
    if (null == lang || (!"en".equalsIgnoreCase(lang) && !"nl".equalsIgnoreCase(lang))) {
        result = false;
    }
    return result;
}



waiting {
    timeout = WAITFOR_TIMEOUT
    retryInterval = WAITFOR_RETRY
}

atCheckWaiting = WAIT_AT_KEYWORD_AT
reportsDir = REPORT_DIR
"C:\Program Files\Java\jdk1.8.0_131\bin\java" -ea -Dgeb.build.reportsDir=target/test-reports/geb -Didea.test.cyclic.buffer.size=1048576 "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2017.2.3\lib\idea_rt.jar=52849:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2017.2.3\bin" -Dfile.encoding=UTF-8 -classpath "C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2017.2.3\lib\idea_rt.jar;C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2017.2.3\plugins\junit\lib\junit-rt.jar;C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2017.2.3\plugins\junit\lib\junit5-rt.jar;C:\Program Files\Java\jdk1.8.0_131\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.8.0_131\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.8.0_131\jre\lib\ext\access-bridge-64.jar;C:\Program Files\Java\jdk1.8.0_131\jre\lib\ext\cldrdata.jar;C:\Program Files\Java\jdk1.8.0_131\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.8.0_131\jre\lib\ext\jaccess.jar;C:\Program Files\Java\jdk1.8.0_131\jre\lib\ext\jfxrt.jar;C:\Program Files\Java\jdk1.8.0_131\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.8.0_131\jre\lib\ext\nashorn.jar;C:\Program Files\Java\jdk1.8.0_131\jre\lib\ext\sunec.jar;C:\Program Files\Java\jdk1.8.0_131\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.8.0_131\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.8.0_131\jre\lib\ext\sunpkcs11.jar;C:\Program Files\Java\jdk1.8.0_131\jre\lib\ext\zipfs.jar;C:\Program Files\Java\jdk1.8.0_131\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.8.0_131\jre\lib\jce.jar;C:\Program Files\Java\jdk1.8.0_131\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.8.0_131\jre\lib\jfxswt.jar;C:\Program Files\Java\jdk1.8.0_131\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.8.0_131\jre\lib\management-agent.jar;C:\Program Files\Java\jdk1.8.0_131\jre\lib\plugin.jar;C:\Program Files\Java\jdk1.8.0_131\jre\lib\resources.jar;C:\Program Files\Java\jdk1.8.0_131\jre\lib\rt.jar;C:\DurgeshProjectWork\Workspace\IdeaProjects\wu_bdd_geb\target\test-classes;C:\Users\acer\.m2\repository\org\spockframework\spock-core\1.0-groovy-2.4\spock-core-1.0-groovy-2.4.jar;C:\Users\acer\.m2\repository\junit\junit\4.12\junit-4.12.jar;C:\Users\acer\.m2\repository\org\hamcrest\hamcrest-core\1.3\hamcrest-core-1.3.jar;C:\Users\acer\.m2\repository\org\gebish\geb-spock\2.1\geb-spock-2.1.jar;C:\Users\acer\.m2\repository\org\codehaus\groovy\groovy-all\2.4.7\groovy-all-2.4.7.jar;C:\Users\acer\.m2\repository\org\gebish\geb-core\2.1\geb-core-2.1.jar;C:\Users\acer\.m2\repository\org\gebish\geb-ast\2.1\geb-ast-2.1.jar;C:\Users\acer\.m2\repository\org\gebish\geb-waiting\2.1\geb-waiting-2.1.jar;C:\Users\acer\.m2\repository\org\gebish\geb-implicit-assertions\2.1\geb-implicit-assertions-2.1.jar;C:\Users\acer\.m2\repository\org\gebish\geb-exceptions\2.1\geb-exceptions-2.1.jar;C:\Users\acer\.m2\repository\org\jodd\jodd-lagarto\3.7.1\jodd-lagarto-3.7.1.jar;C:\Users\acer\.m2\repository\org\jodd\jodd-core\3.7.1\jodd-core-3.7.1.jar;C:\Users\acer\.m2\repository\org\jodd\jodd-log\3.7.1\jodd-log-3.7.1.jar;C:\Users\acer\.m2\repository\org\gebish\geb-test-common\2.1\geb-test-common-2.1.jar;C:\Users\acer\.m2\repository\org\seleniumhq\selenium\selenium-java\3.3.1\selenium-java-3.3.1.jar;C:\Users\acer\.m2\repository\org\seleniumhq\selenium\selenium-chrome-driver\3.3.1\selenium-chrome-driver-3.3.1.jar;C:\Users\acer\.m2\repository\org\seleniumhq\selenium\selenium-remote-driver\3.3.1\selenium-remote-driver-3.3.1.jar;C:\Users\acer\.m2\repository\org\seleniumhq\selenium\selenium-api\3.3.1\selenium-api-3.3.1.jar;C:\Users\acer\.m2\repository\cglib\cglib-nodep\3.2.4\cglib-nodep-3.2.4.jar;C:\Users\acer\.m2\repository\org\apache\commons\commons-exec\1.3\commons-exec-1.3.jar;C:\Users\acer\.m2\repository\com\google\guava\guava\21.0\guava-21.0.jar;C:\Users\acer\.m2\repository\net\java\dev\jna\jna-platform\4.1.0\jna-platform-4.1.0.jar;C:\Users\acer\.m2\repository\net\java\dev\jna\jna\4.1.0\jna-4.1.0.jar;C:\Users\acer\.m2\repository\org\seleniumhq\selenium\selenium-edge-driver\3.3.1\selenium-edge-driver-3.3.1.jar;C:\Users\acer\.m2\repository\org\seleniumhq\selenium\selenium-firefox-driver\3.3.1\selenium-firefox-driver-3.3.1.jar;C:\Users\acer\.m2\repository\org\seleniumhq\selenium\selenium-ie-driver\3.3.1\selenium-ie-driver-3.3.1.jar;C:\Users\acer\.m2\repository\org\seleniumhq\selenium\selenium-opera-driver\3.3.1\selenium-opera-driver-3.3.1.jar;C:\Users\acer\.m2\repository\org\seleniumhq\selenium\selenium-safari-driver\3.3.1\selenium-safari-driver-3.3.1.jar;C:\Users\acer\.m2\repository\com\codeborne\phantomjsdriver\1.4.0\phantomjsdriver-1.4.0.jar;C:\Users\acer\.m2\repository\org\seleniumhq\selenium\htmlunit-driver\2.24\htmlunit-driver-2.24.jar;C:\Users\acer\.m2\repository\org\seleniumhq\selenium\selenium-support\3.9.1\selenium-support-3.9.1.jar;C:\Users\acer\.m2\repository\net\bytebuddy\byte-buddy\1.7.9\byte-buddy-1.7.9.jar;C:\Users\acer\.m2\repository\com\squareup\okhttp3\okhttp\3.9.1\okhttp-3.9.1.jar;C:\Users\acer\.m2\repository\com\squareup\okio\okio\1.13.0\okio-1.13.0.jar;C:\Users\acer\.m2\repository\net\sourceforge\htmlunit\htmlunit\2.24\htmlunit-2.24.jar;C:\Users\acer\.m2\repository\xalan\xalan\2.7.2\xalan-2.7.2.jar;C:\Users\acer\.m2\repository\xalan\serializer\2.7.2\serializer-2.7.2.jar;C:\Users\acer\.m2\repository\org\apache\commons\commons-lang3\3.5\commons-lang3-3.5.jar;C:\Users\acer\.m2\repository\org\apache\httpcomponents\httpmime\4.5.2\httpmime-4.5.2.jar;C:\Users\acer\.m2\repository\net\sourceforge\htmlunit\htmlunit-core-js\2.23\htmlunit-core-js-2.23.jar;C:\Users\acer\.m2\repository\net\sourceforge\htmlunit\neko-htmlunit\2.24\neko-htmlunit-2.24.jar;C:\Users\acer\.m2\repository\xerces\xercesImpl\2.11.0\xercesImpl-2.11.0.jar;C:\Users\acer\.m2\repository\xml-apis\xml-apis\1.4.01\xml-apis-1.4.01.jar;C:\Users\acer\.m2\repository\net\sourceforge\cssparser\cssparser\0.9.21\cssparser-0.9.21.jar;C:\Users\acer\.m2\repository\org\w3c\css\sac\1.3\sac-1.3.jar;C:\Users\acer\.m2\repository\commons-io\commons-io\2.5\commons-io-2.5.jar;C:\Users\acer\.m2\repository\org\eclipse\jetty\websocket\websocket-client\9.2.20.v20161216\websocket-client-9.2.20.v20161216.jar;C:\Users\acer\.m2\repository\org\eclipse\jetty\jetty-util\9.2.20.v20161216\jetty-util-9.2.20.v20161216.jar;C:\Users\acer\.m2\repository\org\eclipse\jetty\jetty-io\9.2.20.v20161216\jetty-io-9.2.20.v20161216.jar;C:\Users\acer\.m2\repository\org\eclipse\jetty\websocket\websocket-common\9.2.20.v20161216\websocket-common-9.2.20.v20161216.jar;C:\Users\acer\.m2\repository\org\eclipse\jetty\websocket\websocket-api\9.2.20.v20161216\websocket-api-9.2.20.v20161216.jar;C:\Users\acer\.m2\repository\com\google\code\gson\gson\2.3.1\gson-2.3.1.jar;C:\Users\acer\.m2\repository\org\apache\httpcomponents\httpclient\4.3.4\httpclient-4.3.4.jar;C:\Users\acer\.m2\repository\org\apache\httpcomponents\httpcore\4.3.2\httpcore-4.3.2.jar;C:\Users\acer\.m2\repository\commons-logging\commons-logging\1.1.3\commons-logging-1.1.3.jar;C:\Users\acer\.m2\repository\commons-codec\commons-codec\1.6\commons-codec-1.6.jar;C:\Users\acer\.m2\repository\com\googlecode\json-simple\json-simple\1.1.1\json-simple-1.1.1.jar" com.intellij.rt.execution.junit.JUnitStarter -ideVersion5 -junit4 specs.sprintOne.TC_001_LoginSample_spec
1520759641134   geckodriver INFO    geckodriver 0.19.1
1520759641140   geckodriver INFO    Listening on 127.0.0.1:8942
1520759642011   mozrunner::runner   INFO    Running command: "C:\\Program Files\\Mozilla Firefox\\firefox.exe" "-marionette" "-profile" "C:\\Users\\acer\\AppData\\Local\\Temp\\rust_mozprofile.jGPMmTbag3iw"
1520759642327   addons.xpi  WARN    Error parsing extensions state: [Exception... "Component returned failure code: 0x80520012 (NS_ERROR_FILE_NOT_FOUND) [amIAddonManagerStartup.readStartupData]"  nsresult: "0x80520012 (NS_ERROR_FILE_NOT_FOUND)"  location: "JS frame :: resource://gre/modules/addons/XPIProvider.jsm :: loadExtensionState :: line 1554"  data: no] Stack trace: loadExtensionState()@resource://gre/modules/addons/XPIProvider.jsm:1554 < getInstallState()@resource://gre/modules/addons/XPIProvider.jsm:1589 < checkForChanges()@resource://gre/modules/addons/XPIProvider.jsm:3109 < startup()@resource://gre/modules/addons/XPIProvider.jsm:2188 < callProvider()@resource://gre/modules/AddonManager.jsm:269 < _startProvider()@resource://gre/modules/AddonManager.jsm:739 < startup()@resource://gre/modules/AddonManager.jsm:906 < startup()@resource://gre/modules/AddonManager.jsm:3090 < observe()@jar:file:///C:/Program%20Files/Mozilla%20Firefox/omni.ja!/components/addonManager.js:65
1520759643229   Marionette  INFO    Enabled via --marionette
Unable to read VR Path Registry from C:\Users\acer\AppData\Local\openvr\openvrpaths.vrpath
[Child 10700] WARNING: pipe error: 109: file z:/build/build/src/ipc/chromium/src/chrome/common/ipc_channel_win.cc, line 346
[Child 10700] WARNING: pipe error: 109: file z:/build/build/src/ipc/chromium/src/chrome/common/ipc_channel_win.cc, line 346
1520759645835   Marionette  INFO    Listening on port 52856
1520759646171   Marionette  DEBUG   Register listener.js for window 6442450945
1520759646375   geckodriver INFO    geckodriver 0.19.1
1520759646387   geckodriver INFO    Listening on 127.0.0.1:5497
1520759646950   mozrunner::runner   INFO    Running command: "C:\\Program Files\\Mozilla Firefox\\firefox.exe" "-marionette" "-profile" "C:\\Users\\acer\\AppData\\Local\\Temp\\rust_mozprofile.WwKvyKDi21YC"
1520759647155   addons.xpi  WARN    Error parsing extensions state: [Exception... "Component returned failure code: 0x80520012 (NS_ERROR_FILE_NOT_FOUND) [amIAddonManagerStartup.readStartupData]"  nsresult: "0x80520012 (NS_ERROR_FILE_NOT_FOUND)"  location: "JS frame :: resource://gre/modules/addons/XPIProvider.jsm :: loadExtensionState :: line 1554"  data: no] Stack trace: loadExtensionState()@resource://gre/modules/addons/XPIProvider.jsm:1554 < getInstallState()@resource://gre/modules/addons/XPIProvider.jsm:1589 < checkForChanges()@resource://gre/modules/addons/XPIProvider.jsm:3109 < startup()@resource://gre/modules/addons/XPIProvider.jsm:2188 < callProvider()@resource://gre/modules/AddonManager.jsm:269 < _startProvider()@resource://gre/modules/AddonManager.jsm:739 < startup()@resource://gre/modules/AddonManager.jsm:906 < startup()@resource://gre/modules/AddonManager.jsm:3090 < observe()@jar:file:///C:/Program%20Files/Mozilla%20Firefox/omni.ja!/components/addonManager.js:65
1520759647895   Marionette  INFO    Enabled via --marionette
1520759650640   Marionette  INFO    Listening on port 52883
1520759651100   Marionette  DEBUG   Register listener.js for window 6442450945

geb.driver.DriverCreationException: failed to create driver from callback 'script15207596390172071282656$_run_closure1$_closure3@51768776'

    at geb.driver.CallbackDriverFactory.getDriver(CallbackDriverFactory.groovy:35)
    at geb.driver.CachingDriverFactory.getDriver_closure3(CachingDriverFactory.groovy:85)
    at geb.driver.CachingDriverFactory.getDriver_closure3(CachingDriverFactory.groovy)
    at geb.driver.CachingDriverFactory$SimpleCache.get(CachingDriverFactory.groovy:32)
    at geb.driver.CachingDriverFactory.getDriver(CachingDriverFactory.groovy:84)
    at geb.Configuration.createDriver(Configuration.groovy:382)
    at geb.Configuration.getDriver(Configuration.groovy:371)
    at geb.Browser.getDriver(Browser.groovy:111)
    at geb.navigator.factory.BrowserBackedNavigatorFactory.<init>(BrowserBackedNavigatorFactory.groovy:35)
    at geb.Configuration.createNavigatorFactory(Configuration.groovy:417)
    at geb.Browser.createNavigatorFactory(Browser.groovy:133)
    at geb.Browser.getNavigatorFactory(Browser.groovy:121)
    at geb.Page.init(Page.groovy:144)
    at geb.Browser.createPage(Browser.groovy:859)
    at geb.Browser.to(Browser.groovy:550)
    at geb.Browser.to(Browser.groovy:539)
    at geb.spock.GebSpec.methodMissing(GebSpec.groovy:56)
    at specs.sprintOne.TC_001_LoginSample_spec.Step 0: Properties laden(TC_001_LoginSample_spec.groovy:14)
Caused by: org.openqa.selenium.SessionNotCreatedException: Unable to create new remote session. desired capabilities = Capabilities [{moz:firefoxOptions={binary=Optional.empty, args=[], legacy=null, logLevel=null, prefs={}, profile=org.openqa.selenium.firefox.FirefoxProfile@36676c1a}, firefox_profile=org.openqa.selenium.firefox.FirefoxProfile@36676c1a}], required capabilities = Capabilities [{moz:firefoxOptions={binary=Optional.empty, args=[], legacy=null, logLevel=null, prefs={}, profile=org.openqa.selenium.firefox.FirefoxProfile@36676c1a}, firefox_profile=org.openqa.selenium.firefox.FirefoxProfile@36676c1a}]
Build info: version: '3.3.1', revision: '5234b325d5', time: '2017-03-10 09:10:29 +0000'
System info: host: 'DESKTOP-KMHBAIB', ip: '192.168.220.1', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_131'
Driver info: driver.version: FirefoxDriver
    at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:126)
    at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:141)
    at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:82)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:604)
    at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:244)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:131)
    at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:218)
    at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:125)
    at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:137)
    at script15207596390172071282656.getDriver(script15207596390172071282656.groovy:131)
    at script15207596390172071282656.run_closure1$_closure3(script15207596390172071282656.groovy:103)
    at script15207596390172071282656.run_closure1$_closure3(script15207596390172071282656.groovy)
    at geb.driver.CallbackDriverFactory.getDriver(CallbackDriverFactory.groovy:29)
    ... 17 more

1520759651155   geckodriver INFO    geckodriver 0.19.1
1520759651162   geckodriver INFO    Listening on 127.0.0.1:7479
1520759651750   mozrunner::runner   INFO    Running command: "C:\\Program Files\\Mozilla Firefox\\firefox.exe" "-marionette" "-profile" "C:\\Users\\acer\\AppData\\Local\\Temp\\rust_mozprofile.gGnTCVSPMRcn"
1520759651983   addons.xpi  WARN    Error parsing extensions state: [Exception... "Component returned failure code: 0x80520012 (NS_ERROR_FILE_NOT_FOUND) [amIAddonManagerStartup.readStartupData]"  nsresult: "0x80520012 (NS_ERROR_FILE_NOT_FOUND)"  location: "JS frame :: resource://gre/modules/addons/XPIProvider.jsm :: loadExtensionState :: line 1554"  data: no] Stack trace: loadExtensionState()@resource://gre/modules/addons/XPIProvider.jsm:1554 < getInstallState()@resource://gre/modules/addons/XPIProvider.jsm:1589 < checkForChanges()@resource://gre/modules/addons/XPIProvider.jsm:3109 < startup()@resource://gre/modules/addons/XPIProvider.jsm:2188 < callProvider()@resource://gre/modules/AddonManager.jsm:269 < _startProvider()@resource://gre/modules/AddonManager.jsm:739 < startup()@resource://gre/modules/AddonManager.jsm:906 < startup()@resource://gre/modules/AddonManager.jsm:3090 < observe()@jar:file:///C:/Program%20Files/Mozilla%20Firefox/omni.ja!/components/addonManager.js:65
1520759652660   Marionette  INFO    Enabled via --marionette
Unable to read VR Path Registry from C:\Users\acer\AppData\Local\openvr\openvrpaths.vrpath
[Child 12052] WARNING: pipe error: 109: file z:/build/build/src/ipc/chromium/src/chrome/common/ipc_channel_win.cc, line 346
[Child 12052] WARNING: pipe error: 109: file z:/build/build/src/ipc/chromium/src/chrome/common/ipc_channel_win.cc, line 346
1520759655598   Marionette  INFO    Listening on port 52919
1520759655906   Marionette  DEBUG   Register listener.js for window 4294967297

geb.driver.DriverCreationException: failed to create driver from callback 'script15207596390172071282656$_run_closure1$_closure3@51768776'

    at geb.driver.CallbackDriverFactory.getDriver(CallbackDriverFactory.groovy:35)
    at geb.driver.CachingDriverFactory.getDriver_closure3(CachingDriverFactory.groovy:85)
    at geb.driver.CachingDriverFactory.getDriver_closure3(CachingDriverFactory.groovy)
    at geb.driver.CachingDriverFactory$SimpleCache.get(CachingDriverFactory.groovy:32)
    at geb.driver.CachingDriverFactory.getDriver(CachingDriverFactory.groovy:84)
    at geb.Configuration.createDriver(Configuration.groovy:382)
    at geb.Configuration.getDriver(Configuration.groovy:371)
    at geb.Browser.getDriver(Browser.groovy:111)
    at geb.report.PageSourceReporter.getPageSource(PageSourceReporter.groovy:42)
    at geb.report.PageSourceReporter.writePageSource(PageSourceReporter.groovy:38)
    at geb.report.PageSourceReporter.writeReport(PageSourceReporter.groovy:29)
    at geb.report.CompositeReporter.writeReport(CompositeReporter.groovy:31)
    at geb.Browser.report(Browser.groovy:931)
    at geb.spock.GebReportingSpec.report(GebReportingSpec.groovy:59)
    at geb.spock.GebReportingSpec.cleanup(GebReportingSpec.groovy:46)
Caused by: org.openqa.selenium.SessionNotCreatedException: Unable to create new remote session. desired capabilities = Capabilities [{moz:firefoxOptions={binary=Optional.empty, args=[], legacy=null, logLevel=null, prefs={}, profile=org.openqa.selenium.firefox.FirefoxProfile@1827a871}, firefox_profile=org.openqa.selenium.firefox.FirefoxProfile@1827a871}], required capabilities = Capabilities [{moz:firefoxOptions={binary=Optional.empty, args=[], legacy=null, logLevel=null, prefs={}, profile=org.openqa.selenium.firefox.FirefoxProfile@1827a871}, firefox_profile=org.openqa.selenium.firefox.FirefoxProfile@1827a871}]
Build info: version: '3.3.1', revision: '5234b325d5', time: '2017-03-10 09:10:29 +0000'
System info: host: 'DESKTOP-KMHBAIB', ip: '192.168.220.1', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_131'
Driver info: driver.version: FirefoxDriver
    at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:126)
    at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:141)
    at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:82)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:604)
    at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:244)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:131)
    at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:218)
    at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:125)
    at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:137)
    at script15207596390172071282656.getDriver(script15207596390172071282656.groovy:131)
    at script15207596390172071282656.run_closure1$_closure3(script15207596390172071282656.groovy:103)
    at script15207596390172071282656.run_closure1$_closure3(script15207596390172071282656.groovy)
    at geb.driver.CallbackDriverFactory.getDriver(CallbackDriverFactory.groovy:29)
    ... 14 more

你能在这方面指导我吗,因为我的要求是非常具体的推出多种语言的浏览器以及。GebConfig文件在Chrome上运行良好。

谢谢

共有1个答案

胡承载
2023-03-14

我可以通过执行以下设置来解决此问题:Selenium版本:3.6.0Firefox版本:56.0Geckodriver版本:0.19.1

然后在gebconfig.groovy中执行以下更改

FirefoxOptions options = new FirefoxOptions().setLogLevel(Level.OFF)
        options.addArguments("incognito")
        def firefoxDriver = new FirefoxDriver(options)
        firefoxDriver.manage().window().maximize()
        firefoxDriver

火狐发射成功。

 类似资料:
  • 我无法使用selenium webdriver 3.4.0启动Firefox浏览器

  • 请有人帮我解决这个问题。提前道谢。当运行java代码在模拟器中打开chrome浏览器时,我收到“无法启动Chromedriver会话:无法创建新会话。详细信息:未创建会话:此版本的Chromedriver仅支持chrome 83版”错误消息。

  • 我的代码: 例外情况 线程“main”java中出现异常。lang.IllegalStateException:驱动程序可执行文件不存在:C:\Users\sony\Downloads\chromedriver\U win32。在com.exe。谷歌。常见的基础先决条件。org上的checkState(premissions.java:534)。openqa。硒。遥远的服务司机服务。在org上检查

  • 线程“main”java.lang.IllegalStateException中的异常:驱动程序可执行文件的路径必须由WebDriver.Chrome.driver系统属性设置;有关更多信息,请参见https://github.com/seleniumhq/selenium/wiki/chromedriver。最新版本可从http://chromedriver.storage.googleapis

  • 我已经通过命令行java-jar Jenkins.war启动了Jenkins服务器。但是,当我尝试执行Jenkins参数化作业(maven测试)时,firefox会打开片刻,然后立即关闭。 如果我使用chrome浏览器,它在Jenkins的工作很好。 注意:同样的测试在火狐和chrome浏览器上执行得很好。

  • 我试图使用eclipse来运行Selenium Web驱动程序自动化,但无法打开浏览器窗口。调试日志显示没有错误,我成功地检索了网页的标题,如下所示: 调试日志:1496221115902 geckodriver信息监听127.0.0.1:39119 1496221116097 geckodriver::木偶信息启动浏览器/应用程序/火狐.app/contents/macos/firefox-bi