Skip to content

Commit

Permalink
version 1.4.1 - assertnear
Browse files Browse the repository at this point in the history
  • Loading branch information
tim-buckland committed Jan 5, 2021
1 parent 361e3bf commit dfdc98b
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ Version 1.42 onwards - https://github.com/Qarj/WebImblaze
---------------------------------
## WebImblaze Release History:

### Version 1.4.1 - Jan 5, 2021
* added an assertnear assertion for non exact value comparison

### Version 1.4.0 - Oct 10, 2020
* changed the auto assertions to negative assertions and provided a way to capture info (e.g. error references) and display in reporting

Expand Down
19 changes: 18 additions & 1 deletion MANUAL.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Manual for WebImblaze version 1.4.0
# Manual for WebImblaze version 1.4.1

## Overview

Expand Down Expand Up @@ -124,6 +124,8 @@

- [assertcount](#assertcount)

- [assertnear](#assertnear)

- [verifyresponsecode](#verifyresponsecode)

- [verifyresponsetime](#verifyresponsetime)
Expand Down Expand Up @@ -1713,6 +1715,21 @@ assertcount: uniquedata1092311|||2|||Expect 2 records only|||Production Bug
<br />


#### assertnear

Used to assert that a value is near enough another value.

```
assertnear: some_anchor(value to grab)|||expected_value|||max_deviance|||Optional custom error message
```

```
assertnear: offsetLeft.(\d+)|||50|||20|||Value is further away from 50 than the max deviance of 20
```

<br />


#### verifyresponsecode

HTTP response code for verification. Verification fails if the HTTP response code you specified does not match the HTTP response
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# WebImblaze 1.4.0
# WebImblaze 1.4.1

_UTF-8 is now well supported and the default, and gzip response content is now uncompressed automatically._

Expand Down
50 changes: 49 additions & 1 deletion wi.pl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use strict;
use vars qw/ $VERSION /;

$VERSION = '1.4.0';
$VERSION = '1.4.1';

# This project is a fork of WebInject version 1.41, http://webinject.org/.
# Copyright 2004-2006 Corey Goldberg ([email protected])
Expand Down Expand Up @@ -1908,6 +1908,7 @@ sub verify { # do verification of http response and print status to HTML/XML/ST
_verify_verifypositive();
_verify_verifynegative();
_verify_assertcount();
_verify_assertnear();
_verify_verifyresponsetime();

if ($case{verifyresponsecode}) {
Expand Down Expand Up @@ -2273,6 +2274,53 @@ sub _verify_assertcount {
return;
}

sub _verify_assertnear {

foreach my $_case_attribute ( sort keys %case ) {
if ( (substr $_case_attribute, 0, 14) eq 'assertnear' ) {
my $_verify_number = $_case_attribute; # determine index assertnear index
$_verify_number =~ s/^assertnear//g; # remove assertnear from string
if (!$_verify_number) {$_verify_number = '0';} # if assertnear, need to treat as 0
my @_verifyparms = split /[|][|][|]/, $case{$_case_attribute} ; # index 0 contains the regex for the value to check, 1 the value to be near, 2 the allowed deviance, 3 the message on failure
my $_actual = 0;
if (uncoded() =~ m/$_verifyparms[0]/si) {
$_actual = $1;
}
my $_near = $_verifyparms[1];
my $_max_deviance = $_verifyparms[2];
my $_min = $_near - $_max_deviance;
my $_max = $_near + $_max_deviance;
my $_info = " resolving to $_actual is between $_min and $_max";
$results_xml .= " <$_case_attribute>\n";
$results_xml .= ' <assert>'._sub_xml_special($_verifyparms[0])."$_info</assert>\n";
if ($_actual > $_min && $_actual < $_max ) {
$results_html .= qq|<span class="pass">Passed Assert Near</span><br />\n|;
$results_xml .= qq| <success>true</success>\n|;
$results_stdout .= "Passed Assert Near \n";
$passed_count++;
$retry_passed_count++;
} else {
$results_html .= qq|<span class="fail">Failed Assert Near:</span> $_verifyparms[0]$_info<br />\n|;
$results_xml .= qq| <success>false</success>\n|;
if ($_verifyparms[3]) { # is there a custom assertion failure message?
$results_html .= qq|<span class="fail">$_verifyparms[3]</span><br />\n|;
$results_xml .= ' <message>'._sub_xml_special($_verifyparms[3])."</message>\n";
}
colour_stdout('bold yellow', "Failed Assert Near $_verify_number: $_verifyparms[0]$_info\n");
if ($_verifyparms[3]) {
colour_stdout('bold yellow', "$_verifyparms[3] \n");
}
$failed_count++;
$retry_failed_count++;
$is_failure++;
}
$results_xml .= qq| </$_case_attribute>\n|;
}
}

return;
}

#------------------------------------------------------------------
sub parseresponse { # parse values from responses for use in future request (for session id's, dynamic URL rewriting, etc)

Expand Down

0 comments on commit dfdc98b

Please sign in to comment.