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

Safari无法启动新会话。可能的原因是远程服务器地址无效或浏览器启动失败

东郭展
2023-03-14

我正在尝试在Safari上运行我的Selenium测试。我可以在FireFox和IE上运行我的测试,它运行良好,但在Safari上不行。所以可能有人遇到了同样的问题,可以告诉我为什么它不起作用,是的,我已经将WebDriver添加到SafariExtencions:http://prntscr.com/809miw

我有这个错误:

2015-08-03 13:18:57.666:INFO::main: Logging initialized @169ms
[2015/08/03 13:18:57] [ID:69E814D] [Session Start]: Initializing Session...
[2015/08/03 13:18:58] [ID:69E814D] [Selenium]: Aug 03, 2015 1:18:58 PM org.openqa.selenium.safari.SafariDriverServer start
INFO: Server started on port 39280

[2015/08/03 13:18:58] [ID:69E814D] [Selenium]: Aug 03, 2015 1:18:58 PM org.openqa.selenium.safari.SafariDriverCommandExecutor start
INFO: Launching Safari

[2015/08/03 13:18:58] [ID:69E814D] [Selenium]: Aug 03, 2015 1:18:58 PM org.openqa.selenium.safari.SafariDriverCommandExecutor start
INFO: Waiting for SafariDriver to connect

[2015/08/03 13:18:59] [ID:69E814D] [Selenium]: Aug 03, 2015 1:18:59 PM org.openqa.selenium.safari.SafariDriverChannelHandler$1 operationComplete
INFO: Connection opened

[2015/08/03 13:18:59] [ID:69E814D] [Selenium]: Aug 03, 2015 1:18:59 PM org.openqa.selenium.safari.SafariDriverCommandExecutor start
INFO: Driver connected in 980 ms

[2015/08/03 13:18:59] [ID:69E814D] [Selenium]: Aug 03, 2015 1:18:59 PM org.openqa.selenium.safari.SafariDriverCommandExecutor stop
INFO: Shutting down

[2015/08/03 13:18:59] [ID:69E814D] [Selenium]: Aug 03, 2015 1:18:59 PM org.openqa.selenium.safari.SafariDriverCommandExecutor stop
INFO: Closing connection

[2015/08/03 13:18:59] [ID:69E814D] [Selenium]: Aug 03, 2015 1:18:59 PM org.openqa.selenium.safari.SafariDriverCommandExecutor stop
INFO: Stopping Safari

[2015/08/03 13:18:59] [ID:69E814D] [Selenium]: Aug 03, 2015 1:18:59 PM org.openqa.selenium.os.UnixProcess$SeleniumWatchDog destroyHarder
INFO: Command failed to close cleanly. Destroying forcefully (v2). org.openqa.selenium.os.UnixProcess$SeleniumWatchDog@2038ae61

[2015/08/03 13:18:59] [ID:69E814D] [Selenium]: Aug 03, 2015 1:18:59 PM org.openqa.selenium.safari.SafariDriverCommandExecutor stop
INFO: Stopping server

[2015/08/03 13:18:59] [ID:69E814D] [Selenium]: Aug 03, 2015 1:18:59 PM org.openqa.selenium.safari.SafariDriverServer stop
INFO: Stopping server

[2015/08/03 13:18:59] [ID:69E814D] [Selenium]: Aug 03, 2015 1:18:59 PM org.openqa.selenium.safari.SafariDriverCommandExecutor stop
INFO: Shutdown complete

[2015/08/03 13:18:59] [ID:69E814D] [Selenium]: Exception in thread "main" 
[2015/08/03 13:18:59] [ID:69E814D] [Selenium]: org.openqa.selenium.remote.UnreachableBrowserException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure.
Build info: version: '2.46.0', revision: '87c69e2', time: '2015-06-04 16:16:47'
System info: host: 'Vitaliii-PC', ip: '169.254.8.187', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_45'
Driver info: driver.version: SafariDriver
[2015/08/03 13:18:59] [ID:69E814D] [Selenium]:  at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:599)
[2015/08/03 13:18:59] [ID:69E814D] [Selenium]:  at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:242)
[2015/08/03 13:18:59] [ID:69E814D] [Selenium]:  at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:128)
[2015/08/03 13:18:59] [ID:69E814D] [Selenium]:  at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:141)
[2015/08/03 13:18:59] [ID:69E814D] [Selenium]:  at org.openqa.selenium.safari.SafariDriver.<init>(SafariDriver.java:58)
[2015/08/03 13:18:59] [ID:69E814D] [Selenium]:  at org.openqa.selenium.safari.SafariDriver.<init>(SafariDriver.java:51)
[2015/08/03 13:18:59] [ID:69E814D] [Selenium]:  at Kodak.AutoTest.Framework.Session.Start(Session.java:117)
[2015/08/03 13:18:59] [ID:69E814D] [Selenium]:  at Kodak.AutoTest.QBT.TC93CreateProject.main(TC93CreateProject.java:27)
[2015/08/03 13:18:59] [ID:69E814D] [Selenium]: Caused by: java.lang.ClassCastException: com.google.gson.JsonObject cannot be cast to java.lang.String
[2015/08/03 13:18:59] [ID:69E814D] [Selenium]:  at org.openqa.selenium.remote.JsonToBeanConverter.convert(JsonToBeanConverter.java:111)
[2015/08/03 13:18:59] [ID:69E814D] [Selenium]:  at org.openqa.selenium.remote.JsonToBeanConverter.convert(JsonToBeanConverter.java:42)
[2015/08/03 13:18:59] [ID:69E814D] [Selenium]:  at org.openqa.selenium.safari.SafariDriverCommandExecutor.execute(SafariDriverCommandExecutor.java:191)
[2015/08/03 13:18:59] [ID:69E814D] [Selenium]:  at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:578)
[2015/08/03 13:18:59] [ID:69E814D] [Selenium]:  ... 7 more

以下是我选择浏览器的方式:

switch(this.type)
        {
            case IE:
                File file = new File(this.config().getParam(ConfigFacade.IEDriverPath_Key));
                System.setProperty("webdriver.ie.driver", file.getAbsolutePath());
                //System.setProperty("webdriver.ie.logfile, ""); // TODO: here somehow redirect log to stream.
                this.driver = new InternetExplorerDriver();
                break;
            case Chrome:
                File chromeFile = new File(this.config().getParam(ConfigFacade.ChromeDriverPath_Key));
                System.setProperty("webdriver.chrome.driver", chromeFile.getAbsolutePath());
                this.driver = new ChromeDriver();
                break;
            case FireFox:
                this.driver = new FirefoxDriver();
                break;
            case Safari:
                this.driver = new SafariDriver();
                break;
            default:
                throw new TestException(String.format("Browser (%1s) is not implemented yet", this.type.toString()));
        }

共有1个答案

瞿博学
2023-03-14

SafariDriver仅适用于OS X。从您的日志中可以看出,您正在尝试在Windows 7上执行它。您可以在此处查看支持的操作系统和浏览器:http://docs.seleniumhq.org/about/platforms.jsp

 类似资料: