【问题标题】:Selenium Webdriver remote setupSelenium Webdriver 远程设置
【发布时间】:2012-10-01 21:56:29
【问题描述】:

我有 selenium-server-standalone.jar 在我的本地机器上运行,我想运行的测试在我的远程机器上编译,但我不知道如何让测试连接到将运行浏览器。任何帮助表示赞赏。

更新: 在我的本地机器上(我将运行浏览器的机器)我跑了

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

在我的远程机器上(我将运行测试)我跑了

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

我的代码包含以下内容:

 @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));

我使用的是 Linux,我的测试是用 Java 编写的

【问题讨论】:

  • 你的 selenium 测试是用什么语言编写的?
  • 我不建议更改implicitWait。将其保留为默认值 0 将为您提供更典型的行为。大多数人实现 FluentWait(例如 WebDriverWait)来为您提供更长的可变等待时间。避免将其更改为“20”秒。

标签: java selenium selenium-webdriver webdriver


【解决方案1】:

好吧。这不是问题。我想分享一下我是如何解决这个问题的。 我得到了安装了 jdk 并在 VM 上运行 selenium 服务器的 VM(虚拟机)。虚拟机有 IP: 192.168.4.52 我通过(RDC-远程桌面连接)连接到它。在其上安装所需的浏览器(firefox 15)。打开浏览器。禁用所有更新和其他弹出窗口。

我的本​​地机器上有硒测试包。我在我的虚拟机上运行它们。 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();
    }

.....

这段代码将在远程机器上运行所有的 selenium 测试。 在字符串driver = new RemoteWebDriver(new URL("http://192.168.4.52:4444/wd/hub"), capability); 您只需提及您机器的 IP 即可。

希望对你有所帮助。

【讨论】:

  • 那么 selenuim-server 是在带有浏览器的机器上运行还是在带有测试的机器上运行?我的测试是在我 ssh 进入的机器上从命令行运行的,而我的浏览器在我的本地机器上
  • 在我的方法中(在当前项目中)硒服务器在 VM(远程机器)上运行,浏览器也在 VM(远程机器)上。测试集在我的本地机器上,但我要将它提交到存储库中,将任务添加到 Hudson-jenkins 以从存储库中获取它们并远程运行。问候
  • 您可以使用 Chrome 浏览器的 docker 容器来执行此操作。参考underthehood.meltwater.com/blog/2016/11/09/…github.com/SeleniumHQ/docker-selenium
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-11-08
  • 2018-12-14
  • 1970-01-01
  • 1970-01-01
  • 2018-01-06
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多