Here is a test that looks fine and proves almost nothing:
await driver.findElement(By.css('[data-testid="add-to-cart"]')).click();
const badge = await driver.findElement(By.css('[data-testid="cart-count"]'));
assert.ok(await badge.isDisplayed());
You add a product. You check the cart badge is displayed. It passes.
Now imagine a developer breaks the cart counter, and the badge always shows 0. Is the badge still displayed? Yes. Does this test still pass? Yes.
So this test tells you the badge exists. Nobody was worried about that.
Check the value your customer actually depends on:
const badge = await driver.wait(
until.elementLocated(By.css('[data-testid="cart-count"]')),
5000
);
assert.strictEqual(await badge.getText(), '1');
getText() reads what the element shows. assert.strictEqual compares it to what you expect. Now a broken counter fails the test immediately.
Remember that Selenium has no assertions of its own. It drives the browser, and a separate library like Node's assert does the checking. So nothing forces you to check anything. That freedom is why weak tests are so common in Selenium projects.
There is a second habit worth building right away. One action usually has more than one effect.
Adding a product promises two things: the badge goes to 1, and a confirmation message appears. Either can break on its own, so check both.
Remember this: for every action, ask what the user is promised, then check each promise.
Reference: Waits.