Writing Assertions is as easy as asking a question

Relicx
Transforming testing with Generative AI
2 min readJul 8, 2024

Relicx simplifies the process of writing assertions. For example, consider the checkout page of the SwagLabs e-commerce app. 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.

Swaglabs Checkout Page

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:

  • “Can you confirm that the sum of the prices of the items in the cart is equal to the item total?

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.

Creating an Natural Language based Assertion

--

--

Relicx
Transforming testing with Generative AI

RelicX enables application to thoroughly test real-world user flows. It ensures confident releases by testing applications as they are used in production.