PageRenderTime 99ms CodeModel.GetById 29ms RepoModel.GetById 1ms app.codeStats 0ms

/firewatir/unittests/div_test.rb

https://github.com/DanielVartanov/firewatir-enhancements
Ruby | 276 lines | 220 code | 45 blank | 11 comment | 0 complexity | b66db192461cc256087eefbde1727188 MD5 | raw file
  1. # feature tests for Divs, Spans and P's
  2. # revision: $Revision: 1.0 $
  3. $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..') unless $SETUP_LOADED
  4. require 'unittests/setup'
  5. class TC_Divs < Test::Unit::TestCase
  6. def setup
  7. goto_page("div.html")
  8. end
  9. def test_divs
  10. assert_raises(UnknownObjectException) {browser.div(:id , "div77").click }
  11. assert_raises(UnknownObjectException) {browser.div(:title , "div77").click }
  12. assert(browser.text_field(:name, "text1").verify_contains("0") )
  13. browser.div(:id , "div3").click
  14. assert(browser.text_field(:name, "text1").verify_contains("1") )
  15. browser.div(:id , "div4").click
  16. assert(browser.text_field(:name, "text1").verify_contains("0") )
  17. end
  18. tag_method :test_show_all_objects, :fails_on_ie
  19. def test_show_all_objects
  20. assert_equal(36, browser.show_all_objects.length)
  21. assert_equal(3,browser.div(:id,"text_fields1").show_all_objects.length)
  22. assert_equal(8,browser.text_fields.length)
  23. assert_equal(3,browser.div(:id,"text_fields1").text_fields.length)
  24. end
  25. def test_div_properties
  26. assert_raises(UnknownObjectException) {browser.div(:id , "div77").text }
  27. assert_raises(UnknownObjectException) {browser.div(:title , "div77").text }
  28. assert_equal("This div has an onClick that increments text1", browser.div(:id , "div3").text.strip )
  29. assert_equal("This text is in a div with an id of div1 and title of test1",browser.div(:title , "Test1").text.strip )
  30. assert_raises(UnknownObjectException) {browser.div(:id , "div77").class_name }
  31. assert_equal("blueText" , browser.div(:id , "div2").class_name )
  32. assert_equal("" , browser.div(:id , "div1").class_name )
  33. assert_raises(UnknownObjectException) {browser.div(:index , 44).class_name }
  34. assert_equal("div1" , browser.div(:index , 1).id )
  35. assert_equal("" , browser.div(:index , 1).class_name )
  36. assert_equal("blueText" , browser.div(:index , 2).class_name )
  37. assert_equal("" , browser.div(:index , 2).value)
  38. #assert_equal(false , browser.div(:index , 2).disabled)
  39. assert_equal("" , browser.div(:index , 2).name)
  40. assert_equal("div2", browser.div(:index , 2).id)
  41. #puts browser.div(:id,"text_fields1").to_s
  42. end
  43. def test_div_iterator
  44. assert_equal( 7 , browser.divs.length)
  45. assert_equal( "div1" , browser.divs[1].id )
  46. index =1
  47. browser.divs.each do |s|
  48. # puts "each - div= " + s.to_s
  49. assert_equal(browser.div(:index, index ).name , s.name )
  50. assert_equal(browser.div(:index, index ).id , s.id )
  51. assert_equal(browser.div(:index, index ).class_name , s.class_name )
  52. index +=1
  53. end
  54. assert_equal(index-1, browser.divs.length) # -1 as we add 1 at the end of the loop
  55. end
  56. def test_objects_in_div
  57. assert(browser.div(:id, 'buttons1').button(:index,1).exists? )
  58. assert(!browser.div(:id, 'buttons1').button(:index,3).exists? )
  59. assert(browser.div(:id, 'buttons1').button(:name,'b1').exists? )
  60. browser.div(:id, 'buttons1').button(:name,'b1').click
  61. assert(browser.div(:id, 'buttons2').button(:index,1).exists? )
  62. assert(browser.div(:id, 'buttons2').button(:index,2).exists? )
  63. assert(!browser.div(:id, 'buttons1').button(:index,3).exists? )
  64. browser.div(:id, 'buttons1').button(:index,1).click
  65. assert_equal( 'button1' , browser.div(:id , 'text_fields1').text_field(:index,1).value)
  66. #assert_equal( 3 , browser.div(:id , 'text_fields1').text_fields.length )
  67. browser.div(:id, 'text_fields1').text_field(:name, 'div_text1').set("drink me")
  68. assert_equal("drink me", browser.div(:id, 'text_fields1').text_field(:name, 'div_text1').getContents)
  69. end
  70. #---- Span Tests ---
  71. def test_spans
  72. assert_raises(UnknownObjectException) {browser.span(:id , "span77").click }
  73. assert_raises(UnknownObjectException) {browser.span(:title , "span77").click }
  74. assert(browser.text_field(:name, "text2").verify_contains("0") )
  75. browser.span(:id , "span3").click
  76. assert(browser.text_field(:name, "text2").verify_contains("1") )
  77. browser.span(:id , "span4").click
  78. assert(browser.text_field(:name, "text2").verify_contains("0") )
  79. #puts browser.span(:id,"text_fields1").to_s
  80. end
  81. def test_span_properties
  82. assert_raises(UnknownObjectException) {browser.span(:id , "span77").text }
  83. assert_raises(UnknownObjectException) {browser.span(:title , "span77").text }
  84. assert_equal("This span has an onClick that increments text2" , browser.span(:id , "span3").text.strip )
  85. assert_equal("This text is in a span with an id of span1 and title of test2" , browser.span(:title , "Test2").text.strip )
  86. assert_raises(UnknownObjectException) {browser.span(:id , "span77").class_name }
  87. assert_equal("blueText" , browser.span(:id , "span2").class_name )
  88. assert_equal("" , browser.span(:id , "span1").class_name )
  89. assert_raises(UnknownObjectException) {browser.span(:index , 44).class_name }
  90. assert_equal("span1" , browser.span(:index , 1).id )
  91. assert_equal("" , browser.span(:index , 1).class_name )
  92. assert_equal("blueText" , browser.span(:index , 2).class_name )
  93. assert_equal("" , browser.span(:index , 2).value)
  94. #assert_equal(false , browser.span(:index , 2).disabled)
  95. assert_equal("" , browser.span(:index , 2).name)
  96. assert_equal("span2", browser.span(:index , 2).id)
  97. end
  98. def test_span_iterator
  99. assert_equal(7, browser.spans.length)
  100. assert_equal("span1", browser.spans[1].id)
  101. index = 1
  102. browser.spans.each do |s|
  103. # puts "each - span = " + s.to_s
  104. assert_equal(browser.span(:index, index ).name , s.name )
  105. assert_equal(browser.span(:index, index ).id , s.id )
  106. assert_equal(browser.span(:index, index ).class_name , s.class_name )
  107. index += 1
  108. end
  109. assert_equal(index - 1, browser.spans.length) # -1 as we add 1 at the end of the loop
  110. end
  111. def test_objects_in_span
  112. assert(browser.span(:id, 'buttons1').button(:index,1).exists? )
  113. assert(!browser.span(:id, 'buttons1').button(:index,3).exists? )
  114. assert(browser.span(:id, 'buttons1').button(:name,'b1').exists? )
  115. assert(browser.span(:id, 'buttons2').button(:index,1).exists? )
  116. assert(browser.span(:id, 'buttons2').button(:index,2).exists? )
  117. assert(!browser.span(:id, 'buttons1').button(:index,3).exists? )
  118. browser.span(:id, 'buttons1').button(:index,1).click
  119. assert_equal( 'button1' , browser.span(:id , 'text_fields1').text_field(:index,1).value)
  120. browser.span(:id , 'text_fields1').text_field(:index,1).set('text box inside span')
  121. assert_equal( 'text box inside span' , browser.span(:id , 'text_fields1').text_field(:index,1).value)
  122. #assert_equal( 3 , browser.span(:id , 'text_fields1').text_fields.length )
  123. end
  124. def test_p
  125. assert(browser.p(:id, 'number1').exists?)
  126. assert(browser.p(:index, 3).exists?)
  127. assert(browser.p(:title, 'test_3').exists?)
  128. assert(!browser.p(:id, 'missing').exists?)
  129. assert(!browser.p(:index, 8).exists?)
  130. assert(!browser.p(:title, 'test_55').exists?)
  131. assert_raises( UnknownObjectException) {browser.p(:id , 'missing').class_name }
  132. assert_raises( UnknownObjectException) {browser.p(:id , 'missing').text }
  133. assert_raises( UnknownObjectException) {browser.p(:id , 'missing').title }
  134. assert_raises( UnknownObjectException) {browser.p(:id , 'missing').to_s }
  135. assert_raises( UnknownObjectException) {browser.p(:id , 'missing').disabled }
  136. assert_equal( 'redText' , browser.p(:index,1).class_name)
  137. assert_equal( 'P_tag_1' , browser.p(:index,1).title)
  138. assert_equal( 'This text is in a p with an id of number2' , browser.p(:index,2).text)
  139. end
  140. def test_p_iterator
  141. assert_equal( 3, browser.ps.length)
  142. assert_equal( 'italicText', browser.ps[2].class_name)
  143. assert_equal( 'number3', browser.ps[3].id)
  144. count=1
  145. browser.ps.each do |p|
  146. assert_equal('number'+count.to_s , p.id)
  147. count+=1
  148. end
  149. assert_equal( count-1 , browser.ps.length)
  150. end
  151. end
  152. class TC_Divs_Display < Test::Unit::TestCase
  153. include MockStdoutTestCase
  154. tag_method :test_showDivs, :fails_on_ie
  155. def test_showDivs
  156. goto_page("div.html")
  157. $stdout = @mockout
  158. browser.showDivs
  159. assert_equal(<<END_OF_MESSAGE, @mockout)
  160. There are 7 divs
  161. div: name:
  162. id: div1
  163. class:
  164. index: 1
  165. div: name:
  166. id: div2
  167. class: blueText
  168. index: 2
  169. div: name:
  170. id: div3
  171. class:
  172. index: 3
  173. div: name:
  174. id: div4
  175. class:
  176. index: 4
  177. div: name:
  178. id: buttons1
  179. class:
  180. index: 5
  181. div: name:
  182. id: buttons2
  183. class:
  184. index: 6
  185. div: name: divName
  186. id: text_fields1
  187. class: divClass
  188. index: 7
  189. END_OF_MESSAGE
  190. end
  191. end
  192. class TC_Spans_Display < Test::Unit::TestCase
  193. include MockStdoutTestCase
  194. tag_method :test_showSpans, :fails_on_ie
  195. def test_showSpans
  196. goto_page("div.html")
  197. $stdout = @mockout
  198. browser.showSpans
  199. assert_equal(<<END_OF_MESSAGE, @mockout)
  200. There are 7 spans
  201. span: name:
  202. id: span1
  203. class:
  204. index: 1
  205. span: name:
  206. id: span2
  207. class: blueText
  208. index: 2
  209. span: name:
  210. id: span3
  211. class:
  212. index: 3
  213. span: name:
  214. id: span4
  215. class:
  216. index: 4
  217. span: name:
  218. id: buttons1
  219. class:
  220. index: 5
  221. span: name:
  222. id: buttons2
  223. class:
  224. index: 6
  225. span: name: spanName
  226. id: text_fields1
  227. class: spanClass
  228. index: 7
  229. END_OF_MESSAGE
  230. end
  231. end