Test-Selenium-Remote-Driver.t 1.2 KB

123456789101112131415161718192021222324252627282930313233
  1. #!/usr/bin/env perl
  2. use lib 't/lib';
  3. use Test::More;
  4. use Test::Exception;
  5. use Test::Selenium::Remote::Driver;
  6. use Selenium::Remote::WebElement;
  7. use MockCommands;
  8. use MockRemoteConnection;
  9. my $spec = {
  10. findElement => sub {
  11. my (undef,$searched_item) = @_;
  12. $DB::single = 1;
  13. return { status => 'OK', return => { ELEMENT => '123456' } }
  14. if ( $searched_item->{value} eq 'q' );
  15. return { status => 'NOK', return => 0, error => 'element not found' };
  16. },
  17. getPageSource => sub { return 'this output matches regex'},
  18. };
  19. my $mock_commands = MockCommands->new;
  20. my $successful_driver =
  21. Test::Selenium::Remote::Driver->new(
  22. remote_conn => MockRemoteConnection->new( spec => $spec, mock_cmds => $mock_commands ),
  23. commands => $mock_commands,
  24. );
  25. $successful_driver->find_element_ok('q','find_element_ok works');
  26. dies_ok { $successful_driver->find_element_ok('notq') } 'find_element_ok dies if element not found';
  27. $successful_driver->find_no_element_ok('notq','find_no_element_ok works');
  28. $successful_driver->content_like( qr/matches/, 'content_like works');
  29. $successful_driver->content_unlike( qr/nomatch/, 'content_unlike works');
  30. done_testing();