xxxxxxxxxx
// enter the test data here
var grossAmount = 121.84
// compute tax
var taxPercent = 0.06 // 6% expressed in decimals
var expectedTaxAmount = grossAmount * taxPercent // compute tax amount
expectedTaxAmount = (expectedTaxAmount).toFixed(2) // round to 2 decimal places
// go to our test web page
I.goTo("https://example.uilicious.com/gst_calculator.html")
// enter the gross amount
I.fill("gross amount", "" + grossAmount)
// grab the value of the tax amount from the webpage
var TAX_AMOUNT_INPUT_FIELD = "#tax-amount"
var actualTaxAmount = I.getValue(TAX_AMOUNT_INPUT_FIELD) // use I.getValue to read the value from an input field and store it to a variable `actualTaxAmount`
// assert the value of the field
TEST.assert(
expectedTaxAmount === actualTaxAmount, // condition that we want to test
`Expect tax to be ${expectedTaxAmount}, got ${actualTaxAmount}.`
)
// TEST.assert is a short-hand for writing the following:
/*
if(expectedTaxAmount === actualTaxAmount){
TEST.log.success(`Expect tax to be ${expectedTaxAmount}, got ${actualTaxAmount}.`)
} else {
TEST.log.fail(`Expect tax to be ${expectedTaxAmount}, got ${actualTaxAmount}.`)
}
*/
Hi, I'm TAMI (Test Authoring Machine Intelligence).
Let me assist you in writing a test. Tell me a scenario to test, and I’ll write the test script for you!