13

I have the selenium-server-standalone.jar running on my local machine, and the tests I want to run compiled on my remote machine, but I have no idea how I make the tests connect to the machine that will run the browser. Any help appreciated.

Update: On my local machine (the one I will be running the browser on) I ran

java -jar selenium-server-standalone-2.25.0.jar -mode hub

on my remote machine (that I will run the tests from) I ran

java -jar selenium-server-standalone-2.25.0.jar -role webDriver -hub http://**My ip*:4444

my code contains the following:

 @Before
    public void setUp() throws Exception {
            DesiredCapabilities capability = DesiredCapabilities.firefox();
            driver = new RemoteWebDriver(new URL("http://**My ip**:4444/wd/hub"),  
            capability);
            baseUrl = "http://phy05:8080";
            driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
            driver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);
            driver.manage().window().setSize(new Dimension(1920, 1080));

I am using Linux and my tests are written in Java

2
  • What language are your selenium tests written in? Commented Oct 11, 2012 at 9:41
  • 1
    I wouldn't recommend changing the implicitWait. Leaving it at the default of 0 is going to give you more typical behavior. Most people implement a FluentWait such as WebDriverWait to give you longer variable wait times. Avoid changing it to '20' seconds. Commented Jan 12, 2015 at 16:03

1 Answer 1

10

well. That's not a problem. I'd like to share how i resolved this issue. I got VM (virtual machine) with jdk installed and selenium server running on VM. VM has IP: 192.168.4.52 I connected to it through(RDC-remote desktop connection). Installed needed browser on it(firefox 15). Open browser. Disabled all the updates and other pop ups.

I've got selenium tests pack on my local machine. And I run them on my VM. Selenium setup is following:

import com.google.common.base.Function;
import com.thoughtworks.selenium.SeleneseTestBase;
import junit.framework.Assert;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.openqa.selenium.*;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.support.ui.FluentWait;
import org.openqa.selenium.support.ui.Wait;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
import org.springframework.core.io.support.PropertiesLoaderUtils;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.NoSuchElementException;
import java.util.Properties;
import java.util.concurrent.TimeUnit;


public class BaseSeleniumTest extends SeleneseTestBase {
    static WebDriver driver;


    @Value("login.base.url")
    private String loginBaseUrl;

    @BeforeClass
    public static void firefoxSetUp() throws MalformedURLException {

//        DesiredCapabilities capability = DesiredCapabilities.firefox();
        DesiredCapabilities capability = DesiredCapabilities.internetExplorer();

        driver = new RemoteWebDriver(new URL("http://192.168.4.52:4444/wd/hub"), capability);


//        driver = new FirefoxDriver();  //for local check

        driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
        driver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);
        driver.manage().window().setSize(new Dimension(1920, 1080));
    }
    @Before
    public void openFiretox() throws IOException {



        driver.get(propertyKeysLoader("login.base.url"));


    }


    @AfterClass
    public static void closeFirefox(){
        driver.quit();
    }

.....

this piece of code will run all the selenium tests on remote machine. in the string driver = new RemoteWebDriver(new URL("http://192.168.4.52:4444/wd/hub"), capability); you simply should mention IP of your machine and this should work.

Hope this helps you.

Sign up to request clarification or add additional context in comments.

3 Comments

So is the seleniuim-server run on the machine with the browser or the one with the tests? My tests are run from the command line on a machine I ssh into, and my browser is on my local machine
in my approach (on the current project) selenium server run on the VM(remote machine) and browser is on VM(remote machine) as well. Test set is on my local machine but I'm gonna to commit it into repository, add task to Hudson-jenkins to take them from repository and run remotely. Regards
You can do this by using docker container for Chrome browser. Refer to underthehood.meltwater.com/blog/2016/11/09/… and github.com/SeleniumHQ/docker-selenium

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.