Kindly refer to the below screenshot. I simply want to prove that 'value entered (£2500)' Less 'total estimated adviser payment (£75)' = Total net deposit amount (£2425)
Not sure if this can be achieved via code snippet ? If yes, can someone please advise the code for the same as my coding skills aren't that great.
This depends on how you are referencing or mapping these objects, but a high-level example (assuming you are indeed scripting your tests and not using keyword tests) would be to just create a few variables for all of the object's innerHTML, innerText, contentText or textContent property values. And example would be something like:
// xPath is referencing the 1st row (/tr), with a table header of 'Value Entered' (/th) and cell value that contains '£' (/td)
var deposit = Sys.Browser("*").Page("*").FindElement("//tbody/tr[1]/th[contains(text(), 'Value Entered')]/td[contains(text(), '£')]");
Log.Message("Deposit Amount = " + deposit.contentText);
// will print "Deposit Amount = £2,500" to the log
Again, this depends on how these objects are referenced in your project, but you can object spy the areas of the screenshot you provided to find how TestComplete is finding these objects and show you what properties, values, and methods you can use within your scripts.
An example would be something like the screenshot below, which is using name mapping, but you can see TC is attempting to find the object based on a generic xPath reference to a table cell, or <td> with 'Active' as a value, IE: //td[.='Active']. This wouldn'twork bc there are several rows in the table which have cells containing a value of 'Active', which is why you may need to tweak your xPath or CSS reference similarly to how I did above:
OR add extra property selectors in your NameMapping file to help TC find a unique table cell (if you use name mapping).
Once you know how to find these objects and extract their values as variables in your test, the math/validation is pretty straight-forward. Something like:
// set your object's as variables
var deposit = Sys.Browser("*").Page("*").FindElement("//tbody/tr[1]/th[contains(text(), 'Value Entered')]/td[contains(text(), '£')]");
var payment = Sys.Browser("*").Page("*").FindElement("//tbody/tr[contains(text(), 'Total Estimated Cost of Transactions')]/td[contains(text(), '£')]");
var netAmount = Sys.Browser("*").Page("*").FindElement("//tbody/tr[contains(text(), 'Total Net Deposit Amount')]/td[contains(text(), '£')]");
// log for reference
Log.Message("Deposit Amount = " + deposit.contentText);
Log.Message("Payment Amount = " + payment.contentText);
Log.Message("Net Amount = " + netAmount.contentText);
// remove symbol and convert to Int may be necessary
var depositInt = aqConvert.StrToInt(aqString.Replace(deposit.contentText, "£", ""));
var paymentInt = aqConvert.StrToInt(aqString.Replace(payment.contentText, "£", ""));
var netAmountInt = aqConvert.StrToInt(aqString.Replace(netAmount.contentText, "£", ""));
// verify math is correct - if deposit minus payment does not equal netAmount, throw an error
if (!equal((depositInt - paymentInt), netAmount)) {
Log.Error("ERROR: deposit " + depositInt + " - payment " + paymentInt + " != netAmount " + netAmountInt);
}
else {
Log.Checkpoint("PASS: math is fun");
}
if ((myvalueentered - myadviserpayment) = mytotalnetdeposit) then log.message("test passed") else log.message("test failed")
You can do the calculations in the snippet or you can have the values in variables and calculate on the variables. I would do the variables if I need those values again somewhere else.
Sorry but I am not sure how this is going to work. I want TC to calculate that the on screen value of 'total net deposit' is the direct result of 'value entered' less 'adviser payment' throuh keyword test. I am little confuse how TC will calculate this using If Then statement ?