Test-Selenium-Remote-WebElement.t 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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 = Test::Selenium::Remote::Driver->new(
  19. remote_conn => Selenium::Remote::Mock::RemoteConnection->new( spec => $spec, mock_cmds => $mock_commands ),
  20. commands => $mock_commands,
  21. );
  22. my $successful_element = Test::Selenium::Remote::WebElement->new(
  23. id => 'placeholder_id',
  24. driver => $driver
  25. );
  26. $successful_element->clear_ok;
  27. $successful_element->click_ok;
  28. $successful_element->submit_ok;
  29. $successful_element->is_selected_ok;
  30. $successful_element->is_enabled_ok;
  31. $successful_element->is_displayed_ok;
  32. $successful_element->send_keys_ok('Hello World');
  33. $successful_element->tag_name_is( 'iframe', 'we got an iframe tag' );
  34. $successful_element->tag_name_isnt( 'BOOM', 'tag name is not boom' );
  35. $successful_element->tag_name_unlike( qr/BOOM/, "tag_name doesn't match BOOM" );
  36. $successful_element->value_is( 'my_value', 'Got an my_value value?' );
  37. $successful_element->value_isnt( 'BOOM', 'Not BOOM.' );
  38. $successful_element->value_like( qr/val/, 'Matches my_value value?' );
  39. $successful_element->value_unlike( qr/BOOM/, "value doesn't match BOOM" );
  40. $successful_element->text_is( "my_text\nis fantastic", 'Got an my_text value?' );
  41. $successful_element->text_isnt( 'BOOM', 'Not BOOM.' );
  42. $successful_element->text_like( qr/tex/, 'Matches my_text value?' );
  43. $successful_element->text_unlike( qr/BOOM/, "text doesn't match BOOM" );
  44. $successful_element->attribute_is( 'foo', 'my_foo', 'attribute_is matched' );
  45. $successful_element->attribute_isnt( 'foo', 'not_foo', 'attribute_is not_foo' );
  46. $successful_element->attribute_like( 'foo',qr/foo/, 'Matches my_attribute' );
  47. $successful_element->attribute_unlike( 'bar',qr/foo/, "Attribute does not match foo" );
  48. # css_attribute_is($attr_name,$match_str,$test_name);
  49. # css_attribute_isnt($attr_name,$match_str,$test_name);
  50. # css_attribute_like($attr_name,$match_re,$test_name);
  51. # css_attribute_unlike($attr_name,$match_re,$test_name);
  52. done_testing();