| 1 | package Test::Selenium::Remote::Driver; | ||||||||||||||||||||||||||||
| 2 | 13 | $Test::Selenium::Remote::Driver::VERSION = '1.50'; | |||||||||||||||||||||||||||
| 3 | # ABSTRACT: Useful testing subclass for Selenium::Remote::Driver | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 13 | ▶ | use Moo; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 13 | ▶ | use Test::Selenium::Remote::WebElement; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 13 | ▶ | use Test::LongString; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 13 | ▶ | use IO::Socket; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 13 | ▶ | use Sub::Install; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 13 | ▶ | use Try::Tiny; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 13 | extends 'Selenium::Remote::Driver'; | |||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | # move_mouse_to_location_ok # TODO # move_to_ok # TODO | ||||||||||||||||||||||||||||
| 15 | has func_list => ( | ||||||||||||||||||||||||||||
| 16 | is => 'lazy', | ||||||||||||||||||||||||||||
| 17 | 2 | ▶ | builder => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
_build_func_list: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | return [ | ||||||||||||||||||||||||||||
| 19 | 2 | 'alert_text_is', 'alert_text_isnt', | |||||||||||||||||||||||||||
| 20 | 'alert_text_like', 'alert_text_unlike', | ||||||||||||||||||||||||||||
| 21 | 'current_window_handle_is', 'current_window_handle_isnt', | ||||||||||||||||||||||||||||
| 22 | 'current_window_handle_like', 'current_window_handle_unlike', | ||||||||||||||||||||||||||||
| 23 | 'window_handles_is', 'window_handles_isnt', | ||||||||||||||||||||||||||||
| 24 | 'window_handles_like', 'window_handles_unlike', | ||||||||||||||||||||||||||||
| 25 | 'window_size_is', 'window_size_isnt', | ||||||||||||||||||||||||||||
| 26 | 'window_size_like', 'window_size_unlike', | ||||||||||||||||||||||||||||
| 27 | 'window_position_is', 'window_position_isnt', | ||||||||||||||||||||||||||||
| 28 | 'window_position_like', 'window_position_unlike', | ||||||||||||||||||||||||||||
| 29 | 'current_url_is', 'current_url_isnt', | ||||||||||||||||||||||||||||
| 30 | 'current_url_like', 'current_url_unlike', | ||||||||||||||||||||||||||||
| 31 | 'title_is', 'title_isnt', | ||||||||||||||||||||||||||||
| 32 | 'title_like', 'title_unlike', | ||||||||||||||||||||||||||||
| 33 | 'active_element_is', 'active_element_isnt', | ||||||||||||||||||||||||||||
| 34 | 'active_element_like', 'active_element_unlike', | ||||||||||||||||||||||||||||
| 35 | 'send_keys_to_active_element_ok', 'send_keys_to_alert_ok', | ||||||||||||||||||||||||||||
| 36 | 'send_keys_to_prompt_ok', 'send_modifier_ok', | ||||||||||||||||||||||||||||
| 37 | 'accept_alert_ok', 'dismiss_alert_ok', | ||||||||||||||||||||||||||||
| 38 | 'get_ok', 'go_back_ok', | ||||||||||||||||||||||||||||
| 39 | 'go_forward_ok', 'add_cookie_ok', | ||||||||||||||||||||||||||||
| 40 | 'get_page_source_ok', 'find_element_ok', | ||||||||||||||||||||||||||||
| 41 | 'find_elements_ok', 'find_child_element_ok', | ||||||||||||||||||||||||||||
| 42 | 'find_child_elements_ok', 'find_no_element_ok', | ||||||||||||||||||||||||||||
| 43 | 'compare_elements_ok', 'click_ok', | ||||||||||||||||||||||||||||
| 44 | 'double_click_ok', 'body_like', | ||||||||||||||||||||||||||||
| 45 | ]; | ||||||||||||||||||||||||||||
| 46 | }, | ||||||||||||||||||||||||||||
| 47 | 13 | ); | |||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | =for Pod::Coverage has_args | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | =cut | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 27 | ▶ | sub has_args { | ||||||||||||||||||||||||||
|
Subroutine
has_args: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 54 | 27 | my $self = shift; | |||||||||||||||||||||||||||
| 55 | 27 | my $fun_name = shift; | |||||||||||||||||||||||||||
| 56 | 27 | my $hash_fun_args = { | |||||||||||||||||||||||||||
| 57 | 'find_element' => 2, | ||||||||||||||||||||||||||||
| 58 | 'find_no_element' => 2, | ||||||||||||||||||||||||||||
| 59 | 'find_child_element' => 3, | ||||||||||||||||||||||||||||
| 60 | 'find_child_elements' => 3, | ||||||||||||||||||||||||||||
| 61 | 'find_element' => 2, | ||||||||||||||||||||||||||||
| 62 | 'find_elements' => 2, | ||||||||||||||||||||||||||||
| 63 | 'compare_elements' => 2, | ||||||||||||||||||||||||||||
| 64 | 'get' => 1, | ||||||||||||||||||||||||||||
| 65 | }; | ||||||||||||||||||||||||||||
| 66 | 27 | ▶ | return ( $hash_fun_args->{$fun_name} // 0 ); | ||||||||||||||||||||||||||
|
Condition100%2/2
$hash_fun_args->{$fun_name} // 0
MC/DC100%1/1
$hash_fun_args->{$fun_name} // 0
$hash_fun_args->{$fun_name}
Truth table100%2/2
A
A= $hash_fun_args->{$fun_name}
| |||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 13 | with 'Test::Selenium::Remote::Role::DoesTesting'; | |||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | =for Pod::Coverage BUILD | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | =cut | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 9 | ▶ | sub BUILD { | ||||||||||||||||||||||||||
|
Subroutine
BUILD: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 76 | 9 | my $self = shift; | |||||||||||||||||||||||||||
| 77 | 9 | foreach my $method_name ( @{ $self->func_list } ) { | |||||||||||||||||||||||||||
| 78 | 468 | ▶ | unless ( defined( __PACKAGE__->can($method_name) ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 79 | 312 | my $sub = $self->_build_sub($method_name); | |||||||||||||||||||||||||||
| 80 | 312 | Sub::Install::install_sub( | |||||||||||||||||||||||||||
| 81 | { | ||||||||||||||||||||||||||||
| 82 | code => $sub, | ||||||||||||||||||||||||||||
| 83 | into => __PACKAGE__, | ||||||||||||||||||||||||||||
| 84 | as => $method_name | ||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||
| 86 | ); | ||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | =head1 NAME | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | Test::Selenium::Remote::Driver - add testing methods to L<Selenium::Remote::Driver> | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | A subclass of L<Selenium::Remote::Driver> which provides useful testing | ||||||||||||||||||||||||||||
| 98 | methods. | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | This is an I<experimental> addition to the Selenium::Remote::Driver | ||||||||||||||||||||||||||||
| 101 | distribution. Some interfaces may change. | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | =head1 Methods | ||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | =head2 new ( %opts ) | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | This will create a new Test::Selenium::Remote::Driver object, which subclasses | ||||||||||||||||||||||||||||
| 108 | L<Selenium::Remote::Driver>. This subclass provides useful testing | ||||||||||||||||||||||||||||
| 109 | functions. It is modeled on L<Test::WWW::Selenium>. | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | Environment vars can be used to specify options to pass to | ||||||||||||||||||||||||||||
| 112 | L<Selenium::Remote::Driver>. ENV vars are prefixed with C<TWD_>. | ||||||||||||||||||||||||||||
| 113 | ( After the old fork name, "Test::WebDriver" ). The explicitly passed | ||||||||||||||||||||||||||||
| 114 | options have precedence. ENV vars take only effect when they are | ||||||||||||||||||||||||||||
| 115 | actually set. This important e.g. for the option C<javascript>, which | ||||||||||||||||||||||||||||
| 116 | is turned on per default in L<Selenium::Remote::Driver>. | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | Set the Selenium server address with C<$TWD_HOST> and C<$TWD_PORT>. | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | Pick which browser is used using the C<$TWD_BROWSER>, C<$TWD_VERSION>, | ||||||||||||||||||||||||||||
| 121 | C<$TWD_PLATFORM>, C<$TWD_JAVASCRIPT>, C<$TWD_EXTRA_CAPABILITIES>. | ||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | C<$TWD_BROWSER> is actually an alias for C<$TWD_BROWSER_NAME>. | ||||||||||||||||||||||||||||
| 124 | C<$TWD_HOST> is actually an alias for C<$TWD_REMOTE_SERVER_ADDR>. | ||||||||||||||||||||||||||||
| 125 | The aliases habe lower precedence than the original values. | ||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | See L<Selenium::Remote::Driver> for the meanings of these options. | ||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | =for Pod::Coverage BUILDARGS | ||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | =cut | ||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | 7 | ▶ | sub BUILDARGS { | ||||||||||||||||||||||||||
|
Subroutine
BUILDARGS: called CC=9 SCAR=30.7
Pod
undocumented
| |||||||||||||||||||||||||||||
| 134 | 7 | my ( undef, %p ) = @_; | |||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | OPT: | ||||||||||||||||||||||||||||
| 137 | 7 | for my $opt ( | |||||||||||||||||||||||||||
| 138 | qw/remote_server_addr port browser_name version platform | ||||||||||||||||||||||||||||
| 139 | javascript auto_close extra_capabilities/ | ||||||||||||||||||||||||||||
| 140 | ) | ||||||||||||||||||||||||||||
| 141 | { | ||||||||||||||||||||||||||||
| 142 | 56 | my $env_var_name = 'TWD_' . uc($opt); | |||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | 56 | ▶ | next OPT unless exists $ENV{$env_var_name}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | 0 | ▶ | $p{$opt} //= $ENV{$env_var_name}; | ||||||||||||||||||||||||||
|
Condition0%0/3
$p{$opt} //= $ENV{$env_var_name}
MC/DC0%0/2
$p{$opt} //= $ENV{$env_var_name}
$p{$opt}
$ENV{$env_var_name}
Truth table0%0/3
A //= B
A= $p{$opt}B= $ENV{$env_var_name}
| |||||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||
| 148 | 7 | ▶ | $p{browser_name} //= $ENV{TWD_BROWSER} if exists $ENV{TWD_BROWSER}; # ykwim | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$p{"browser_name"} //= $ENV{"TWD_BROWSER"}
MC/DC0%0/2
$p{"browser_name"} //= $ENV{"TWD_BROWSER"}
$p{"browser_name"}
$ENV{"TWD_BROWSER"}
Truth table0%0/3
A //= B
A= $p{"browser_name"}B= $ENV{"TWD_BROWSER"}
| |||||||||||||||||||||||||||||
| 149 | 7 | ▶ | $p{remote_server_addr} //= $ENV{TWD_HOST} if exists $ENV{TWD_HOST}; # ykwim | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$p{"remote_server_addr"} //= $ENV{"TWD_HOST"}
MC/DC0%0/2
$p{"remote_server_addr"} //= $ENV{"TWD_HOST"}
$p{"remote_server_addr"}
$ENV{"TWD_HOST"}
Truth table0%0/3
A //= B
A= $p{"remote_server_addr"}B= $ENV{"TWD_HOST"}
| |||||||||||||||||||||||||||||
| 150 | 7 | ▶ | $p{webelement_class} //= 'Test::Selenium::Remote::WebElement'; | ||||||||||||||||||||||||||
|
Condition50%1/2
$p{"webelement_class"} //= "Test::Selenium::Remote::WebElement"
MC/DC0%0/1
$p{"webelement_class"} //= "Test::Selenium::Remote::WebElement"
$p{"webelement_class"}
Truth table50%1/2
A
A= $p{"webelement_class"}
| |||||||||||||||||||||||||||||
| 151 | 7 | return \%p; | |||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | =head2 verbose | ||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||
| 156 | Enable/disable debugging output, or view the status of verbosity. | ||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | =cut | ||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | 13 | has verbose => ( is => 'rw', ); | |||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||
| 162 | =head2 server_is_running( $host, $port ) | ||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||
| 164 | Returns true if a Selenium server is running. The host and port | ||||||||||||||||||||||||||||
| 165 | parameters are optional, and they default to C<localhost:4444>. | ||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||
| 167 | The environment vars C<TWD_HOST> and C<TWD_PORT> can also be used to | ||||||||||||||||||||||||||||
| 168 | determine which server should be checked. | ||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||
| 170 | =cut | ||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | 0 | ▶ | sub server_is_running { | ||||||||||||||||||||||||||
|
Subroutine
server_is_running: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||
| 173 | 0 | ▶ | my $host = $ENV{TWD_HOST} || shift || 'localhost'; | ||||||||||||||||||||||||||
|
Condition0%0/5
$ENV{'TWD_HOST'} || shift() || 'localhost'
$ENV{"TWD_HOST"} or shift()
MC/DC0%0/2
$ENV{'TWD_HOST'} || shift() || 'localhost'
$ENV{"TWD_HOST"}
shift()
Truth table0%0/3
A or B
A= $ENV{"TWD_HOST"}B= shift()
| |||||||||||||||||||||||||||||
| 174 | 0 | ▶ | my $port = $ENV{TWD_PORT} || shift || 4444; | ||||||||||||||||||||||||||
|
Condition0%0/5
$ENV{'TWD_PORT'} || shift() || 4444
$ENV{"TWD_PORT"} or shift()
MC/DC0%0/2
$ENV{'TWD_PORT'} || shift() || 4444
$ENV{"TWD_PORT"}
shift()
Truth table0%0/3
A or B
A= $ENV{"TWD_PORT"}B= shift()
| |||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||
| 176 | 0 | ▶ | return ( $host, $port ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 177 | if IO::Socket::INET->new( | ||||||||||||||||||||||||||||
| 178 | PeerAddr => $host, | ||||||||||||||||||||||||||||
| 179 | PeerPort => $port, | ||||||||||||||||||||||||||||
| 180 | ); | ||||||||||||||||||||||||||||
| 181 | 0 | return; | |||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||
| 184 | =head2 error_handler | ||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||
| 186 | As for L<Selenium::Remote::Driver>, this class also supports adding an | ||||||||||||||||||||||||||||
| 187 | optional C<error_handler> attribute during instantiation : | ||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||
| 189 | my $test_driver = Test::Selenium::Remote::Driver->new( | ||||||||||||||||||||||||||||
| 190 | error_handler => sub { print $_[1]; croak 'goodbye'; } | ||||||||||||||||||||||||||||
| 191 | ); | ||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||
| 193 | Additionally, you can set and/or clear it at any time on an | ||||||||||||||||||||||||||||
| 194 | already-instantiated driver: | ||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||
| 196 | # later, change the error handler to something else | ||||||||||||||||||||||||||||
| 197 | $driver->error_handler( sub { print $_[1]; croak 'hello'; } ); | ||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||
| 199 | # stop handling errors manually and use the default S:R:D behavior | ||||||||||||||||||||||||||||
| 200 | # (we will croak about the exception) | ||||||||||||||||||||||||||||
| 201 | $driver->clear_error_handler; | ||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||
| 203 | Your error handler will receive two arguments, | ||||||||||||||||||||||||||||
| 204 | The first argument is the C<$driver> object itself. | ||||||||||||||||||||||||||||
| 205 | Due to some specificities of this class, the second argument passed to the | ||||||||||||||||||||||||||||
| 206 | handler can be: | ||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||
| 208 | =over | ||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||
| 210 | =item the error message from the Webdriver | ||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||
| 212 | This is the case when the error message is raised by a WebDriver failure | ||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||
| 214 | =item "Failed to find ..." | ||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||
| 216 | This message is raised when the Webdriver call is successful but the failure | ||||||||||||||||||||||||||||
| 217 | occurs on the test performed aftwerwards. This is the case for functions like | ||||||||||||||||||||||||||||
| 218 | C<body_text_like>, C<body_text_unlike>, C<body_text_contains>, C<body_text_lacks>, | ||||||||||||||||||||||||||||
| 219 | C<content_like>, C<content_unlike>, C<content_contains>, C<content_lacks>. | ||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||
| 221 | =back | ||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||
| 223 | If you set your own handler, you should not rely that much on the message returned. | ||||||||||||||||||||||||||||
| 224 | You should also remember that you are entirely responsible for handling exceptions, | ||||||||||||||||||||||||||||
| 225 | which means that should the error handler be called, it means that the test you are | ||||||||||||||||||||||||||||
| 226 | doing has failed, so you should croak. | ||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||
| 228 | You should also call fail() in your handler, in case the function called raised a | ||||||||||||||||||||||||||||
| 229 | webdriver error, because, as exceptions are not caught anymore when you specify a | ||||||||||||||||||||||||||||
| 230 | handler, the function will not fail anymore, which translates to a 'ok' in your TAP | ||||||||||||||||||||||||||||
| 231 | output if you do not handle it properly. | ||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||
| 233 | =head1 Testing Methods | ||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||
| 235 | The following testing methods are available. | ||||||||||||||||||||||||||||
| 236 | For more documentation, see the related methods in L<Selenium::Remote::Driver>. | ||||||||||||||||||||||||||||
| 237 | (And feel free to submit a patch to flesh out the documentation for these here). | ||||||||||||||||||||||||||||
| 238 | Defaults for optional arguments B<should> be the same as for their analogues in | ||||||||||||||||||||||||||||
| 239 | L<Selenium::Remote::Driver>. | ||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||
| 241 | alert_text_is | ||||||||||||||||||||||||||||
| 242 | alert_text_isnt | ||||||||||||||||||||||||||||
| 243 | alert_text_like | ||||||||||||||||||||||||||||
| 244 | alert_text_unlike | ||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||
| 246 | current_window_handle_is | ||||||||||||||||||||||||||||
| 247 | current_window_handle_isnt | ||||||||||||||||||||||||||||
| 248 | current_window_handle_like | ||||||||||||||||||||||||||||
| 249 | current_window_handle_unlike | ||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||
| 251 | window_handles_is | ||||||||||||||||||||||||||||
| 252 | window_handles_isnt | ||||||||||||||||||||||||||||
| 253 | window_handles_like | ||||||||||||||||||||||||||||
| 254 | window_handles_unlike | ||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||
| 256 | window_size_is | ||||||||||||||||||||||||||||
| 257 | window_size_isnt | ||||||||||||||||||||||||||||
| 258 | window_size_like | ||||||||||||||||||||||||||||
| 259 | window_size_unlike | ||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||
| 261 | window_position_is | ||||||||||||||||||||||||||||
| 262 | window_position_isnt | ||||||||||||||||||||||||||||
| 263 | window_position_like | ||||||||||||||||||||||||||||
| 264 | window_position_unlike | ||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||
| 266 | current_url_is | ||||||||||||||||||||||||||||
| 267 | current_url_isnt | ||||||||||||||||||||||||||||
| 268 | current_url_like | ||||||||||||||||||||||||||||
| 269 | current_url_unlike | ||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||
| 271 | title_is | ||||||||||||||||||||||||||||
| 272 | title_isnt | ||||||||||||||||||||||||||||
| 273 | title_like | ||||||||||||||||||||||||||||
| 274 | title_unlike | ||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||
| 277 | active_element_is | ||||||||||||||||||||||||||||
| 278 | active_element_isnt | ||||||||||||||||||||||||||||
| 279 | active_element_like | ||||||||||||||||||||||||||||
| 280 | active_element_unlike | ||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||
| 282 | # Basically the same as 'content_like()', but content_like() supports multiple regex's. | ||||||||||||||||||||||||||||
| 283 | page_source_is | ||||||||||||||||||||||||||||
| 284 | page_source_isnt | ||||||||||||||||||||||||||||
| 285 | page_source_like | ||||||||||||||||||||||||||||
| 286 | page_source_unlike | ||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||
| 288 | send_keys_to_active_element_ok | ||||||||||||||||||||||||||||
| 289 | send_keys_to_alert_ok | ||||||||||||||||||||||||||||
| 290 | send_keys_to_prompt_ok | ||||||||||||||||||||||||||||
| 291 | send_modifier_ok | ||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||
| 293 | accept_alert_ok | ||||||||||||||||||||||||||||
| 294 | dismiss_alert_ok | ||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||
| 296 | move_mouse_to_location_ok # TODO | ||||||||||||||||||||||||||||
| 297 | move_to_ok # TODO | ||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||
| 299 | get_ok | ||||||||||||||||||||||||||||
| 300 | go_back_ok | ||||||||||||||||||||||||||||
| 301 | go_forward_ok | ||||||||||||||||||||||||||||
| 302 | add_cookie_ok | ||||||||||||||||||||||||||||
| 303 | get_page_source_ok | ||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||
| 305 | find_element_ok($search_target) | ||||||||||||||||||||||||||||
| 306 | find_element_ok($search_target) | ||||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||
| 308 | find_elements_ok | ||||||||||||||||||||||||||||
| 309 | find_child_element_ok | ||||||||||||||||||||||||||||
| 310 | find_child_elements_ok | ||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||
| 312 | compare_elements_ok | ||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||
| 314 | click_ok | ||||||||||||||||||||||||||||
| 315 | double_click_ok | ||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||
| 317 | =cut | ||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||
| 319 | # function composing a find_element with locator with a webelement test | ||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||
| 321 | 10 | ▶ | sub _find_element_with_action { | ||||||||||||||||||||||||||
|
Subroutine
_find_element_with_action: called CC=11 SCAR=24.8
| |||||||||||||||||||||||||||||
| 322 | 10 | my $self = shift; | |||||||||||||||||||||||||||
| 323 | 10 | my $method = shift; | |||||||||||||||||||||||||||
| 324 | 10 | my ( $locator, $locator_strategy, $params, $desc ) = @_; | |||||||||||||||||||||||||||
| 325 | 10 | ▶ | $locator_strategy //= 'xpath'; | ||||||||||||||||||||||||||
|
Condition100%2/2
$locator_strategy //= "xpath"
MC/DC100%1/1
$locator_strategy //= "xpath"
$locator_strategy
Truth table100%2/2
A
A= $locator_strategy
| |||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||
| 327 | # case 4 args | ||||||||||||||||||||||||||||
| 328 | 10 | ▶ | if ($desc) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 329 | $self->croak('Invalid locator strategy') | ||||||||||||||||||||||||||||
| 330 | 0 | ▶ | unless ( $self->FINDERS->{$locator_strategy} ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 331 | } | ||||||||||||||||||||||||||||
| 332 | else { | ||||||||||||||||||||||||||||
| 333 | 10 | ▶ | if ($params) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||
| 335 | # means that we called it the 'old way' (no locator strategy) | ||||||||||||||||||||||||||||
| 336 | 6 | ▶ | if ( !defined( $self->FINDERS->{$locator_strategy} ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 337 | 2 | $desc = $params; | |||||||||||||||||||||||||||
| 338 | 2 | $params = $locator_strategy; | |||||||||||||||||||||||||||
| 339 | 2 | $locator_strategy = | |||||||||||||||||||||||||||
| 340 | $self->_get_finder_key( $self->default_finder ); | ||||||||||||||||||||||||||||
| 341 | } | ||||||||||||||||||||||||||||
| 342 | } | ||||||||||||||||||||||||||||
| 343 | else { | ||||||||||||||||||||||||||||
| 344 | # means it was called with no locator strategy and no desc | ||||||||||||||||||||||||||||
| 345 | 4 | ▶ | if ($locator_strategy) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 346 | 4 | ▶ | if ( !defined( $self->FINDERS->{$locator_strategy} ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 347 | 3 | $params = $locator_strategy; | |||||||||||||||||||||||||||
| 348 | 3 | $locator_strategy = | |||||||||||||||||||||||||||
| 349 | $self->_get_finder_key( $self->default_finder ); | ||||||||||||||||||||||||||||
| 350 | } | ||||||||||||||||||||||||||||
| 351 | } | ||||||||||||||||||||||||||||
| 352 | else { | ||||||||||||||||||||||||||||
| 353 | 0 | $self->croak('Not enough arguments'); | |||||||||||||||||||||||||||
| 354 | } | ||||||||||||||||||||||||||||
| 355 | } | ||||||||||||||||||||||||||||
| 356 | } | ||||||||||||||||||||||||||||
| 357 | 10 | ▶ | unless ($desc) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 358 | 8 | $desc = $method; | |||||||||||||||||||||||||||
| 359 | 8 | ▶ | $desc .= "'" . join( " ", ( $params // '' ) ) . "'"; | ||||||||||||||||||||||||||
|
Condition100%2/2
$params // ""
MC/DC100%1/1
$params // ""
$params
Truth table100%2/2
A
A= $params
| |||||||||||||||||||||||||||||
| 360 | } | ||||||||||||||||||||||||||||
| 361 | 10 | my $element; | |||||||||||||||||||||||||||
| 362 | 10 | eval { $element = $self->find_element( $locator, $locator_strategy ); }; | |||||||||||||||||||||||||||
| 363 | 10 | ▶ | if ($@) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 364 | 0 | print "# Error: $@\n"; | |||||||||||||||||||||||||||
| 365 | 0 | return 0; | |||||||||||||||||||||||||||
| 366 | } | ||||||||||||||||||||||||||||
| 367 | 10 | return $element->$method( $params, $desc ); | |||||||||||||||||||||||||||
| 368 | } | ||||||||||||||||||||||||||||
| 369 | |||||||||||||||||||||||||||||
| 370 | =head2 $twd->type_element_ok($search_target [,$locator], $keys, [, $desc ]); | ||||||||||||||||||||||||||||
| 371 | |||||||||||||||||||||||||||||
| 372 | $twd->type_element_ok( $search_target [,$locator], $keys [, $desc ] ); | ||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||
| 374 | Use L<Selenium::Remote::Driver/find_element> to resolve the C<$search_target> | ||||||||||||||||||||||||||||
| 375 | to a web element and an optional locator, and then type C<$keys> into it, providing an optional test | ||||||||||||||||||||||||||||
| 376 | label. | ||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||
| 378 | =cut | ||||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||
| 380 | 2 | ▶ | sub type_element_ok { | ||||||||||||||||||||||||||
|
Subroutine
type_element_ok: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 381 | 2 | my $self = shift; | |||||||||||||||||||||||||||
| 382 | 2 | my $method = 'send_keys_ok'; | |||||||||||||||||||||||||||
| 383 | 2 | return $self->_find_element_with_action( $method, @_ ); | |||||||||||||||||||||||||||
| 384 | } | ||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||
| 386 | =head2 $twd->element_text_is($search_target[,$finder],$expected_text [,$desc]); | ||||||||||||||||||||||||||||
| 387 | |||||||||||||||||||||||||||||
| 388 | $twd->element_text_is($search_target[,$finder],$expected_text [,$desc]); | ||||||||||||||||||||||||||||
| 389 | |||||||||||||||||||||||||||||
| 390 | =cut | ||||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||
| 392 | 2 | ▶ | sub element_text_is { | ||||||||||||||||||||||||||
|
Subroutine
element_text_is: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 393 | 2 | my $self = shift; | |||||||||||||||||||||||||||
| 394 | 2 | my $method = 'text_is'; | |||||||||||||||||||||||||||
| 395 | 2 | return $self->_find_element_with_action( $method, @_ ); | |||||||||||||||||||||||||||
| 396 | } | ||||||||||||||||||||||||||||
| 397 | |||||||||||||||||||||||||||||
| 398 | =head2 $twd->element_value_is($search_target[,$finder],$expected_value [,$desc]); | ||||||||||||||||||||||||||||
| 399 | |||||||||||||||||||||||||||||
| 400 | $twd->element_value_is($search_target[,$finder],$expected_value [,$desc]); | ||||||||||||||||||||||||||||
| 401 | |||||||||||||||||||||||||||||
| 402 | =cut | ||||||||||||||||||||||||||||
| 403 | |||||||||||||||||||||||||||||
| 404 | 1 | ▶ | sub element_value_is { | ||||||||||||||||||||||||||
|
Subroutine
element_value_is: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 405 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 406 | 1 | my $method = 'value_is'; | |||||||||||||||||||||||||||
| 407 | 1 | return $self->_find_element_with_action( $method, @_ ); | |||||||||||||||||||||||||||
| 408 | } | ||||||||||||||||||||||||||||
| 409 | |||||||||||||||||||||||||||||
| 410 | =head2 $twd->click_element_ok($search_target [,$finder ,$desc]); | ||||||||||||||||||||||||||||
| 411 | |||||||||||||||||||||||||||||
| 412 | $twd->click_element_ok($search_target [,$finder ,$desc]); | ||||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||
| 414 | Find an element and then click on it. | ||||||||||||||||||||||||||||
| 415 | |||||||||||||||||||||||||||||
| 416 | =cut | ||||||||||||||||||||||||||||
| 417 | |||||||||||||||||||||||||||||
| 418 | 2 | ▶ | sub click_element_ok { | ||||||||||||||||||||||||||
|
Subroutine
click_element_ok: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 419 | 2 | my $self = shift; | |||||||||||||||||||||||||||
| 420 | 2 | my $method = 'click_ok'; | |||||||||||||||||||||||||||
| 421 | 2 | return $self->_find_element_with_action( $method, @_ ); | |||||||||||||||||||||||||||
| 422 | } | ||||||||||||||||||||||||||||
| 423 | |||||||||||||||||||||||||||||
| 424 | =head2 $twd->clear_element_ok($search_target [,$finder ,$desc]); | ||||||||||||||||||||||||||||
| 425 | |||||||||||||||||||||||||||||
| 426 | $twd->clear_element_ok($search_target [,$finder ,$desc]); | ||||||||||||||||||||||||||||
| 427 | |||||||||||||||||||||||||||||
| 428 | Find an element and then clear on it. | ||||||||||||||||||||||||||||
| 429 | |||||||||||||||||||||||||||||
| 430 | =cut | ||||||||||||||||||||||||||||
| 431 | |||||||||||||||||||||||||||||
| 432 | 1 | ▶ | sub clear_element_ok { | ||||||||||||||||||||||||||
|
Subroutine
clear_element_ok: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 433 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 434 | 1 | my $method = 'clear_ok'; | |||||||||||||||||||||||||||
| 435 | 1 | return $self->_find_element_with_action( $method, @_ ); | |||||||||||||||||||||||||||
| 436 | } | ||||||||||||||||||||||||||||
| 437 | |||||||||||||||||||||||||||||
| 438 | =head2 $twd->is_element_displayed_ok($search_target [,$finder ,$desc]); | ||||||||||||||||||||||||||||
| 439 | |||||||||||||||||||||||||||||
| 440 | $twd->is_element_displayed_ok($search_target [,$finder ,$desc]); | ||||||||||||||||||||||||||||
| 441 | |||||||||||||||||||||||||||||
| 442 | Find an element and check to confirm that it is displayed. (visible) | ||||||||||||||||||||||||||||
| 443 | |||||||||||||||||||||||||||||
| 444 | =cut | ||||||||||||||||||||||||||||
| 445 | |||||||||||||||||||||||||||||
| 446 | 1 | ▶ | sub is_element_displayed_ok { | ||||||||||||||||||||||||||
|
Subroutine
is_element_displayed_ok: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 447 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 448 | 1 | my $method = 'is_displayed_ok'; | |||||||||||||||||||||||||||
| 449 | 1 | return $self->_find_element_with_action( $method, @_ ); | |||||||||||||||||||||||||||
| 450 | } | ||||||||||||||||||||||||||||
| 451 | |||||||||||||||||||||||||||||
| 452 | =head2 $twd->is_element_enabled_ok($search_target [,$finder ,$desc]); | ||||||||||||||||||||||||||||
| 453 | |||||||||||||||||||||||||||||
| 454 | $twd->is_element_enabled_ok($search_target [,$finder ,$desc]); | ||||||||||||||||||||||||||||
| 455 | |||||||||||||||||||||||||||||
| 456 | Find an element and check to confirm that it is enabled. | ||||||||||||||||||||||||||||
| 457 | |||||||||||||||||||||||||||||
| 458 | =cut | ||||||||||||||||||||||||||||
| 459 | |||||||||||||||||||||||||||||
| 460 | 1 | ▶ | sub is_element_enabled_ok { | ||||||||||||||||||||||||||
|
Subroutine
is_element_enabled_ok: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 461 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 462 | 1 | my $method = 'is_enabled_ok'; | |||||||||||||||||||||||||||
| 463 | 1 | return $self->_find_element_with_action( $method, @_ ); | |||||||||||||||||||||||||||
| 464 | } | ||||||||||||||||||||||||||||
| 465 | |||||||||||||||||||||||||||||
| 466 | =head2 $twd->find_element_ok($search_target [,$finder, $desc ]); | ||||||||||||||||||||||||||||
| 467 | |||||||||||||||||||||||||||||
| 468 | $twd->find_element_ok( $search_target [,$finder, $desc ] ); | ||||||||||||||||||||||||||||
| 469 | |||||||||||||||||||||||||||||
| 470 | Returns true if C<$search_target> is successfully found on the page. C<$search_target> | ||||||||||||||||||||||||||||
| 471 | is passed to L<Selenium::Remote::Driver/find_element> using a finder or the C<default_finder> | ||||||||||||||||||||||||||||
| 472 | if none passed. | ||||||||||||||||||||||||||||
| 473 | See there for more details on the format for C<find_element_ok()>. | ||||||||||||||||||||||||||||
| 474 | |||||||||||||||||||||||||||||
| 475 | =head2 $twd->find_no_element_ok($search_target [,$finder, $desc ]); | ||||||||||||||||||||||||||||
| 476 | |||||||||||||||||||||||||||||
| 477 | $twd->find_no_element_ok( $search_target [,$finder, $desc ] ); | ||||||||||||||||||||||||||||
| 478 | |||||||||||||||||||||||||||||
| 479 | Returns true if C<$search_target> is I<not> found on the page. C<$search_target> | ||||||||||||||||||||||||||||
| 480 | is passed to L<Selenium::Remote::Driver/find_element> using a finder or the | ||||||||||||||||||||||||||||
| 481 | C<default_finder> if none passed. See there for more details on the format for C<find_no_element_ok()>. | ||||||||||||||||||||||||||||
| 482 | |||||||||||||||||||||||||||||
| 483 | =head2 $twd->content_like( $regex [, $desc ] ) | ||||||||||||||||||||||||||||
| 484 | |||||||||||||||||||||||||||||
| 485 | $twd->content_like( $regex [, $desc ] ) | ||||||||||||||||||||||||||||
| 486 | $twd->content_like( [$regex_1, $regex_2] [, $desc ] ) | ||||||||||||||||||||||||||||
| 487 | |||||||||||||||||||||||||||||
| 488 | Tells if the content of the page matches I<$regex>. If an arrayref of regex's | ||||||||||||||||||||||||||||
| 489 | are provided, one 'test' is run for each regex against the content of the | ||||||||||||||||||||||||||||
| 490 | current page. | ||||||||||||||||||||||||||||
| 491 | |||||||||||||||||||||||||||||
| 492 | A default description of 'Content is like "$regex"' will be provided if there | ||||||||||||||||||||||||||||
| 493 | is no description. | ||||||||||||||||||||||||||||
| 494 | |||||||||||||||||||||||||||||
| 495 | =cut | ||||||||||||||||||||||||||||
| 496 | |||||||||||||||||||||||||||||
| 497 | 3 | ▶ | sub content_like { | ||||||||||||||||||||||||||
|
Subroutine
content_like: called CC=10 SCAR=29.7
Pod
documented
| |||||||||||||||||||||||||||||
| 498 | 3 | my $self = shift; | |||||||||||||||||||||||||||
| 499 | 3 | my $regex = shift; | |||||||||||||||||||||||||||
| 500 | 3 | my $desc = shift; | |||||||||||||||||||||||||||
| 501 | |||||||||||||||||||||||||||||
| 502 | 3 | local $Test::Builder::Level = $Test::Builder::Level + 1; | |||||||||||||||||||||||||||
| 503 | |||||||||||||||||||||||||||||
| 504 | 3 | my $content = $self->get_page_source(); | |||||||||||||||||||||||||||
| 505 | 3 | my $ret; | |||||||||||||||||||||||||||
| 506 | |||||||||||||||||||||||||||||
| 507 | 3 | ▶ | if ( not ref $regex eq 'ARRAY' ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 508 | 3 | ▶ | $desc = qq{Content is like "$regex"} if ( not defined $desc ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 509 | 3 | $ret = like_string( $content, $regex, $desc ); | |||||||||||||||||||||||||||
| 510 | 3 | ▶ | if ( !$ret && $self->has_error_handler ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not $ret and $self->has_error_handler
MC/DC100%2/2
not $ret and $self->has_error_handler
not $ret
$self->has_error_handler
Truth table100%3/3
not(A) and B
A= not $retB= $self->has_error_handler
| |||||||||||||||||||||||||||||
| 511 | 1 | $self->error_handler->( $self, "Failed to find $regex" ); | |||||||||||||||||||||||||||
| 512 | } | ||||||||||||||||||||||||||||
| 513 | 2 | return $ret; | |||||||||||||||||||||||||||
| 514 | } | ||||||||||||||||||||||||||||
| 515 | elsif ( ref $regex eq 'ARRAY' ) { | ||||||||||||||||||||||||||||
| 516 | 0 | for my $re (@$regex) { | |||||||||||||||||||||||||||
| 517 | 0 | ▶ | $desc = qq{Content is like "$re"} if ( not defined $desc ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 518 | 0 | $ret = like_string( $content, $re, $desc ); | |||||||||||||||||||||||||||
| 519 | 0 | ▶ | if ( !$ret && $self->has_error_handler ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $ret and $self->has_error_handler
MC/DC0%0/2
not $ret and $self->has_error_handler
not $ret
$self->has_error_handler
Truth table0%0/3
not(A) and B
A= not $retB= $self->has_error_handler
| |||||||||||||||||||||||||||||
| 520 | 0 | $self->error_handler->( $self, "Failed to find $re" ); | |||||||||||||||||||||||||||
| 521 | } | ||||||||||||||||||||||||||||
| 522 | } | ||||||||||||||||||||||||||||
| 523 | } | ||||||||||||||||||||||||||||
| 524 | } | ||||||||||||||||||||||||||||
| 525 | |||||||||||||||||||||||||||||
| 526 | =head2 $twd->content_unlike( $regex [, $desc ] ) | ||||||||||||||||||||||||||||
| 527 | |||||||||||||||||||||||||||||
| 528 | $twd->content_unlike( $regex [, $desc ] ) | ||||||||||||||||||||||||||||
| 529 | $twd->content_unlike( [$regex_1, $regex_2] [, $desc ] ) | ||||||||||||||||||||||||||||
| 530 | |||||||||||||||||||||||||||||
| 531 | Tells if the content of the page does NOT match I<$regex>. If an arrayref of regex's | ||||||||||||||||||||||||||||
| 532 | are provided, one 'test' is run for each regex against the content of the | ||||||||||||||||||||||||||||
| 533 | current page. | ||||||||||||||||||||||||||||
| 534 | |||||||||||||||||||||||||||||
| 535 | A default description of 'Content is unlike "$regex"' will be provided if there | ||||||||||||||||||||||||||||
| 536 | is no description. | ||||||||||||||||||||||||||||
| 537 | |||||||||||||||||||||||||||||
| 538 | =cut | ||||||||||||||||||||||||||||
| 539 | |||||||||||||||||||||||||||||
| 540 | 3 | ▶ | sub content_unlike { | ||||||||||||||||||||||||||
|
Subroutine
content_unlike: called CC=10 SCAR=30.2
Pod
documented
| |||||||||||||||||||||||||||||
| 541 | 3 | my $self = shift; | |||||||||||||||||||||||||||
| 542 | 3 | my $regex = shift; | |||||||||||||||||||||||||||
| 543 | 3 | my $desc = shift; | |||||||||||||||||||||||||||
| 544 | 3 | local $Test::Builder::Level = $Test::Builder::Level + 1; | |||||||||||||||||||||||||||
| 545 | |||||||||||||||||||||||||||||
| 546 | 3 | my $content = $self->get_page_source(); | |||||||||||||||||||||||||||
| 547 | 3 | my $ret; | |||||||||||||||||||||||||||
| 548 | |||||||||||||||||||||||||||||
| 549 | 3 | ▶ | if ( not ref $regex eq 'ARRAY' ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 550 | 3 | ▶ | $desc = qq{Content is unlike "$regex"} if ( not defined $desc ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 551 | 3 | $ret = unlike_string( $content, $regex, $desc ); | |||||||||||||||||||||||||||
| 552 | 3 | ▶ | if ( !$ret && $self->has_error_handler ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not $ret and $self->has_error_handler
MC/DC100%2/2
not $ret and $self->has_error_handler
not $ret
$self->has_error_handler
Truth table100%3/3
not(A) and B
A= not $retB= $self->has_error_handler
| |||||||||||||||||||||||||||||
| 553 | 1 | $self->error_handler->( $self, "Failed to find $regex" ); | |||||||||||||||||||||||||||
| 554 | } | ||||||||||||||||||||||||||||
| 555 | } | ||||||||||||||||||||||||||||
| 556 | elsif ( ref $regex eq 'ARRAY' ) { | ||||||||||||||||||||||||||||
| 557 | 0 | for my $re (@$regex) { | |||||||||||||||||||||||||||
| 558 | 0 | ▶ | $desc = qq{Content is unlike "$re"} if ( not defined $desc ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 559 | 0 | $ret = unlike_string( $content, $re, $desc ); | |||||||||||||||||||||||||||
| 560 | 0 | ▶ | if ( !$ret && $self->has_error_handler ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $ret and $self->has_error_handler
MC/DC0%0/2
not $ret and $self->has_error_handler
not $ret
$self->has_error_handler
Truth table0%0/3
not(A) and B
A= not $retB= $self->has_error_handler
| |||||||||||||||||||||||||||||
| 561 | 0 | $self->error_handler->( $self, "Failed to find $re" ); | |||||||||||||||||||||||||||
| 562 | } | ||||||||||||||||||||||||||||
| 563 | } | ||||||||||||||||||||||||||||
| 564 | } | ||||||||||||||||||||||||||||
| 565 | } | ||||||||||||||||||||||||||||
| 566 | |||||||||||||||||||||||||||||
| 567 | =head2 $twd->body_text_like( $regex [, $desc ] ) | ||||||||||||||||||||||||||||
| 568 | |||||||||||||||||||||||||||||
| 569 | $twd->body_text_like( $regex [, $desc ] ) | ||||||||||||||||||||||||||||
| 570 | $twd->body_text_like( [$regex_1, $regex_2] [, $desc ] ) | ||||||||||||||||||||||||||||
| 571 | |||||||||||||||||||||||||||||
| 572 | Tells if the text of the page (as returned by C<< get_body() >>) matches | ||||||||||||||||||||||||||||
| 573 | I<$regex>. If an arrayref of regex's are provided, one 'test' is run for each | ||||||||||||||||||||||||||||
| 574 | regex against the text of the current page. | ||||||||||||||||||||||||||||
| 575 | |||||||||||||||||||||||||||||
| 576 | A default description of 'Text is like "$regex"' will be provided if there | ||||||||||||||||||||||||||||
| 577 | is no description. | ||||||||||||||||||||||||||||
| 578 | |||||||||||||||||||||||||||||
| 579 | To also match the HTML, see C<< content_unlike() >>. | ||||||||||||||||||||||||||||
| 580 | |||||||||||||||||||||||||||||
| 581 | =cut | ||||||||||||||||||||||||||||
| 582 | |||||||||||||||||||||||||||||
| 583 | 3 | ▶ | sub body_text_like { | ||||||||||||||||||||||||||
|
Subroutine
body_text_like: called CC=10 SCAR=29.7
Pod
documented
| |||||||||||||||||||||||||||||
| 584 | 3 | my $self = shift; | |||||||||||||||||||||||||||
| 585 | 3 | my $regex = shift; | |||||||||||||||||||||||||||
| 586 | 3 | my $desc = shift; | |||||||||||||||||||||||||||
| 587 | |||||||||||||||||||||||||||||
| 588 | 3 | local $Test::Builder::Level = $Test::Builder::Level + 1; | |||||||||||||||||||||||||||
| 589 | |||||||||||||||||||||||||||||
| 590 | 3 | my $text = $self->get_body(); | |||||||||||||||||||||||||||
| 591 | 3 | my $ret; | |||||||||||||||||||||||||||
| 592 | |||||||||||||||||||||||||||||
| 593 | 3 | ▶ | if ( not ref $regex eq 'ARRAY' ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 594 | 3 | ▶ | $desc = qq{Text is like "$regex"} if ( not defined $desc ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 595 | 3 | $ret = like_string( $text, $regex, $desc ); | |||||||||||||||||||||||||||
| 596 | 3 | ▶ | if ( !$ret && $self->has_error_handler ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not $ret and $self->has_error_handler
MC/DC100%2/2
not $ret and $self->has_error_handler
not $ret
$self->has_error_handler
Truth table100%3/3
not(A) and B
A= not $retB= $self->has_error_handler
| |||||||||||||||||||||||||||||
| 597 | 1 | $self->error_handler->( $self, "Failed to find $regex" ); | |||||||||||||||||||||||||||
| 598 | } | ||||||||||||||||||||||||||||
| 599 | 2 | return $ret; | |||||||||||||||||||||||||||
| 600 | } | ||||||||||||||||||||||||||||
| 601 | elsif ( ref $regex eq 'ARRAY' ) { | ||||||||||||||||||||||||||||
| 602 | 0 | for my $re (@$regex) { | |||||||||||||||||||||||||||
| 603 | 0 | ▶ | $desc = qq{Text is like "$re"} if ( not defined $desc ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 604 | 0 | $ret = like_string( $text, $re, $desc ); | |||||||||||||||||||||||||||
| 605 | 0 | ▶ | if ( !$ret && $self->has_error_handler ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $ret and $self->has_error_handler
MC/DC0%0/2
not $ret and $self->has_error_handler
not $ret
$self->has_error_handler
Truth table0%0/3
not(A) and B
A= not $retB= $self->has_error_handler
| |||||||||||||||||||||||||||||
| 606 | 0 | $self->error_handler->( $self, "Failed to find $re" ); | |||||||||||||||||||||||||||
| 607 | } | ||||||||||||||||||||||||||||
| 608 | } | ||||||||||||||||||||||||||||
| 609 | } | ||||||||||||||||||||||||||||
| 610 | } | ||||||||||||||||||||||||||||
| 611 | |||||||||||||||||||||||||||||
| 612 | =head2 $twd->body_text_unlike( $regex [, $desc ] ) | ||||||||||||||||||||||||||||
| 613 | |||||||||||||||||||||||||||||
| 614 | $twd->body_text_unlike( $regex [, $desc ] ) | ||||||||||||||||||||||||||||
| 615 | $twd->body_text_unlike( [$regex_1, $regex_2] [, $desc ] ) | ||||||||||||||||||||||||||||
| 616 | |||||||||||||||||||||||||||||
| 617 | Tells if the text of the page (as returned by C<< get_body() >>) | ||||||||||||||||||||||||||||
| 618 | does NOT match I<$regex>. If an arrayref of regex's | ||||||||||||||||||||||||||||
| 619 | are provided, one 'test' is run for each regex against the text of the | ||||||||||||||||||||||||||||
| 620 | current page. | ||||||||||||||||||||||||||||
| 621 | |||||||||||||||||||||||||||||
| 622 | A default description of 'Text is unlike "$regex"' will be provided if there | ||||||||||||||||||||||||||||
| 623 | is no description. | ||||||||||||||||||||||||||||
| 624 | |||||||||||||||||||||||||||||
| 625 | To also match the HTML, see C<< content_unlike() >>. | ||||||||||||||||||||||||||||
| 626 | |||||||||||||||||||||||||||||
| 627 | =cut | ||||||||||||||||||||||||||||
| 628 | |||||||||||||||||||||||||||||
| 629 | 3 | ▶ | sub body_text_unlike { | ||||||||||||||||||||||||||
|
Subroutine
body_text_unlike: called CC=10 SCAR=29.7
Pod
documented
| |||||||||||||||||||||||||||||
| 630 | 3 | my $self = shift; | |||||||||||||||||||||||||||
| 631 | 3 | my $regex = shift; | |||||||||||||||||||||||||||
| 632 | 3 | my $desc = shift; | |||||||||||||||||||||||||||
| 633 | |||||||||||||||||||||||||||||
| 634 | 3 | local $Test::Builder::Level = $Test::Builder::Level + 1; | |||||||||||||||||||||||||||
| 635 | |||||||||||||||||||||||||||||
| 636 | 3 | my $text = $self->get_body(); | |||||||||||||||||||||||||||
| 637 | 3 | my $ret; | |||||||||||||||||||||||||||
| 638 | |||||||||||||||||||||||||||||
| 639 | 3 | ▶ | if ( not ref $regex eq 'ARRAY' ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 640 | 3 | ▶ | $desc = qq{Text is unlike "$regex"} if ( not defined $desc ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 641 | 3 | $ret = unlike_string( $text, $regex, $desc ); | |||||||||||||||||||||||||||
| 642 | 3 | ▶ | if ( !$ret && $self->has_error_handler ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not $ret and $self->has_error_handler
MC/DC100%2/2
not $ret and $self->has_error_handler
not $ret
$self->has_error_handler
Truth table100%3/3
not(A) and B
A= not $retB= $self->has_error_handler
| |||||||||||||||||||||||||||||
| 643 | 1 | $self->error_handler->( $self, "Failed to find $regex" ); | |||||||||||||||||||||||||||
| 644 | } | ||||||||||||||||||||||||||||
| 645 | 2 | return $ret; | |||||||||||||||||||||||||||
| 646 | |||||||||||||||||||||||||||||
| 647 | } | ||||||||||||||||||||||||||||
| 648 | elsif ( ref $regex eq 'ARRAY' ) { | ||||||||||||||||||||||||||||
| 649 | 0 | for my $re (@$regex) { | |||||||||||||||||||||||||||
| 650 | 0 | ▶ | $desc = qq{Text is unlike "$re"} if ( not defined $desc ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 651 | 0 | $ret = unlike_string( $text, $re, $desc ); | |||||||||||||||||||||||||||
| 652 | 0 | ▶ | if ( !$ret && $self->has_error_handler ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $ret and $self->has_error_handler
MC/DC0%0/2
not $ret and $self->has_error_handler
not $ret
$self->has_error_handler
Truth table0%0/3
not(A) and B
A= not $retB= $self->has_error_handler
| |||||||||||||||||||||||||||||
| 653 | 0 | $self->error_handler->( $self, "Failed to find $re" ); | |||||||||||||||||||||||||||
| 654 | } | ||||||||||||||||||||||||||||
| 655 | } | ||||||||||||||||||||||||||||
| 656 | } | ||||||||||||||||||||||||||||
| 657 | } | ||||||||||||||||||||||||||||
| 658 | |||||||||||||||||||||||||||||
| 659 | ##### | ||||||||||||||||||||||||||||
| 660 | |||||||||||||||||||||||||||||
| 661 | =head2 $twd->content_contains( $str [, $desc ] ) | ||||||||||||||||||||||||||||
| 662 | |||||||||||||||||||||||||||||
| 663 | $twd->content_contains( $str [, $desc ] ) | ||||||||||||||||||||||||||||
| 664 | $twd->content_contains( [$str_1, $str_2] [, $desc ] ) | ||||||||||||||||||||||||||||
| 665 | |||||||||||||||||||||||||||||
| 666 | Tells if the content of the page contains I<$str>. If an arrayref of strings | ||||||||||||||||||||||||||||
| 667 | are provided, one 'test' is run for each string against the content of the | ||||||||||||||||||||||||||||
| 668 | current page. | ||||||||||||||||||||||||||||
| 669 | |||||||||||||||||||||||||||||
| 670 | A default description of 'Content contains "$str"' will be provided if there | ||||||||||||||||||||||||||||
| 671 | is no description. | ||||||||||||||||||||||||||||
| 672 | |||||||||||||||||||||||||||||
| 673 | =cut | ||||||||||||||||||||||||||||
| 674 | |||||||||||||||||||||||||||||
| 675 | 3 | ▶ | sub content_contains { | ||||||||||||||||||||||||||
|
Subroutine
content_contains: called CC=10 SCAR=29.7
Pod
documented
| |||||||||||||||||||||||||||||
| 676 | 3 | my $self = shift; | |||||||||||||||||||||||||||
| 677 | 3 | my $str = shift; | |||||||||||||||||||||||||||
| 678 | 3 | my $desc = shift; | |||||||||||||||||||||||||||
| 679 | |||||||||||||||||||||||||||||
| 680 | 3 | local $Test::Builder::Level = $Test::Builder::Level + 1; | |||||||||||||||||||||||||||
| 681 | |||||||||||||||||||||||||||||
| 682 | 3 | my $content = $self->get_page_source(); | |||||||||||||||||||||||||||
| 683 | 3 | my $ret; | |||||||||||||||||||||||||||
| 684 | |||||||||||||||||||||||||||||
| 685 | 3 | ▶ | if ( not ref $str eq 'ARRAY' ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 686 | 3 | ▶ | $desc = qq{Content contains "$str"} if ( not defined $desc ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 687 | 3 | $ret = contains_string( $content, $str, $desc ); | |||||||||||||||||||||||||||
| 688 | 3 | ▶ | if ( !$ret && $self->has_error_handler ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not $ret and $self->has_error_handler
MC/DC100%2/2
not $ret and $self->has_error_handler
not $ret
$self->has_error_handler
Truth table100%3/3
not(A) and B
A= not $retB= $self->has_error_handler
| |||||||||||||||||||||||||||||
| 689 | 1 | $self->error_handler->( $self, "Failed to find $str" ); | |||||||||||||||||||||||||||
| 690 | } | ||||||||||||||||||||||||||||
| 691 | 2 | return $ret; | |||||||||||||||||||||||||||
| 692 | } | ||||||||||||||||||||||||||||
| 693 | elsif ( ref $str eq 'ARRAY' ) { | ||||||||||||||||||||||||||||
| 694 | 0 | for my $s (@$str) { | |||||||||||||||||||||||||||
| 695 | 0 | ▶ | $desc = qq{Content contains "$s"} if ( not defined $desc ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 696 | 0 | $ret = contains_string( $content, $s, $desc ); | |||||||||||||||||||||||||||
| 697 | |||||||||||||||||||||||||||||
| 698 | 0 | ▶ | if ( !$ret && $self->has_error_handler ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $ret and $self->has_error_handler
MC/DC0%0/2
not $ret and $self->has_error_handler
not $ret
$self->has_error_handler
Truth table0%0/3
not(A) and B
A= not $retB= $self->has_error_handler
| |||||||||||||||||||||||||||||
| 699 | 0 | $self->error_handler->( $self, "Failed to find $s" ); | |||||||||||||||||||||||||||
| 700 | } | ||||||||||||||||||||||||||||
| 701 | } | ||||||||||||||||||||||||||||
| 702 | } | ||||||||||||||||||||||||||||
| 703 | } | ||||||||||||||||||||||||||||
| 704 | |||||||||||||||||||||||||||||
| 705 | =head2 $twd->content_lacks( $str [, $desc ] ) | ||||||||||||||||||||||||||||
| 706 | |||||||||||||||||||||||||||||
| 707 | $twd->content_lacks( $str [, $desc ] ) | ||||||||||||||||||||||||||||
| 708 | $twd->content_lacks( [$str_1, $str_2] [, $desc ] ) | ||||||||||||||||||||||||||||
| 709 | |||||||||||||||||||||||||||||
| 710 | Tells if the content of the page does NOT contain I<$str>. If an arrayref of strings | ||||||||||||||||||||||||||||
| 711 | are provided, one 'test' is run for each string against the content of the | ||||||||||||||||||||||||||||
| 712 | current page. | ||||||||||||||||||||||||||||
| 713 | |||||||||||||||||||||||||||||
| 714 | A default description of 'Content lacks "$str"' will be provided if there | ||||||||||||||||||||||||||||
| 715 | is no description. | ||||||||||||||||||||||||||||
| 716 | |||||||||||||||||||||||||||||
| 717 | =cut | ||||||||||||||||||||||||||||
| 718 | |||||||||||||||||||||||||||||
| 719 | 3 | ▶ | sub content_lacks { | ||||||||||||||||||||||||||
|
Subroutine
content_lacks: called CC=10 SCAR=29.7
Pod
documented
| |||||||||||||||||||||||||||||
| 720 | 3 | my $self = shift; | |||||||||||||||||||||||||||
| 721 | 3 | my $str = shift; | |||||||||||||||||||||||||||
| 722 | 3 | my $desc = shift; | |||||||||||||||||||||||||||
| 723 | |||||||||||||||||||||||||||||
| 724 | 3 | local $Test::Builder::Level = $Test::Builder::Level + 1; | |||||||||||||||||||||||||||
| 725 | |||||||||||||||||||||||||||||
| 726 | 3 | my $content = $self->get_page_source(); | |||||||||||||||||||||||||||
| 727 | 3 | my $ret; | |||||||||||||||||||||||||||
| 728 | |||||||||||||||||||||||||||||
| 729 | 3 | ▶ | if ( not ref $str eq 'ARRAY' ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 730 | 3 | ▶ | $desc = qq{Content lacks "$str"} if ( not defined $desc ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 731 | 3 | $ret = lacks_string( $content, $str, $desc ); | |||||||||||||||||||||||||||
| 732 | 3 | ▶ | if ( !$ret && $self->has_error_handler ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not $ret and $self->has_error_handler
MC/DC100%2/2
not $ret and $self->has_error_handler
not $ret
$self->has_error_handler
Truth table100%3/3
not(A) and B
A= not $retB= $self->has_error_handler
| |||||||||||||||||||||||||||||
| 733 | 1 | $self->error_handler->( $self, "Failed to find $str" ); | |||||||||||||||||||||||||||
| 734 | } | ||||||||||||||||||||||||||||
| 735 | 2 | return $ret; | |||||||||||||||||||||||||||
| 736 | } | ||||||||||||||||||||||||||||
| 737 | elsif ( ref $str eq 'ARRAY' ) { | ||||||||||||||||||||||||||||
| 738 | 0 | for my $s (@$str) { | |||||||||||||||||||||||||||
| 739 | 0 | ▶ | $desc = qq{Content lacks "$s"} if ( not defined $desc ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 740 | 0 | $ret = lacks_string( $content, $s, $desc ); | |||||||||||||||||||||||||||
| 741 | 0 | ▶ | if ( !$ret && $self->has_error_handler ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $ret and $self->has_error_handler
MC/DC0%0/2
not $ret and $self->has_error_handler
not $ret
$self->has_error_handler
Truth table0%0/3
not(A) and B
A= not $retB= $self->has_error_handler
| |||||||||||||||||||||||||||||
| 742 | 0 | $self->error_handler->( $self, "Failed to find $s" ); | |||||||||||||||||||||||||||
| 743 | } | ||||||||||||||||||||||||||||
| 744 | } | ||||||||||||||||||||||||||||
| 745 | } | ||||||||||||||||||||||||||||
| 746 | } | ||||||||||||||||||||||||||||
| 747 | |||||||||||||||||||||||||||||
| 748 | =head2 $twd->body_text_contains( $str [, $desc ] ) | ||||||||||||||||||||||||||||
| 749 | |||||||||||||||||||||||||||||
| 750 | $twd->body_text_contains( $str [, $desc ] ) | ||||||||||||||||||||||||||||
| 751 | $twd->body_text_contains( [$str_1, $str_2] [, $desc ] ) | ||||||||||||||||||||||||||||
| 752 | |||||||||||||||||||||||||||||
| 753 | Tells if the text of the page (as returned by C<< get_body() >>) contains | ||||||||||||||||||||||||||||
| 754 | I<$str>. If an arrayref of strings are provided, one 'test' is run for each | ||||||||||||||||||||||||||||
| 755 | string against the text of the current page. | ||||||||||||||||||||||||||||
| 756 | |||||||||||||||||||||||||||||
| 757 | A default description of 'Text contains "$str"' will be provided if there | ||||||||||||||||||||||||||||
| 758 | is no description. | ||||||||||||||||||||||||||||
| 759 | |||||||||||||||||||||||||||||
| 760 | To also match the HTML, see C<< content_lacks() >>. | ||||||||||||||||||||||||||||
| 761 | |||||||||||||||||||||||||||||
| 762 | =cut | ||||||||||||||||||||||||||||
| 763 | |||||||||||||||||||||||||||||
| 764 | 3 | ▶ | sub body_text_contains { | ||||||||||||||||||||||||||
|
Subroutine
body_text_contains: called CC=10 SCAR=23.8
Pod
documented
| |||||||||||||||||||||||||||||
| 765 | 3 | my $self = shift; | |||||||||||||||||||||||||||
| 766 | 3 | my $str = shift; | |||||||||||||||||||||||||||
| 767 | 3 | my $desc = shift; | |||||||||||||||||||||||||||
| 768 | |||||||||||||||||||||||||||||
| 769 | 3 | local $Test::Builder::Level = $Test::Builder::Level + 1; | |||||||||||||||||||||||||||
| 770 | |||||||||||||||||||||||||||||
| 771 | 3 | my $text = $self->get_body(); | |||||||||||||||||||||||||||
| 772 | 3 | my $ret; | |||||||||||||||||||||||||||
| 773 | |||||||||||||||||||||||||||||
| 774 | 3 | ▶ | if ( not ref $str eq 'ARRAY' ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 775 | 2 | ▶ | $desc = qq{Text contains "$str"} if ( not defined $desc ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 776 | 2 | $ret = contains_string( $text, $str, $desc ); | |||||||||||||||||||||||||||
| 777 | 2 | ▶ | if ( !$ret && $self->has_error_handler ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not $ret and $self->has_error_handler
MC/DC50%1/2
not $ret and $self->has_error_handler
not $ret
$self->has_error_handler
Truth table66%2/3
not(A) and B
A= not $retB= $self->has_error_handler
| |||||||||||||||||||||||||||||
| 778 | 1 | $self->error_handler->( $self, "Failed to find $str" ); | |||||||||||||||||||||||||||
| 779 | } | ||||||||||||||||||||||||||||
| 780 | 1 | return $ret; | |||||||||||||||||||||||||||
| 781 | } | ||||||||||||||||||||||||||||
| 782 | elsif ( ref $str eq 'ARRAY' ) { | ||||||||||||||||||||||||||||
| 783 | 1 | for my $s (@$str) { | |||||||||||||||||||||||||||
| 784 | 2 | ▶ | $desc = qq{Text contains "$s"} if ( not defined $desc ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 785 | 2 | $ret = contains_string( $text, $s, $desc ); | |||||||||||||||||||||||||||
| 786 | 2 | ▶ | if ( !$ret && $self->has_error_handler ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not $ret and $self->has_error_handler
MC/DC0%0/2
not $ret and $self->has_error_handler
not $ret
$self->has_error_handler
Truth table33%1/3
not(A) and B
A= not $retB= $self->has_error_handler
| |||||||||||||||||||||||||||||
| 787 | 0 | $self->error_handler->( $self, "Failed to find $s" ); | |||||||||||||||||||||||||||
| 788 | } | ||||||||||||||||||||||||||||
| 789 | } | ||||||||||||||||||||||||||||
| 790 | } | ||||||||||||||||||||||||||||
| 791 | } | ||||||||||||||||||||||||||||
| 792 | |||||||||||||||||||||||||||||
| 793 | =head2 $twd->body_text_lacks( $str [, $desc ] ) | ||||||||||||||||||||||||||||
| 794 | |||||||||||||||||||||||||||||
| 795 | $twd->body_text_lacks( $str [, $desc ] ) | ||||||||||||||||||||||||||||
| 796 | $twd->body_text_lacks( [$str_1, $str_2] [, $desc ] ) | ||||||||||||||||||||||||||||
| 797 | |||||||||||||||||||||||||||||
| 798 | Tells if the text of the page (as returned by C<< get_body() >>) | ||||||||||||||||||||||||||||
| 799 | does NOT contain I<$str>. If an arrayref of strings | ||||||||||||||||||||||||||||
| 800 | are provided, one 'test' is run for each string against the content of the | ||||||||||||||||||||||||||||
| 801 | current page. | ||||||||||||||||||||||||||||
| 802 | |||||||||||||||||||||||||||||
| 803 | A default description of 'Text lacks "$str"' will be provided if there | ||||||||||||||||||||||||||||
| 804 | is no description. | ||||||||||||||||||||||||||||
| 805 | |||||||||||||||||||||||||||||
| 806 | To also match the HTML, see C<< content_lacks() >>. | ||||||||||||||||||||||||||||
| 807 | |||||||||||||||||||||||||||||
| 808 | =cut | ||||||||||||||||||||||||||||
| 809 | |||||||||||||||||||||||||||||
| 810 | 3 | ▶ | sub body_text_lacks { | ||||||||||||||||||||||||||
|
Subroutine
body_text_lacks: called CC=10 SCAR=23.5
Pod
documented
| |||||||||||||||||||||||||||||
| 811 | 3 | my $self = shift; | |||||||||||||||||||||||||||
| 812 | 3 | my $str = shift; | |||||||||||||||||||||||||||
| 813 | 3 | my $desc = shift; | |||||||||||||||||||||||||||
| 814 | |||||||||||||||||||||||||||||
| 815 | 3 | local $Test::Builder::Level = $Test::Builder::Level + 1; | |||||||||||||||||||||||||||
| 816 | |||||||||||||||||||||||||||||
| 817 | 3 | my $text = $self->get_body(); | |||||||||||||||||||||||||||
| 818 | 3 | my $ret; | |||||||||||||||||||||||||||
| 819 | |||||||||||||||||||||||||||||
| 820 | 3 | ▶ | if ( not ref $str eq 'ARRAY' ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 821 | 1 | ▶ | $desc = qq{Text lacks "$str"} if ( not defined $desc ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 822 | 1 | $ret = lacks_string( $text, $str, $desc ); | |||||||||||||||||||||||||||
| 823 | 1 | ▶ | if ( !$ret && $self->has_error_handler ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not $ret and $self->has_error_handler
MC/DC0%0/2
not $ret and $self->has_error_handler
not $ret
$self->has_error_handler
Truth table33%1/3
not(A) and B
A= not $retB= $self->has_error_handler
| |||||||||||||||||||||||||||||
| 824 | 0 | $self->error_handler->( $self, "Failed to find $str" ); | |||||||||||||||||||||||||||
| 825 | } | ||||||||||||||||||||||||||||
| 826 | 1 | return $ret; | |||||||||||||||||||||||||||
| 827 | } | ||||||||||||||||||||||||||||
| 828 | elsif ( ref $str eq 'ARRAY' ) { | ||||||||||||||||||||||||||||
| 829 | 2 | for my $s (@$str) { | |||||||||||||||||||||||||||
| 830 | 3 | ▶ | $desc = qq{Text lacks "$s"} if ( not defined $desc ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 831 | 3 | $ret = lacks_string( $text, $s, $desc ); | |||||||||||||||||||||||||||
| 832 | 3 | ▶ | if ( !$ret && $self->has_error_handler ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not $ret and $self->has_error_handler
MC/DC100%2/2
not $ret and $self->has_error_handler
not $ret
$self->has_error_handler
Truth table100%3/3
not(A) and B
A= not $retB= $self->has_error_handler
| |||||||||||||||||||||||||||||
| 833 | 1 | $self->error_handler->( $self, "Failed to find $s" ); | |||||||||||||||||||||||||||
| 834 | } | ||||||||||||||||||||||||||||
| 835 | } | ||||||||||||||||||||||||||||
| 836 | } | ||||||||||||||||||||||||||||
| 837 | } | ||||||||||||||||||||||||||||
| 838 | |||||||||||||||||||||||||||||
| 839 | 13 | 1; | |||||||||||||||||||||||||||
| 840 | |||||||||||||||||||||||||||||
| 841 | __END__ | ||||||||||||||||||||||||||||