Created
May 14, 2013 08:11
-
-
Save shinofara/5574432 to your computer and use it in GitHub Desktop.
selenium webdriverを使って、MacとLinux間でリモート、クライアントの関係を作成し、テストを実行するまで。Ruby Version ref: http://qiita.com/items/426b9d79fb1037b844e9
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sudo su | |
cd /usr/local/src/ | |
curl -O https://selenium.googlecode.com/files/selenium-server-standalone-2.32.0.jar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
java -jar selenium-server-standalone-2.32.0.jar -role hub |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mkdir -p ~/src | |
cd ~/src | |
curl -O https://selenium.googlecode.com/files/selenium-server-standalone-2.32.0.jar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
java -jar selenium-server-standalone-2.32.0.jar -role webdriver -hub http://<<リモートサーバのIP OR HOST>>:4444/grid/register |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sudo gem install selenium-webdriver |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ruby selenium.rb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Run options: | |
# Running tests: | |
[1/1] GoogleSearchTest#test_search_schoo"schoo - Google \u691C\u7D22" | |
"schoo\uFF08\u30B9\u30AF\u30FC\uFF09 WEB-campus" | |
Finished tests in 19.673129s, 0.0508 tests/s, 0.1525 assertions/s. | |
1 tests, 3 assertions, 0 failures, 0 errors, 0 skips | |
ruby -v: ruby 2.0.0p0 (2013-02-24 revision 39474) [x86_64-darwin12.2.0] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "test/unit" | |
require "rubygems" | |
require "selenium-webdriver" | |
· | |
class GoogleSearchTest < Test::Unit::TestCase | |
· | |
def setup | |
# 127.0.0.1なのは、ローカルにクライアント・サーバを起動しているからだよ | |
@driver = Selenium::WebDriver.for :remote, :url => "http://127.0.0.1:5555/wd/hub", :desired_capabilities => :firefox | |
end | |
· | |
def teardown | |
@driver.quit | |
end | |
· | |
def test_search_schoo | |
# 1. google検索ページへ遷移 | |
@driver.navigate.to "http://www.google.co.jp/" | |
# 2. 遷移先のページタイトルが「Google」である事 | |
assert_equal( "Google", @driver.title) | |
# 3. input name='q'のエレメントを取得 | |
element = @driver.find_element(:name, 'q') | |
# 4. schooをエレメントに送信 | |
element.send_keys "schoo" | |
# 5. 送信ボタンを押す | |
element.submit | |
# 6. 2秒ほど待ちますよ | |
sleep(2) | |
# 7. 遷移先のページタイトルを出力しちゃうよ | |
p @driver.title | |
# 8. 検索結果にschooという文言が存在するかチェックしちゃえ、存在しない場合はテスト失敗、そしてエラー文言出力 | |
assert( /.*schoo.*/ =~ @driver.title, "検索結果にschooが存在しない。") | |
# 9. schoo(スクー) WEB-campusというリンクをクリック | |
@driver.find_element(:link_text, 'schoo(スクー) WEB-campus').click | |
# 10. また2秒ほど、描画待ちなんで | |
sleep(2) | |
# 11. 遷移先のページタイトルを出力 | |
p @driver.title | |
# 12. schoo(スクー) WEB-campusというタイトルだよねー? | |
assert( "schoo(スクー) WEB-campus" == @driver.title, "クリックしたリンクが想定外のページ") | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment