Test-Selenium-Remote-WebElement.t 5.3 KB

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