18 January 2026:
Sahi Pro is an enterprise grade test automation platform which can automate web, mobile, API, windows and java based applications and SAP.
This forum is now archived and is in read-only mode. Please continue discussions on our improved new Sahi Pro Community forum.
Sahi Pro is an enterprise grade test automation platform which can automate web, mobile, API, windows and java based applications and SAP.
Assertion issue
Hi All,
I have the following assertion in a test:
_assertExists(_cell(59));
_assert(_isVisible(_cell(59)));
_assertEqual($new_limit, _getText(_cell(59)));
_assertContainsText($new_limit, _cell(59));
The assertion fails, as indicated by the log output below, when running the test:
_assertEqual("$ 50502.50", _getText(_cell(59)));
Assertion Failed.
Expected:"$ 50502.50"
Actual:"$ 50,502.50" at 16 Jan 2014 2:57:56 PM
I do some string manipulation using the following function which inserts commas and decimal places:
function addCommas($current_limit) {
$new_limit = $current_limit.replace(/[a-z,()\","]/gi, "");
//$s = Math.round($ * Math.pow(10,2)) / Math.pow(10,2); // 2DP
$new_limit = (+$new_limit + 100.50).toFixed(2);
$new_limit = $new_limit.toString();
var $ssplt = $new_limit.split(".");
$new_limit = Number($ssplt[0]).toLocaleString();
$new_limit = $new_limit.replace(/\..+/,"");
$new_limit = "$ " + $new_limit + "."+ ($ssplt[1] || "00");
return $new_limit;
}
What I find strange is that when I test the code in the Sahi Controller, the $new_limit value comes out as expected, i.e "$ 50,502.60", so what I'd like to know is whether or not I'm the issue or is something going wrong with Sahi?
Thanks,
JB
I have the following assertion in a test:
_assertExists(_cell(59));
_assert(_isVisible(_cell(59)));
_assertEqual($new_limit, _getText(_cell(59)));
_assertContainsText($new_limit, _cell(59));
The assertion fails, as indicated by the log output below, when running the test:
_assertEqual("$ 50502.50", _getText(_cell(59)));
Assertion Failed.
Expected:"$ 50502.50"
Actual:"$ 50,502.50" at 16 Jan 2014 2:57:56 PM
I do some string manipulation using the following function which inserts commas and decimal places:
function addCommas($current_limit) {
$new_limit = $current_limit.replace(/[a-z,()\","]/gi, "");
//$s = Math.round($ * Math.pow(10,2)) / Math.pow(10,2); // 2DP
$new_limit = (+$new_limit + 100.50).toFixed(2);
$new_limit = $new_limit.toString();
var $ssplt = $new_limit.split(".");
$new_limit = Number($ssplt[0]).toLocaleString();
$new_limit = $new_limit.replace(/\..+/,"");
$new_limit = "$ " + $new_limit + "."+ ($ssplt[1] || "00");
return $new_limit;
}
What I find strange is that when I test the code in the Sahi Controller, the $new_limit value comes out as expected, i.e "$ 50,502.60", so what I'd like to know is whether or not I'm the issue or is something going wrong with Sahi?
Thanks,
JB
Answers
When you have already done string manipulation on the output and you get the commas as expected, why are you not asserting with "$ 50,502.50" instead of "$ 50502.50"?
Regards,
Pratyush
Thanks for the reply.
I am asserting on the value with the comma; _assertContainsText($new_limit, _cell(59)).
$new_limit takes the 50502.50 amount and adds a comma and currency unit.
Could it be possible that the Sahi controller gives me a different value to the one which is created during the test run?
Sahi controller will give you the the same value as given during the test run.
There is some problem in your addCommas() function. You please try to remove the +100.5 in the function and then try it out it will work.
Regards,
Sachin