Writing Assertions is as easy as asking a question
Relicx simplifies the process of writing assertions. For example, consider the checkout page of the SwagLabs e-commerce app (https://www.saucedemo.com/v1/checkout-step-two.html). In this scenario, a user has added three items to their cart and needs to assert that the sum of the individual item prices equals the total item price.
Using a scripting tool like Cypress, the user can write a few lines of code (as shown below) to define this assertion.
describe('Cart Total Verification', () => {
it('should verify that the sum of item prices equals the item total', () => {
cy.visit('https://www.saucedemo.com/v1/checkout-step-two.html');
// Retrieve the prices of individual items
let itemPrices = [];
cy.get('#checkout_summary_container > div > div.cart_list > div:nth-child(3) > div.cart_item_label > div.inventory_item_price').each(($el) => {
const priceText = $el.text().replace('$', '');
const price = parseFloat(priceText);
itemPrices.push(price);
});
// Calculate the sum of item prices
let sumOfPrices = 0;
cy.wrap(itemPrices).each((price) => {
sumOfPrices += price;
});
// Retrieve the item total
cy.get('#checkout_summary_container > div > div.summary_info > div.summary_subtotal_label').invoke('text').then((itemTotalText) => {
const itemTotal = parseFloat(itemTotalText.replace('Item total: $', ''));
// Assert the sum of prices equals the item total
expect(sumOfPrices).to.eq(itemTotal);
});
});
});
领英推荐
In Relicx, this process is incredibly simple. You can just ask the Relicx Copilot to verify the question as follows:
That's it—no coding required. The Relicx Copilot automatically generates the code and verifies the total for you in just a few seconds. In the video below, you can see how the assertion is created and executed in Relicx.