#!ruby -Ks require "runit/testcase" require "runit/cui/testrunner" require 'ie_lib' class TestIE < RUNIT::TestCase def test_initialize() assert_equal(@ie.visible, true) # IEは可視属性ONになってるはず @ie.quit @ie=IE.new(false) assert_equal(@ie.visible, false) # IEは可視属性ONになってるはず @ie.visible = true end def test_navigate() @ie.navigate("http://www.yahoo.co.jp/") # wait_stableが無くてもちゃんと待つはず assert_equal("Yahoo! JAPAN", @ie.LocationName) assert_equal("http://www.yahoo.co.jp/", @ie.LocationURL) end def test_document_frames() # フレームがない場合 @ie.navigate("http://www.tech-notes.dyndns.org/") doc = @ie.document assert_equal(0,doc.frames.size) # フレームがある場合 @ie.navigate("http://www.tech-notes.dyndns.org/testcase/") assert_equal(2,doc.frames.size) # フレーム指定 assert_equal("MENU", @ie.document.frames[0].document.head.tags("TITLE")[0].innerText) end def test_document_all() @ie.navigate("http://www.tech-notes.dyndns.org/") assert_equal(true,@ie.document.all.size > 10) # 要素の数がある程度出ればいいや、という適当なテスト assert_equal("!",@ie.document.all[0].tagName) # 最初の要素はコレらしい assert_equal("IE::TagElementCollection",@ie.document.all.type.to_s) end def test_document_tags() @ie.navigate("http://www.tech-notes.dyndns.org/") assert_equal("IE::TagElement",@ie.document.tags("HEAD")[0].type.to_s) assert_equal("My Technical Notes",@ie.document.tags("HEAD")[0].innerText) end def test_document_head() @ie.navigate("http://www.tech-notes.dyndns.org/") assert_equal("My Technical Notes",@ie.document.head.innerText) assert_equal(3,@ie.document.head.all.size) end def test_document_body() @ie.navigate("http://www.tech-notes.dyndns.org/") assert_equal("IE::TagElement",@ie.document.body.type.to_s) assert_equal("H1",@ie.document.body.all[0].tagName) end def test_tagelementcollection_index @ie.navigate("http://www.tech-notes.dyndns.org/") assert_equal("H1",@ie.document.body.all[0].tagName) assert_equal("Contents",@ie.document.body.tags("H2")[1].innerText) end def test_tagelementcollection_size @ie.navigate("http://www.tech-notes.dyndns.org/") assert_equal(1,@ie.document.body.tags("H1").size) assert_equal(2,@ie.document.body.tags("H2").size) end def test_tagelementcollection_each @ie.navigate("http://www.tech-notes.dyndns.org/") @ie.document.body.tags("H2").each {|h2_element| assert_equal("What's New",h2_element.innerText) assert_equal("H2",h2_element.tagName) break } end def test_tagelementcollection_get_by_value @ie.navigate("http://www.google.com/") assert_equal("INPUT",@ie.document.tags("INPUT").get_tag_by_title("Google").tagName) assert_equal("INPUT",@ie.document.tags("INPUT").get_tag_by_value("Google").tagName) assert_equal("http://www.google.co.jp/grphp?hl=ja&tab=wg&ie=UTF-8&oe=UTF-8", @ie.document.tags("A").get_tag_by_text("グループ").href) @ie.navigate("http://tv.yahoo.co.jp/") assert_equal(47,@ie.document.tags("SELECT").get_tag_by_option("広島").all.size) end def setup() @ie =IE.new end def teardown() @ie.quit sleep 3 end end if ARGV.size == 0 RUNIT::CUI::TestRunner.run(TestIE.suite) else ARGV.each{|test_method| RUNIT::CUI::TestRunner.run(TestIE.new(test_method)) } end