Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selenium 2 webdriver - connection to http://localhost:7055 refused

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?

like image 577
Stefan Kendall Avatar asked Nov 20 '25 09:11

Stefan Kendall


1 Answers

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?

like image 110
think01 Avatar answered Nov 22 '25 21:11

think01