Test-Selenium-Remote-Driver.t 1.1 KB

1234567891011121314151617181920212223242526272829303132
  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. return { status => 'OK', return => { ELEMENT => '123456' } }
  13. if ( $searched_item->{value} eq 'q' );
  14. return { status => 'NOK', return => 0, error => 'element not found' };
  15. },
  16. getPageSource => sub { return 'this output matches regex'},
  17. };
  18. my $mock_commands = MockCommands->new;
  19. my $successful_driver =
  20. Test::Selenium::Remote::Driver->new(
  21. remote_conn => MockRemoteConnection->new( spec => $spec, mock_cmds => $mock_commands ),
  22. commands => $mock_commands,
  23. );
  24. $successful_driver->find_element_ok('q','find_element_ok works');
  25. dies_ok { $successful_driver->find_element_ok('notq') } 'find_element_ok dies if element not found';
  26. $successful_driver->find_no_element_ok('notq','find_no_element_ok works');
  27. $successful_driver->content_like( qr/matches/, 'content_like works');
  28. $successful_driver->content_unlike( qr/nomatch/, 'content_unlike works');
  29. done_testing();