Selenium 2 webdriver - 连接到 http://localhost:7055 被拒绝

发布于 2024-11-26 13:53:49 字数 1537 浏览 2 评论 0原文

我正在尝试使用selenium-java:2.2.0,但我不断收到此错误:

org.openqa.selenium.WebDriverException: org.apache.http.conn.HttpHostConnectException: Connection to http://localhost:7055 refused
System info: os.name: 'Linux', os.arch: 'amd64', os.version: '2.6.18-238.12.1.el5', java.version: '1.6.0_26'
Driver info: driver.version: FirefoxDriver
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:406)
    at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:103)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:86)
    at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:121)
    at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:77)
    at com.lexmark.cloudprint.BaseSeleneseTestCase.setUp(BaseSeleneseTestCase.groovy:21)

通过这个简单的设置:

class BaseSeleneseTestCase {
    Selenium selenium
    FirefoxDriver driver

    @Rule public TestName name = new TestName();

    @Before
    public void setUp() {
        driver = new FirefoxDriver();

        def config = new ConfigSlurper(GrailsUtil.environment).parse(new File('grails-app/conf/Config.groovy').toURL())
        selenium = new WebDriverBackedSelenium(driver, (String) config.grails.serverURL);

        def GLOBAL_TIMEOUT_IN_MS = "10000"
        selenium.setTimeout(GLOBAL_TIMEOUT_IN_MS)
    }

在互联网上浏览,似乎很多人都遇到了同样的问题,但是我需要一些解决办法。有人让 selenium2 webdriver 在 Linux 上工作吗?如果是这样,怎么办?

I'm trying to use selenium-java:2.2.0, and I keep getting this error:

org.openqa.selenium.WebDriverException: org.apache.http.conn.HttpHostConnectException: Connection to http://localhost:7055 refused
System info: os.name: 'Linux', os.arch: 'amd64', os.version: '2.6.18-238.12.1.el5', java.version: '1.6.0_26'
Driver info: driver.version: FirefoxDriver
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:406)
    at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:103)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:86)
    at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:121)
    at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:77)
    at com.lexmark.cloudprint.BaseSeleneseTestCase.setUp(BaseSeleneseTestCase.groovy:21)

With this simple setup:

class BaseSeleneseTestCase {
    Selenium selenium
    FirefoxDriver driver

    @Rule public TestName name = new TestName();

    @Before
    public void setUp() {
        driver = new FirefoxDriver();

        def config = new ConfigSlurper(GrailsUtil.environment).parse(new File('grails-app/conf/Config.groovy').toURL())
        selenium = new WebDriverBackedSelenium(driver, (String) config.grails.serverURL);

        def GLOBAL_TIMEOUT_IN_MS = "10000"
        selenium.setTimeout(GLOBAL_TIMEOUT_IN_MS)
    }

Poking around the internet, it seems like many people are having the same issue, but I need some kind of work around. Has anyone gotten selenium2 webdriver to work on linux? If so, how?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

大姐,你呐 2024-12-03 13:53:50

使用 WebDriverBackedSelenium 意味着您要求连接到远程控制的驱动程序。如果这就是你想要的,我认为你必须部署远程控制的 selenium 服务器。

如果您只想直接在 Firefox 中执行测试(我的意思是,没有 RemoteControl Selenium),您可以完全避免使用 WebDriverBackedSelenium,如下所示:

FirefoxDriver driver;
driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
[...]
driver.get(myTestUrl);
driver.findElement(By.xpath(myElementXpath)).click();

阅读测试的其余部分将有助于更好地理解您的问题:如何调用测试方法、断言等。

更新 可以使用基本的 WebDriver 接口在实现之间进行切换(例如,更改浏览器)。

像这样的事情:

在基本测试类中:

public abstract class WebDriverBaseTest {

    protected WebDriver driver;

    @Before
    public void setUp() throws Exception {
        setDriverForTest();
    }

    protected abstract void setDriverForTest();

    // Rest of tests here ...
}

为每个浏览器扩展这个类来测试:

public class FirefoxTest extends WebDriverBaseTest {

    @Override
    protected void setDriverForTest() {
        driver = new FirefoxDriver();
    }
}

public class HtmlUnitTest extends WebDriverBaseTest {

    @Override
    protected void setDriverForTest() {
        HtmlUnitDriver htmlUnitDriver = new HtmlUnitDriver(BrowserVersion.FIREFOX_3_6);
        htmlUnitDriver.setJavascriptEnabled(true);
        driver = htmlUnitDriver;
    }
}

这是您需要的吗?

Using WebDriverBackedSelenium means you're asking to connect to a remote-controlled Driver. If that is what you wants, I think you have to deploy the remote controlled selenium server.

If you only want to execute your tests directly in Firefox (I mean, no RemoteControl Selenium), you can avoid using WebDriverBackedSelenium at all, with something like this:

FirefoxDriver driver;
driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
[...]
driver.get(myTestUrl);
driver.findElement(By.xpath(myElementXpath)).click();

It would be useful to better understand your problem to read the rest of your test: how do you call test methods, assertions and so on.

UPDATE It's possible to use the base WebDriver interface in order to switch between implementations (to change browser, for example).

Something like this:

in base test class:

public abstract class WebDriverBaseTest {

    protected WebDriver driver;

    @Before
    public void setUp() throws Exception {
        setDriverForTest();
    }

    protected abstract void setDriverForTest();

    // Rest of tests here ...
}

Extend this class for every browser to test:

public class FirefoxTest extends WebDriverBaseTest {

    @Override
    protected void setDriverForTest() {
        driver = new FirefoxDriver();
    }
}

public class HtmlUnitTest extends WebDriverBaseTest {

    @Override
    protected void setDriverForTest() {
        HtmlUnitDriver htmlUnitDriver = new HtmlUnitDriver(BrowserVersion.FIREFOX_3_6);
        htmlUnitDriver.setJavascriptEnabled(true);
        driver = htmlUnitDriver;
    }
}

Is this what you needed?

诗笺 2024-12-03 13:53:50

请检查您的 Firefox 版本,也许新的 Firefox 需要更高的 Selenium 驱动程序。
目前我必须升级到 Firefox 29.0 的 selenium 驱动程序 2.39.0。

Please check the version of your firefox, maybe a new firefox need a higher selenium driver.
At the moment i must upgrade to selenium driver 2.39.0 for firefox 29.0.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文