1
0

Test-Selenium-Remote-WebElement.t 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. #!perl
  2. use lib 't/lib';
  3. use Test::More;
  4. use MockCommands;
  5. use MockRemoteConnection;
  6. use Test::Selenium::Remote::Driver;
  7. use Test::Selenium::Remote::WebElement;
  8. # Start off by faking a bunch of Selenium::Remote::WebElement calls succeeding
  9. my $mock_commands = MockCommands->new;
  10. my $spec = { };
  11. foreach my $k (
  12. qw/clearElement clickElement submitElement sendKeysToElement isElementSelected isElementEnabled isElementDisplayed/
  13. ) {
  14. $spec->{$k} = sub { return { status => 'OK', return => 1 }};
  15. }
  16. $spec->{getElementTagName} = sub { return { status => 'OK', return => 'iframe' }};
  17. $spec->{getElementValue} = sub { return { status => 'OK', return => 'my_value' }};
  18. $spec->{getElementText} = sub { return { status => 'OK', return => "my_text\nis fantastic" }};
  19. $spec->{getElementAttribute} = sub { my @args = @_; my $name = $args[0]->{name}; return { status => 'OK', return => "my_$name" }};
  20. my $driver =
  21. Test::Selenium::Remote::Driver->new(
  22. remote_conn => MockRemoteConnection->new( spec => $spec, mock_cmds => $mock_commands ),
  23. commands => $mock_commands,
  24. );
  25. my $successful_element = Test::Selenium::Remote::WebElement->new(driver => $driver);
  26. $successful_element->clear_ok;
  27. $successful_element->click_ok;
  28. $successful_element->submit_ok;
  29. $successful_element->is_selected_ok;
  30. $successful_element->is_enabled_ok;
  31. $successful_element->is_displayed_ok;
  32. $successful_element->send_keys_ok('Hello World');
  33. $successful_element->tag_name_is( 'iframe', 'we got an iframe tag' );
  34. $successful_element->tag_name_isnt( 'BOOM', 'tag name is not boom' );
  35. $successful_element->tag_name_unlike( qr/BOOM/, "tag_name doesn't match BOOM" );
  36. $successful_element->value_is( 'my_value', 'Got an my_value value?' );
  37. # check_test(
  38. # sub {
  39. # $successful_element->tag_name_unlike( qr/BOOM/,
  40. # "tag_name doesn't match BOOM" );
  41. # },
  42. # { ok => 1,
  43. # name => "tag_name doesn't match BOOM",
  44. # diag => "",
  45. # }
  46. # );
  47. # }
  48. # # value_*
  49. # {
  50. # check_test(
  51. # sub {
  52. # $successful_element->value_is( 'my_value',
  53. # 'Got an my_value value?' );
  54. # },
  55. # { ok => 1,
  56. # name => "Got an my_value value?",
  57. # diag => "",
  58. # }
  59. # );
  60. # check_test(
  61. # sub { $successful_element->value_isnt( 'BOOM', 'Not BOOM.' ) },
  62. # { ok => 1,
  63. # name => "Not BOOM.",
  64. # diag => "",
  65. # }
  66. # );
  67. # check_test(
  68. # sub {
  69. # $successful_element->value_like( qr/val/,
  70. # 'Matches my_value value?' );
  71. # },
  72. # { ok => 1,
  73. # name => "Matches my_value value?",
  74. # diag => "",
  75. # }
  76. # );
  77. # check_test(
  78. # sub {
  79. # $successful_element->value_unlike( qr/BOOM/,
  80. # "value doesn't match BOOM" );
  81. # },
  82. # { ok => 1,
  83. # name => "value doesn't match BOOM",
  84. # diag => "",
  85. # }
  86. # );
  87. # }
  88. # # text_*
  89. # {
  90. # check_test(
  91. # sub {
  92. # $successful_element->text_is( "my_text\nis fantastic",
  93. # 'Got an my_text value?' );
  94. # },
  95. # { ok => 1,
  96. # name => "Got an my_text value?",
  97. # diag => "",
  98. # }
  99. # );
  100. # check_test(
  101. # sub { $successful_element->text_isnt( 'BOOM', 'Not BOOM.' ) },
  102. # { ok => 1,
  103. # name => "Not BOOM.",
  104. # diag => "",
  105. # }
  106. # );
  107. # check_test(
  108. # sub {
  109. # $successful_element->text_like( qr/tex/,
  110. # 'Matches my_text value?' );
  111. # },
  112. # { ok => 1,
  113. # name => "Matches my_text value?",
  114. # diag => "",
  115. # }
  116. # );
  117. # check_test(
  118. # sub {
  119. # $successful_element->text_unlike( qr/BOOM/,
  120. # "text doesn't match BOOM" );
  121. # },
  122. # { ok => 1,
  123. # name => "text doesn't match BOOM",
  124. # diag => "",
  125. # }
  126. # );
  127. # }
  128. # {
  129. # check_test(
  130. # sub {
  131. # $successful_element->attribute_is( 'foo', 'my_foo',
  132. # 'attribute_is matched' );
  133. # },
  134. # { ok => 1,
  135. # name => "attribute_is matched",
  136. # diag => "",
  137. # }
  138. # );
  139. # check_test(
  140. # sub {
  141. # $successful_element->attribute_isnt( 'foo', 'not_foo',
  142. # 'attribute_is not_foo' );
  143. # },
  144. # { ok => 1,
  145. # name => "attribute_is not_foo",
  146. # diag => "",
  147. # }
  148. # );
  149. # check_test(
  150. # sub {
  151. # $successful_element->attribute_like( 'foo',qr/foo/,
  152. # 'Matches my_attribute' );
  153. # },
  154. # { ok => 1,
  155. # name => "Matches my_attribute",
  156. # diag => "",
  157. # }
  158. # );
  159. # check_test(
  160. # sub {
  161. # $successful_element->attribute_unlike( 'bar',qr/foo/,
  162. # "Attribute does not match foo" );
  163. # },
  164. # { ok => 1,
  165. # name => "Attribute does not match foo",
  166. # diag => "",
  167. # }
  168. # );
  169. # }
  170. # css_attribute_is($attr_name,$match_str,$test_name);
  171. # css_attribute_isnt($attr_name,$match_str,$test_name);
  172. # css_attribute_like($attr_name,$match_re,$test_name);
  173. # css_attribute_unlike($attr_name,$match_re,$test_name);
  174. done_testing();