简体   繁体   English

Selenium Webdriver远程设置

[英]Selenium Webdriver remote setup

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. 我在我的本地机器上运行了selenium-server-standalone.jar,我想在远程机器上编译运行的测试,但我不知道如何让测试连接到将运行浏览器的机器。 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 我使用的是Linux,我的测试是用Java编写的

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. 我安装了jdk的VM(虚拟机)和在VM上运行的selenium服务器。 VM has IP: 192.168.4.52 I connected to it through(RDC-remote desktop connection). VM有IP:192.168.4.52我通过(RDC-远程桌面连接)连接到它。 Installed needed browser on it(firefox 15). 安装了所需的浏览器(firefox 15)。 Open browser. 打开浏览器。 Disabled all the updates and other pop ups. 禁用所有更新和其他弹出窗口。

I've got selenium tests pack on my local machine. 我的本地机器上有selenium测试包。 And I run them on my VM. 我在我的VM上运行它们。 Selenium setup is following: Selenium设置如下:

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. 这段代码将运行远程机器上的所有selenium测试。 in the string driver = new RemoteWebDriver(new URL("http://192.168.4.52:4444/wd/hub"), capability); 在字符串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. 你应该提一下机器的IP,这应该有用。

Hope this helps you. 希望这对你有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM