Test-Selenium-Remote-WebElement.t 2.8 KB

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