Test-Selenium-Remote-WebElement.t 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. use Test::Tester;
  2. use Test::More;
  3. use Test::MockObject::Extends;
  4. use Test::Selenium::Remote::WebElement;
  5. # Start off by faking a bunch of Selenium::Remote::WebElement calls succeeding
  6. my $successful_element = Test::Selenium::Remote::WebElement->new;
  7. $successful_element = Test::MockObject::Extends->new($successful_element);
  8. $successful_element->set_true(
  9. qw/
  10. clear
  11. click
  12. submit
  13. is_selected
  14. is_enabled
  15. is_displayed
  16. send_keys
  17. /
  18. );
  19. $successful_element->mock( 'get_tag_name', sub {'iframe'} );
  20. $successful_element->mock( 'get_value', sub {'my_value'} );
  21. $successful_element->mock( 'get_text', sub {"my_text\nis fantastic"} );
  22. # Given input 'foo' to 'get_attribute', return 'my_foo';
  23. $successful_element->mock( 'get_attribute', sub { 'my_' . $_[1] } );
  24. check_test(
  25. sub { $successful_element->clear_ok },
  26. {
  27. ok => 1,
  28. name => "clear",
  29. diag => "",
  30. }
  31. );
  32. check_test(
  33. sub { $successful_element->clear_ok('test_name') },
  34. {
  35. ok => 1,
  36. name => "test_name",
  37. diag => "",
  38. }
  39. );
  40. check_test(
  41. sub { $successful_element->click_ok },
  42. {
  43. ok => 1,
  44. name => "click",
  45. diag => "",
  46. }
  47. );
  48. check_test(
  49. sub { $successful_element->submit_ok },
  50. {
  51. ok => 1,
  52. name => "submit",
  53. diag => "",
  54. }
  55. );
  56. check_test(
  57. sub { $successful_element->is_selected_ok },
  58. {
  59. ok => 1,
  60. name => "is_selected",
  61. diag => "",
  62. }
  63. );
  64. check_test(
  65. sub { $successful_element->is_enabled_ok },
  66. {
  67. ok => 1,
  68. name => "is_enabled",
  69. diag => "",
  70. }
  71. );
  72. check_test(
  73. sub { $successful_element->is_displayed_ok },
  74. {
  75. ok => 1,
  76. name => "is_displayed",
  77. diag => "",
  78. }
  79. );
  80. check_test(
  81. sub { $successful_element->send_keys_ok('Hello World', 'I sent keys') },
  82. {
  83. ok => 1,
  84. name => "I sent keys",
  85. diag => "",
  86. }
  87. );
  88. # tag_name_*
  89. {
  90. check_test(
  91. sub {
  92. $successful_element->tag_name_is( 'iframe', 'Got an iframe tag?' );
  93. },
  94. { ok => 1,
  95. name => "Got an iframe tag?",
  96. diag => "",
  97. }
  98. );
  99. check_test(
  100. sub { $successful_element->tag_name_isnt( 'BOOM', 'Not BOOM.' ) },
  101. { ok => 1,
  102. name => "Not BOOM.",
  103. diag => "",
  104. }
  105. );
  106. check_test(
  107. sub {
  108. $successful_element->tag_name_like( qr/frame/,
  109. 'Matches iframe tag?' );
  110. },
  111. { ok => 1,
  112. name => "Matches iframe tag?",
  113. diag => "",
  114. }
  115. );
  116. check_test(
  117. sub {
  118. $successful_element->tag_name_unlike( qr/BOOM/,
  119. "tag_name doesn't match BOOM" );
  120. },
  121. { ok => 1,
  122. name => "tag_name doesn't match BOOM",
  123. diag => "",
  124. }
  125. );
  126. }
  127. # value_*
  128. {
  129. check_test(
  130. sub {
  131. $successful_element->value_is( 'my_value',
  132. 'Got an my_value value?' );
  133. },
  134. { ok => 1,
  135. name => "Got an my_value value?",
  136. diag => "",
  137. }
  138. );
  139. check_test(
  140. sub { $successful_element->value_isnt( 'BOOM', 'Not BOOM.' ) },
  141. { ok => 1,
  142. name => "Not BOOM.",
  143. diag => "",
  144. }
  145. );
  146. check_test(
  147. sub {
  148. $successful_element->value_like( qr/val/,
  149. 'Matches my_value value?' );
  150. },
  151. { ok => 1,
  152. name => "Matches my_value value?",
  153. diag => "",
  154. }
  155. );
  156. check_test(
  157. sub {
  158. $successful_element->value_unlike( qr/BOOM/,
  159. "value doesn't match BOOM" );
  160. },
  161. { ok => 1,
  162. name => "value doesn't match BOOM",
  163. diag => "",
  164. }
  165. );
  166. }
  167. # text_*
  168. {
  169. check_test(
  170. sub {
  171. $successful_element->text_is( "my_text\nis fantastic",
  172. 'Got an my_text value?' );
  173. },
  174. { ok => 1,
  175. name => "Got an my_text value?",
  176. diag => "",
  177. }
  178. );
  179. check_test(
  180. sub { $successful_element->text_isnt( 'BOOM', 'Not BOOM.' ) },
  181. { ok => 1,
  182. name => "Not BOOM.",
  183. diag => "",
  184. }
  185. );
  186. check_test(
  187. sub {
  188. $successful_element->text_like( qr/tex/,
  189. 'Matches my_text value?' );
  190. },
  191. { ok => 1,
  192. name => "Matches my_text value?",
  193. diag => "",
  194. }
  195. );
  196. check_test(
  197. sub {
  198. $successful_element->text_unlike( qr/BOOM/,
  199. "text doesn't match BOOM" );
  200. },
  201. { ok => 1,
  202. name => "text doesn't match BOOM",
  203. diag => "",
  204. }
  205. );
  206. }
  207. {
  208. check_test(
  209. sub {
  210. $successful_element->attribute_is( 'foo', 'my_foo',
  211. 'attribute_is matched' );
  212. },
  213. { ok => 1,
  214. name => "attribute_is matched",
  215. diag => "",
  216. }
  217. );
  218. check_test(
  219. sub {
  220. $successful_element->attribute_isnt( 'foo', 'not_foo',
  221. 'attribute_is not_foo' );
  222. },
  223. { ok => 1,
  224. name => "attribute_is not_foo",
  225. diag => "",
  226. }
  227. );
  228. check_test(
  229. sub {
  230. $successful_element->attribute_like( 'foo',qr/foo/,
  231. 'Matches my_attribute' );
  232. },
  233. { ok => 1,
  234. name => "Matches my_attribute",
  235. diag => "",
  236. }
  237. );
  238. check_test(
  239. sub {
  240. $successful_element->attribute_unlike( 'bar',qr/foo/,
  241. "Attribute does not match foo" );
  242. },
  243. { ok => 1,
  244. name => "Attribute does not match foo",
  245. diag => "",
  246. }
  247. );
  248. }
  249. # css_attribute_is($attr_name,$match_str,$test_name);
  250. # css_attribute_isnt($attr_name,$match_str,$test_name);
  251. # css_attribute_like($attr_name,$match_re,$test_name);
  252. # css_attribute_unlike($attr_name,$match_re,$test_name);
  253. done_testing();