SeleniumのServerとClientのプロトコルドキュメントを読むと、Selenium Clientのインスタンスを作るときにバージョンやプラットフォームを指定できるようになっているみたいなんだけど、どうも無視されている気がしたので調べてみました。
use strict; use warnings; use Selenium::Remote::Driver; my $driver = Selenium::Remote::Driver->new( browser_name => 'firefox', version => '3.5', platform => 'MAC', ); $driver->get('http://www.google.com/');
結論
standaloneサーバーの起動時に、-browserを組み合わせたときにだけ効くオプションだと思います。
公式ドキュメントの「Grid2 - selenium - Browser automation framework - Google Project Hosting」に以下のように、つらつらと書いてあったので・・
Configuring the nodes
By default, this starts 11 browsers : 5 Firefox, 5 Chrome, 1 Internet Explorer. The maximum number of concurrent tests is set to 5 by default. To change this and other browser settings, you can pass in parameters to each -browser switch (each switch represents a node based on your parameters). If you use the -browser parameter, the default browsers will be ignored and only what you specify command line will be used.This setting starts 5 Firefox 3.6 nodes on a linux machine.
If your remote machine has multiple versions of Firefox you’d like to use, you can map the location of each binary to a particular version on the same machine:
- browser browserName=firefox,version=3.6,firefox_binary=/home/myhomedir/firefox36/firefox,maxInstances=3,platform=LINUX -browser browserName=firefox,version=4,firefox_binary=/home/myhomedir/firefox4/firefox,maxInstances=4,platform=LINUX
Tip: If you need to provide a space somewhere in your browser parameters, then surround the parameters with quotation marks:
gridとstandaloneを組み合わせて使うときに効果を発揮するオプションなのかなーと思いました。
以下、検証方法です。
検証方法
Firefox3.6を入手
以下のURLからFirefox3.6を入手してきました。Applicationsにインストールはせず、デスクトップにコピーしました。
Selenium Server
続いて、standaloneモードでseleniumを起動。
java -jar selenium-server-standalone-2.15.0.jar -role node -hub http://localhost:4444/grid/register -browser browserName=firefox,version=3.6,firefox_binary=<3.6のFirefoxバイナリパス>,maxInstances=3,platform=MAC
Selenium Client
vol.1はPerlで書きましたが、まだPerlのライブラリがgrid環境に適応していなかったようなので、vol2ではjavaで書きました。
import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.remote.DesiredCapabilities; import org.openqa.selenium.remote.RemoteWebDriver; import org.openqa.selenium.Platform; import java.net.URL; public class Selenium2Example { public static void main(String[] args) { try { DesiredCapabilities capabilities = new DesiredCapabilities("firefox", "3.6", Platform.MAC); WebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capabilities); // And now use this to visit Google driver.get("http://www.google.com"); // Find the text input element by its name WebElement element = driver.findElement(By.name("q")); // Enter something to search for element.sendKeys("Cheese!"); // Now submit the form. WebDriver will find the form for us from the element element.submit(); // Check the title of the page System.out.println("Page title is: " + driver.getTitle()); //Close the browser driver.quit(); } catch (java.net.MalformedURLException e) { } } }
キャプチャ
意図したとおりの3.6が起動しました。