WebElement.pm 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. package Test::Selenium::Remote::WebElement;
  2. use parent 'Selenium::Remote::WebElement';
  3. use Moo;
  4. use Test::Builder;
  5. has _builder => (
  6. is => 'lazy',
  7. builder => sub { return Test::Builder->new() },
  8. handles => [qw/is_eq isnt_eq like unlike/],
  9. );
  10. sub _check_main_method {
  11. my $self = shift;
  12. my $method = shift;
  13. my $method_to_test = shift;
  14. $method = "get_$method";
  15. my $rv = $self->$method();
  16. # +2 because of the delegation on _builder
  17. local $Test::Builder::Level = $Test::Builder::Level + 2;
  18. return $self->$method_to_test( $rv, @_ );
  19. }
  20. sub text_is {
  21. my $self = shift;
  22. return $self->_check_main_method( 'text', 'is_eq', @_ );
  23. }
  24. sub text_isnt {
  25. my $self = shift;
  26. return $self->_check_main_method( 'text', 'isnt_eq', @_ );
  27. }
  28. sub text_like {
  29. my $self = shift;
  30. return $self->_check_main_method( 'text', 'like', @_ );
  31. }
  32. sub text_unlike {
  33. my $self = shift;
  34. return $self->_check_main_method( 'text', 'unlike', @_ );
  35. }
  36. sub tag_name_is {
  37. my $self = shift;
  38. return $self->_check_main_method( 'tag_name', 'is_eq', @_ );
  39. }
  40. sub tag_name_isnt {
  41. my $self = shift;
  42. return $self->_check_main_method( 'tag_name', 'isnt_eq', @_ );
  43. }
  44. sub tag_name_like {
  45. my $self = shift;
  46. return $self->_check_main_method( 'tag_name', 'like', @_ );
  47. }
  48. sub tag_name_unlike {
  49. my $self = shift;
  50. return $self->_check_main_method( 'tag_name', 'unlike', @_ );
  51. }
  52. sub value_is {
  53. my $self = shift;
  54. return $self->_check_main_method( 'value', 'is_eq', @_ );
  55. }
  56. sub value_isnt {
  57. my $self = shift;
  58. return $self->_check_main_method( 'value', 'isnt_eq', @_ );
  59. }
  60. sub value_like {
  61. my $self = shift;
  62. return $self->_check_main_method( 'value', 'like', @_ );
  63. }
  64. sub value_unlike {
  65. my $self = shift;
  66. return $self->_check_main_method( 'value', 'unlike', @_ );
  67. }
  68. 1;
  69. __END__
  70. =head1 NAME
  71. Test::Selenium::Remote::WebElement
  72. =head1 DESCRIPTION
  73. A sub-class of L<Selenium::Remote::WebElement>, with several test-specific method additions.
  74. This is an I<experimental> addition to the Selenium::Remote::Driver
  75. distribution, and some interfaces may change.
  76. =head1 METHODS
  77. All methods from L<Selenium::Remote::WebElement> are available through this
  78. module, as well as the following test-specific methods. All test names are optional.
  79. text_is($match_str,$test_name);
  80. text_isnt($match_str,$test_name);
  81. text_like($match_re,$test_name);
  82. text_unlike($match_re,$test_name);
  83. tag_name_is($match_str,$test_name);
  84. tag_name_isnt($match_str,$test_name);
  85. tag_name_like($match_re,$test_name);
  86. tag_name_unlike($match_re,$test_name);
  87. value_is($match_str,$test_name);
  88. value_isnt($match_str,$test_name);
  89. value_like($match_re,$test_name);
  90. value_unlike($match_re,$test_name);
  91. clear_ok($test_name);
  92. click_ok($test_name);
  93. submit_ok($test_name);
  94. is_selected_ok($test_name);
  95. is_enabled_ok($test_name);
  96. is_displayed_ok($test_name);
  97. send_keys_ok($str)
  98. send_keys_ok($str,$test_name)
  99. attribute_is($attr_name,$match_str,$test_name); # TODO
  100. attribute_isnt($attr_name,$match_str,$test_name); # TODO
  101. attribute_like($attr_name,$match_re,$test_name); # TODO
  102. attribute_unlike($attr_name,$match_re,$test_name); # TODO
  103. css_attribute_is($attr_name,$match_str,$test_name); # TODO
  104. css_attribute_isnt($attr_name,$match_str,$test_name); # TODO
  105. css_attribute_like($attr_name,$match_re,$test_name); # TODO
  106. css_attribute_unlike($attr_name,$match_re,$test_name); # TODO
  107. element_location_is([x,y]) # TODO
  108. element_location_in_view_is([x,y]) # TODO
  109. =head1 AUTHORS
  110. =over 4
  111. =item *
  112. Created by: Mark Stosberg <mark@stosberg.org>, but inspired by
  113. L<Test::WWW::Selenium> and its authors.
  114. =back
  115. =head1 COPYRIGHT AND LICENSE
  116. Copyright (c) 2013 Mark Stosberg
  117. This program is free software; you can redistribute it and/or
  118. modify it under the same terms as Perl itself.