2012-10-11 15 views
9

ローカルマシンでselenium-server-standalone.jarを実行しています。リモートマシンでコンパイルしたテストを実行したいのですが、どのようにテストをマシンに接続するかわかりませんブラウザを起動します。どんな助けもありがたい。Selenium Webdriverリモートセットアップ

更新: 私のローカルマシン(私は上でブラウザを実行します1)で私は、リモートマシン上で

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で書かれています

+0

セレンテストはどの言語で書かれていますか? –

+0

私のテストはJavaで書かれています – confusified

+1

私はimplicitWaitの変更をお勧めしません。デフォルトのままにしておくと、より典型的な動作が得られます。ほとんどの人はWebDriverWaitなどのFluentWaitを実装して、より長い可変待ち時間を与えます。 「20」秒に変更しないでください。 – djangofan

答えて

7

よく。それは問題じゃない。私はこの問題をどのように解決したかを共有したいと思います。 jdkがインストールされたVM(仮想マシン)とVM上で動作している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

私のアプローチ(現在のプロジェクト)では、VM(リモートマシン)上で実行され、ブラウザーはVMマシン)も同様です。テストセットは私のローカルマシン上にありますが、リポジトリにコミットし、Hudson-jenkinsにタスクを追加してリポジトリから取り出し、リモートで実行します。 よろしくお願いします。 –

+0

これは、Chromeブラウザ用のドッカーコンテナを使用して行うことができます。 http://underthehood.meltwater.com/blog/2016/11/09/using-docker-with-selenium-server-to-run-your-browser-tests/およびhttps://github.com/SeleniumHQを参照してください。 /ドッカー - セレン – vikramvi