2012-10-11 90 views
9

我在本地机器上运行了selenium-server-standalone.jar,并且我想运行的测试在远程机器上编译,但是我不知道如何让测试连接到机器上这将运行浏览器。任何帮助赞赏。Selenium Webdriver远程设置

更新: 在我的本地机器(一个我将运行在浏览器上),我在我的远程机器上运行

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和我的T ests是用Java编写的

+0

你的硒测试用什么语言写的? –

+0

我的测试用java编写 – confusified

+1

我不建议改变implicitWait。将它保留为默认值0会给你更多的典型行为。大多数人使用WebDriverWait等FluentWait来为您提供更长的变量等待时间。避免将其更改为“20”秒。 – djangofan

回答

7

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

我已经在我的本地机器上安装了硒测试包。我在VM上运行它们。 硒设置是以下:

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(); 
    } 

..... 

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

希望这有助于你。

+0

seleniuim-server在浏览器的机器上运行还是在测试的机器上运行?我的测试是在我使用ssh的计算机上的命令行上运行的,并且我的浏览器位于我的本地计算机 – confusified

+1

(在当前项目中)上,selenium服务器运行在VM(远程计算机)上,浏览器运行在VM(远程计算机机器)。测试集在我的本地机器上,但我会将其提交到存储库中,将任务添加到Hudson-jenkins以从存储库中取出并远程运行。 Regards –

+0

您可以通过使用Docker容器来执行此操作。请参阅http://underthehood.meltwater.com/blog/2016/11/09/using-docker-with-selenium-server-to-run-your-browser-tests/和https://github.com/SeleniumHQ /泊坞窗硒 – vikramvi

相关问题