簡體   English   中英

Selenium Webdriver遠程設置

[英]Selenium Webdriver remote setup

我在我的本地機器上運行了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編寫的

好。 那不是問題。 我想分享一下我是如何解決這個問題的。 我安裝了jdk的VM(虛擬機)和在VM上運行的selenium服務器。 VM有IP:192.168.4.52我通過(RDC-遠程桌面連接)連接到它。 安裝了所需的瀏覽器(firefox 15)。 打開瀏覽器。 禁用所有更新和其他彈出窗口。

我的本地機器上有selenium測試包。 我在我的VM上運行它們。 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,這應該有用。

希望這對你有所幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM