Browse Source

Fix #180 : removed the 'my' before some desc in body_ and content_ functions, added some tests

Emmanuel 'BHS_error' Peroumalnaik 11 years ago
parent
commit
c30b087bc4
2 changed files with 23 additions and 13 deletions
  1. 12 12
      lib/Test/Selenium/Remote/Driver.pm
  2. 11 1
      t/Test-Selenium-Remote-Driver.t

+ 12 - 12
lib/Test/Selenium/Remote/Driver.pm

@@ -503,12 +503,12 @@ sub body_text_like {
     my $text = $self->get_body();
     my $text = $self->get_body();
 
 
     if ( not ref $regex eq 'ARRAY' ) {
     if ( not ref $regex eq 'ARRAY' ) {
-        my $desc = qq{Text is like "$regex"} if ( not defined $desc );
+        $desc = qq{Text is like "$regex"} if ( not defined $desc );
         return like_string( $text, $regex, $desc );
         return like_string( $text, $regex, $desc );
     }
     }
     elsif ( ref $regex eq 'ARRAY' ) {
     elsif ( ref $regex eq 'ARRAY' ) {
         for my $re (@$regex) {
         for my $re (@$regex) {
-            my $desc = qq{Text is like "$re"} if ( not defined $desc );
+            $desc = qq{Text is like "$re"} if ( not defined $desc );
             like_string( $text, $re, $desc );
             like_string( $text, $re, $desc );
         }
         }
     }
     }
@@ -541,12 +541,12 @@ sub body_text_unlike {
     my $text = $self->get_body();
     my $text = $self->get_body();
 
 
     if ( not ref $regex eq 'ARRAY' ) {
     if ( not ref $regex eq 'ARRAY' ) {
-        my $desc = qq{Text is unlike "$regex"} if ( not defined $desc );
+        $desc = qq{Text is unlike "$regex"} if ( not defined $desc );
         return unlike_string( $text, $regex, $desc );
         return unlike_string( $text, $regex, $desc );
     }
     }
     elsif ( ref $regex eq 'ARRAY' ) {
     elsif ( ref $regex eq 'ARRAY' ) {
         for my $re (@$regex) {
         for my $re (@$regex) {
-            my $desc = qq{Text is unlike "$re"} if ( not defined $desc );
+            $desc = qq{Text is unlike "$re"} if ( not defined $desc );
             unlike_string( $text, $re, $desc );
             unlike_string( $text, $re, $desc );
         }
         }
     }
     }
@@ -578,12 +578,12 @@ sub content_contains {
     my $content = $self->get_page_source();
     my $content = $self->get_page_source();
 
 
     if ( not ref $str eq 'ARRAY' ) {
     if ( not ref $str eq 'ARRAY' ) {
-        my $desc = qq{Content contains "$str"} if ( not defined $desc );
+        $desc = qq{Content contains "$str"} if ( not defined $desc );
         return contains_string( $content, $str, $desc );
         return contains_string( $content, $str, $desc );
     }
     }
     elsif ( ref $str eq 'ARRAY' ) {
     elsif ( ref $str eq 'ARRAY' ) {
         for my $s (@$str) {
         for my $s (@$str) {
-            my $desc = qq{Content contains "$s"} if ( not defined $desc );
+            $desc = qq{Content contains "$s"} if ( not defined $desc );
             contains_string( $content, $s, $desc );
             contains_string( $content, $s, $desc );
         }
         }
     }
     }
@@ -613,12 +613,12 @@ sub content_lacks {
     my $content = $self->get_page_source();
     my $content = $self->get_page_source();
 
 
     if ( not ref $str eq 'ARRAY' ) {
     if ( not ref $str eq 'ARRAY' ) {
-        my $desc = qq{Content lacks "$str"} if ( not defined $desc );
+        $desc = qq{Content lacks "$str"} if ( not defined $desc );
         return lacks_string( $content, $str, $desc );
         return lacks_string( $content, $str, $desc );
     }
     }
     elsif ( ref $str eq 'ARRAY' ) {
     elsif ( ref $str eq 'ARRAY' ) {
         for my $s (@$str) {
         for my $s (@$str) {
-            my $desc = qq{Content lacks "$s"} if ( not defined $desc );
+            $desc = qq{Content lacks "$s"} if ( not defined $desc );
             lacks_string( $content, $s, $desc );
             lacks_string( $content, $s, $desc );
         }
         }
     }
     }
@@ -651,12 +651,12 @@ sub body_text_contains {
     my $text = $self->get_body();
     my $text = $self->get_body();
 
 
     if ( not ref $str eq 'ARRAY' ) {
     if ( not ref $str eq 'ARRAY' ) {
-        my $desc = qq{Text contains "$str"} if ( not defined $desc );
+        $desc = qq{Text contains "$str"} if ( not defined $desc );
         return contains_string( $text, $str, $desc );
         return contains_string( $text, $str, $desc );
     }
     }
     elsif ( ref $str eq 'ARRAY' ) {
     elsif ( ref $str eq 'ARRAY' ) {
         for my $s (@$str) {
         for my $s (@$str) {
-            my $desc = qq{Text contains "$s"} if ( not defined $desc );
+            $desc = qq{Text contains "$s"} if ( not defined $desc );
             contains_string( $text, $s, $desc );
             contains_string( $text, $s, $desc );
         }
         }
     }
     }
@@ -689,12 +689,12 @@ sub body_text_lacks {
     my $text = $self->get_body();
     my $text = $self->get_body();
 
 
     if ( not ref $str eq 'ARRAY' ) {
     if ( not ref $str eq 'ARRAY' ) {
-        my $desc = qq{Text is lacks "$str"} if ( not defined $desc );
+        $desc = qq{Text is lacks "$str"} if ( not defined $desc );
         return lacks_string( $text, $str, $desc );
         return lacks_string( $text, $str, $desc );
     }
     }
     elsif ( ref $str eq 'ARRAY' ) {
     elsif ( ref $str eq 'ARRAY' ) {
         for my $s (@$str) {
         for my $s (@$str) {
-            my $desc = qq{Text is lacks "$s"} if ( not defined $desc );
+            $desc = qq{Text is lacks "$s"} if ( not defined $desc );
             lacks_string( $text, $s, $desc );
             lacks_string( $text, $s, $desc );
         }
         }
     }
     }

+ 11 - 1
t/Test-Selenium-Remote-Driver.t

@@ -16,6 +16,9 @@ my $find_element = sub {
     {
     {
         return { status => 'OK', return => { ELEMENT => '123457' } };
         return { status => 'OK', return => { ELEMENT => '123457' } };
     }
     }
+    if ( $searched_item->{value} eq '//body' && $searched_item->{using} eq 'xpath') { 
+        return { status => 'OK', return => { ELEMENT => '123458' } };
+    }
     return { status => 'NOK', return => 0, error => 'element not found' };
     return { status => 'NOK', return => 0, error => 'element not found' };
 };
 };
 my $find_child_element = sub {
 my $find_child_element = sub {
@@ -59,6 +62,7 @@ my $get_text = sub {
     my ($session_object) =@_; 
     my ($session_object) =@_; 
     return 'abc' if ($session_object->{id} eq '123456');
     return 'abc' if ($session_object->{id} eq '123456');
     return 'def' if ($session_object->{id} eq '123457');
     return 'def' if ($session_object->{id} eq '123457');
+    return 'this output matches' if ($session_object->{id} eq '123458');
     return;
     return;
 };
 };
 
 
@@ -105,9 +109,15 @@ dies_ok{ $successful_driver->find_child_element_ok({id => 1200}) } 'find_child_e
 
 
 $successful_driver->find_no_element_ok('notq','xpath','find_no_element_ok works');
 $successful_driver->find_no_element_ok('notq','xpath','find_no_element_ok works');
 
 
-
+# body and content function family 
 $successful_driver->content_like( qr/matches/, 'content_like works');
 $successful_driver->content_like( qr/matches/, 'content_like works');
 $successful_driver->content_unlike( qr/nomatch/, 'content_unlike works');
 $successful_driver->content_unlike( qr/nomatch/, 'content_unlike works');
+$successful_driver->content_contains( 'matches', 'content_contains works');
+$successful_driver->content_lacks( 'nomatch', 'content_lacks works');
+$successful_driver->body_text_contains( ['match','output'], 'body_text_contains works');
+$successful_driver->body_text_lacks( 'nomatch', 'body_text_lacks works');
+$successful_driver->body_text_like( qr/this/, 'body_text_like works');
+$successful_driver->body_text_unlike( qr/notthis/, 'body_text_unlike works');
 
 
 $successful_driver->type_element_ok('q','abc');
 $successful_driver->type_element_ok('q','abc');
 $successful_driver->type_element_ok('p','class','def','type_element_ok works with a locator');
 $successful_driver->type_element_ok('p','class','def','type_element_ok works with a locator');