WebElement.pm 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. package Test::Selenium::Remote::WebElement;
  2. # ABSTRACT: A sub-class of L<Selenium::Remote::WebElement>, with several test-specific method additions.
  3. use Moo;
  4. use Sub::Install;
  5. extends 'Selenium::Remote::WebElement';
  6. =for Pod::Coverage *EVERYTHING*
  7. =cut
  8. # list of test functions to be built
  9. has func_list => (
  10. is => 'lazy',
  11. builder => sub {
  12. return [
  13. 'clear_ok', 'click_ok', 'send_keys_ok',
  14. 'is_displayed_ok', 'is_enabled_ok', 'is_selected_ok',
  15. 'submit_ok', 'text_is', 'text_isnt',
  16. 'text_like', 'text_unlike', 'attribute_is',
  17. 'attribute_isnt', 'attribute_like', 'attribute_unlike',
  18. 'value_is', 'value_isnt', 'value_like',
  19. 'value_unlike', 'tag_name_is', 'tag_name_isnt',
  20. 'tag_name_like', 'tag_name_unlike'
  21. ];
  22. }
  23. );
  24. with 'Test::Selenium::Remote::Role::DoesTesting';
  25. # helper so we could specify the num of args a method takes (if any)
  26. sub has_args {
  27. my $self = shift;
  28. my $fun_name = shift;
  29. my $hash_fun_args = {
  30. 'get_attribute' => 1,
  31. 'send_keys' => 1,
  32. };
  33. return ( $hash_fun_args->{$fun_name} // 0 );
  34. }
  35. # install the test methods into the class namespace
  36. sub BUILD {
  37. my $self = shift;
  38. foreach my $method_name ( @{ $self->func_list } ) {
  39. unless ( defined( __PACKAGE__->can($method_name) ) ) {
  40. my $sub = $self->_build_sub($method_name);
  41. Sub::Install::install_sub(
  42. {
  43. code => $sub,
  44. into => __PACKAGE__,
  45. as => $method_name
  46. }
  47. );
  48. }
  49. }
  50. }
  51. 1;
  52. __END__
  53. =head1 DESCRIPTION
  54. This is an I<experimental> addition to the Selenium::Remote::Driver
  55. distribution, and some interfaces may change.
  56. =head1 METHODS
  57. All methods from L<Selenium::Remote::WebElement> are available through this
  58. module, as well as the following test-specific methods. All test names are optional.
  59. text_is($match_str,$test_name);
  60. text_isnt($match_str,$test_name);
  61. text_like($match_re,$test_name);
  62. text_unlike($match_re,$test_name);
  63. tag_name_is($match_str,$test_name);
  64. tag_name_isnt($match_str,$test_name);
  65. tag_name_like($match_re,$test_name);
  66. tag_name_unlike($match_re,$test_name);
  67. value_is($match_str,$test_name);
  68. value_isnt($match_str,$test_name);
  69. value_like($match_re,$test_name);
  70. value_unlike($match_re,$test_name);
  71. clear_ok($test_name);
  72. click_ok($test_name);
  73. submit_ok($test_name);
  74. is_selected_ok($test_name);
  75. is_enabled_ok($test_name);
  76. is_displayed_ok($test_name);
  77. send_keys_ok($str)
  78. send_keys_ok($str,$test_name)
  79. attribute_is($attr_name,$match_str,$test_name);
  80. attribute_isnt($attr_name,$match_str,$test_name);
  81. attribute_like($attr_name,$match_re,$test_name);
  82. attribute_unlike($attr_name,$match_re,$test_name);
  83. css_attribute_is($attr_name,$match_str,$test_name); # TODO
  84. css_attribute_isnt($attr_name,$match_str,$test_name); # TODO
  85. css_attribute_like($attr_name,$match_re,$test_name); # TODO
  86. css_attribute_unlike($attr_name,$match_re,$test_name); # TODO
  87. element_location_is([x,y]) # TODO
  88. element_location_in_view_is([x,y]) # TODO
  89. =head1 AUTHORS
  90. =over 4
  91. =item *
  92. Created by: Mark Stosberg <mark@stosberg.org>, but inspired by
  93. L<Test::WWW::Selenium> and its authors.
  94. =back
  95. =head1 COPYRIGHT AND LICENSE
  96. Copyright (c) 2013 Mark Stosberg
  97. This program is free software; you can redistribute it and/or
  98. modify it under the same terms as Perl itself.