Test-Selenium-Remote-WebElement.t 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #!perl
  2. use Test::More;
  3. use Selenium::Remote::Mock::Commands;
  4. use Selenium::Remote::Mock::RemoteConnection;
  5. use Test::Selenium::Remote::Driver;
  6. use Test::Selenium::Remote::WebElement;
  7. # Start off by faking a bunch of Selenium::Remote::WebElement calls succeeding
  8. my $mock_commands = Selenium::Remote::Mock::Commands->new;
  9. my $spec = { };
  10. foreach my $k (
  11. qw/clearElement clickElement submitElement sendKeysToElement isElementSelected isElementEnabled isElementDisplayed/
  12. ) {
  13. $spec->{$k} = sub { return { status => 'OK', return => 1 }};
  14. }
  15. $spec->{getElementTagName} = sub { return { status => 'OK', return => 'iframe' }};
  16. $spec->{getElementValue} = sub { return { status => 'OK', return => 'my_value' }};
  17. $spec->{getElementText} = sub { return { status => 'OK', return => "my_text\nis fantastic" }};
  18. $spec->{getElementAttribute} = sub { my @args = @_; my $name = $args[0]->{name}; return { status => 'OK', return => "my_$name" }};
  19. my $driver =
  20. Test::Selenium::Remote::Driver->new(
  21. remote_conn => Selenium::Remote::Mock::RemoteConnection->new( spec => $spec, mock_cmds => $mock_commands ),
  22. commands => $mock_commands,
  23. );
  24. my $successful_element = Test::Selenium::Remote::WebElement->new(driver => $driver);
  25. $successful_element->clear_ok;
  26. $successful_element->click_ok;
  27. $successful_element->submit_ok;
  28. $successful_element->is_selected_ok;
  29. $successful_element->is_enabled_ok;
  30. $successful_element->is_displayed_ok;
  31. $successful_element->send_keys_ok('Hello World');
  32. $successful_element->tag_name_is( 'iframe', 'we got an iframe tag' );
  33. $successful_element->tag_name_isnt( 'BOOM', 'tag name is not boom' );
  34. $successful_element->tag_name_unlike( qr/BOOM/, "tag_name doesn't match BOOM" );
  35. $successful_element->value_is( 'my_value', 'Got an my_value value?' );
  36. $successful_element->value_isnt( 'BOOM', 'Not BOOM.' );
  37. $successful_element->value_like( qr/val/, 'Matches my_value value?' );
  38. $successful_element->value_unlike( qr/BOOM/, "value doesn't match BOOM" );
  39. $successful_element->text_is( "my_text\nis fantastic", 'Got an my_text value?' );
  40. $successful_element->text_isnt( 'BOOM', 'Not BOOM.' );
  41. $successful_element->text_like( qr/tex/, 'Matches my_text value?' );
  42. $successful_element->text_unlike( qr/BOOM/, "text doesn't match BOOM" );
  43. $successful_element->attribute_is( 'foo', 'my_foo', 'attribute_is matched' );
  44. $successful_element->attribute_isnt( 'foo', 'not_foo', 'attribute_is not_foo' );
  45. $successful_element->attribute_like( 'foo',qr/foo/, 'Matches my_attribute' );
  46. $successful_element->attribute_unlike( 'bar',qr/foo/, "Attribute does not match foo" );
  47. # css_attribute_is($attr_name,$match_str,$test_name);
  48. # css_attribute_isnt($attr_name,$match_str,$test_name);
  49. # css_attribute_like($attr_name,$match_re,$test_name);
  50. # css_attribute_unlike($attr_name,$match_re,$test_name);
  51. done_testing();