1
0

Test-Selenium-Remote-Driver.t 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #!/usr/bin/env perl
  2. use Test::More;
  3. use Test::Exception;
  4. use Test::Selenium::Remote::Driver;
  5. use Selenium::Remote::WebElement;
  6. use Selenium::Remote::Mock::Commands;
  7. use Selenium::Remote::Mock::RemoteConnection;
  8. my $spec = {
  9. findElement => sub {
  10. my ( undef, $searched_item ) = @_;
  11. if ( $searched_item->{value} eq 'q' ) {
  12. return { status => 'OK', return => { ELEMENT => '123456' } };
  13. }
  14. if ( $searched_item->{value} eq 'p'
  15. && $searched_item->{using} eq 'class name' )
  16. {
  17. return { status => 'OK', return => { ELEMENT => '123456' } };
  18. }
  19. return { status => 'NOK', return => 0, error => 'element not found' };
  20. },
  21. getPageSource => sub { return 'this output matches regex'},
  22. findElements => sub {
  23. my (undef,$searched_expr) = @_;
  24. if ($searched_expr->{value} eq 'abc' && $searched_expr->{using} eq 'xpath') {
  25. return { status => 'OK', return => [ { ELEMENT => '123456' }, { ELEMENT => '12341234' } ] }
  26. }
  27. },
  28. };
  29. my $mock_commands = Selenium::Remote::Mock::Commands->new;
  30. my $successful_driver =
  31. Test::Selenium::Remote::Driver->new(
  32. remote_conn => Selenium::Remote::Mock::RemoteConnection->new( spec => $spec, mock_cmds => $mock_commands ),
  33. commands => $mock_commands,
  34. );
  35. $successful_driver->find_element_ok('q','find_element_ok works');
  36. $successful_driver->find_element_ok('p','class','find_element_ok with a locator works');
  37. dies_ok { $successful_driver->find_element_ok('notq') } 'find_element_ok dies if element not found';
  38. $successful_driver->find_no_element_ok('notq','find_no_element_ok works');
  39. $successful_driver->content_like( qr/matches/, 'content_like works');
  40. $successful_driver->content_unlike( qr/nomatch/, 'content_unlike works');
  41. $successful_driver->find_elements_ok('abc','find_elements_ok works');
  42. done_testing();