Test-Selenium-Remote-Driver.t 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738
  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. return { status => 'OK', return => { ELEMENT => '123456' } }
  12. if ( $searched_item->{value} eq 'q' );
  13. return { status => 'NOK', return => 0, error => 'element not found' };
  14. },
  15. getPageSource => sub { return 'this output matches regex'},
  16. findElements => sub {
  17. my (undef,$searched_expr) = @_;
  18. if ($searched_expr) {
  19. return { status => 'OK', return => [ { ELEMENT => '123456' }, { ELEMENT => '12341234' } ] }
  20. }
  21. },
  22. };
  23. my $mock_commands = Selenium::Remote::Mock::Commands->new;
  24. my $successful_driver =
  25. Test::Selenium::Remote::Driver->new(
  26. remote_conn => Selenium::Remote::Mock::RemoteConnection->new( spec => $spec, mock_cmds => $mock_commands ),
  27. commands => $mock_commands,
  28. );
  29. $successful_driver->find_element_ok('q','find_element_ok works');
  30. dies_ok { $successful_driver->find_element_ok('notq') } 'find_element_ok dies if element not found';
  31. $successful_driver->find_no_element_ok('notq','find_no_element_ok works');
  32. $successful_driver->content_like( qr/matches/, 'content_like works');
  33. $successful_driver->content_unlike( qr/nomatch/, 'content_unlike works');
  34. $successful_driver->find_elements_ok('abc','find_elements_ok works');
  35. done_testing();