我已经完成了研究并发现了其他相关问题。没有人有帮助。
至今:
拥有最新版本的 selenium
安装了旧版本的火狐
我在 Windows 7 上有 Eclipse,我创建了一个 .war 并在 localhost:8080/JSPprojectServlets (在 W7 上)下的 Eclipse 中进行了测试,它工作正常。selenium 打开 Firefox,获取 url,然后获取源。
然后我将 .war 文件放入我的 linux (ubuntu) 机器下的 tomcat7/webapps 并尝试使用我的 windows 7 机器在 192.168.1.102:8080/JSPprojectServlets 下访问它,但它不起作用并且它给出以下错误:
HTTP Status 500 - Failed to connect to binary FirefoxBinary(/usr/bin/firefox) on port 7055; process output follows:
type Exception report
message Failed to connect to binary FirefoxBinary(/usr/bin/firefox) on port 7055; process output follows:
description The server encountered an internal error that prevented it from fulfilling this request.
exception
org.openqa.selenium.WebDriverException: Failed to connect to binary FirefoxBinary(/usr/bin/firefox) on port 7055; process output follows:
(process:32704): GLib-CRITICAL **: g_slice_set_config: assertion `sys_page_size == 0' failed
Error: no display specified
(process:32711): GLib-CRITICAL **: g_slice_set_config: assertion `sys_page_size == 0' failed
Error: no display specified
Build info: version: '2.32.0', revision: '6c40c18', time: '2013-04-09 17:23:22'
System info: os.name: 'Linux', os.arch: 'amd64', os.version: '3.8.0-29-generic', java.version: '1.7.0_25'
Driver info: driver.version: FirefoxDriver
org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.start(NewProfileExtensionConnection.java:118)
org.openqa.selenium.firefox.FirefoxDriver.startClient(FirefoxDriver.java:244)
org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:110)
org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:190)
org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:183)
org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:179)
org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:92)
org.blah.blah.XmlServlet.doGet(XmlServlet.java:25)
javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
root cause
org.openqa.selenium.firefox.NotConnectedException: Unable to connect to host 127.0.0.1 on port 7055 after 45000 ms. Firefox console output:
(process:32704): GLib-CRITICAL **: g_slice_set_config: assertion `sys_page_size == 0' failed
Error: no display specified
(process:32711): GLib-CRITICAL **: g_slice_set_config: assertion `sys_page_size == 0' failed
Error: no display specified
org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.start(NewProfileExtensionConnection.java:106)
org.openqa.selenium.firefox.FirefoxDriver.startClient(FirefoxDriver.java:244)
org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:110)
org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:190)
org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:183)
org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:179)
org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:92)
org.blah.blah.XmlServlet.doGet(XmlServlet.java:25)
javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
note The full stack trace of the root cause is available in the Apache Tomcat/7.0.35 logs.
我的代码看起来像这样
package org.blah.blah;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
//import org.openqa.selenium.chrome.ChromeDriver;
public class XmlServlet extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//System.out.println("Hello from GET method.");
PrintWriter writer = response.getWriter();
writer.println("<h3></h3>");
WebDriver driver = new FirefoxDriver();
driver.get("http://google.com");
writer.println(driver.getPageSource());
}
}
更新:
当我使用 HtmlUnitDriver 它工作 192.168.1.102:8080/JSPprojectServlets
显然由于某种原因它无法打开Firefox。我在 W7 64bit 并且安装了 FF10 仍然没有。