次世代Selenium IDEと唱われている、Selenium Builderを試したメモ。
次世代Selenium IDE
次世代という意味は、Selenium2 、 つまりWebdriverをサポートしているということ。
Selenium IDEは Selenium1(or RemoteConsole RC)をサポートしている。
Selenium Builderの準備
Selenium Builderは forefoxのブラグイン。 なので、まずはfirefoxをインストール。
次に、以下からプラグインをインストール。
firefoxを再起動後、Ctrl+Alt+B or メニュー -> 開発ツール -> Launch Senium Builder.
Selenium Builderについては、以下の記事がとても詳しい。Special Thanks!!
まとまったドキュメントはここ。
ruby selenium webdriverの準備
rubyから seleniumを利用するために、selenium-webdriverを利用する。
gem install selenium-webdriver
プロキシ配下では以下。
gem install selenium-webdriver -r -p http://username:password@proxy.hostname:port
Windows環境のワナ
Windows環境でgem installを動かすためには、devkitのインストールが必要。 RubyInstallerと Devkitをセットでインストールする必要がある。
Cygwin環境のワナ
そもそも、Cygwin環境では 依存パッケージのffiがバグっててインストールできない。
Cygwin64bit版は依存しているffiライブラリがバグってる! パッチを当てる必要があるという茨の道。
$ gem install selenium-webdriver Building native extensions. This could take a while... ERROR: Error installing selenium-webdriver: ERROR: Failed to build gem native extension. /usr/bin/ruby.exe extconf.rb checking for ffi.h... *** extconf.rb failed *** Could not create Makefile due to some reason, probably lack of necessary libraries and/or headers. Check the mkmf.log file for more
回避方法をためしてみても、自分の環境ではうまくいかなかったので諦め。
Rubyコードを生成
自動化したいページで右クリックする。
SeleniumBuilderが立ち上がる。記録の開始を選択して、作業を記録。
記録が終わったら、ツールバー -> ファイル -> エクスポートを選択。
Selenium2としては以下の形式へExportできる(2014/5現在)
- JSON
- Java(Junit/TestNG)
- Ruby
- Python
- PHP
- Node.JS
- C#
Selenium1としてExportするとさらに対応言語が多くなる。
- HTML
- Groovry
- Perl
Selenium1だと、RubyのRSpecやtextunitにも対応しているようだ。 もっともっと多くなるのは時間の問題だろう。スゴい!
Rubyを選択して、Rubyのコードを生成。
require 'rubygems' require 'selenium-webdriver' wd = Selenium::WebDriver.for :firefox wd.get "https://www.google.co.jp/" wd.find_element(:id, "lst-ib").click wd.find_element(:id, "lst-ib").clear wd.find_element(:id, "lst-ib").send_keys "Selenium Builder" wd.find_element(:css, "div.tsf-p").click wd.find_element(:name, "btnK").click wd.quit
selenium-webdriverがrequireされいてるところに注目されたし。
Rubyコードを実行
生成したコードをコマンドラインから実行するだけ!こんなに簡単だとは!