codeceptjs / codeceptjs/CodeceptJS

Inconsistent assert behavior for text

Đang mở
#5,278 2 bình luận 1 reaction 0 người được giao Xem trên GitHub
stale
Ngôn ngữ chính
JavaScript
Star
4.2k
Fork
757
Merge trung bình
2 ngày 9 giờ
Pull request đã merge (30 ngày)
16

Mô tả

Hello!

While experimenting with codecept I noticed inconsistent behaviors between the testing methods.

Here are two tests:
- The first contains spans that have numbers in them. The asserts are generally consistent (they add spaces to each span) except grabTextFrom, which adds \n.
- The second is much more problematic. In this one, the HTML also contains spans, but with bootstrap styles on the spans. We can see that:
- I.see adds spaces
- I.waitForText does not
- nor does I.grabTextFrom
- BUT when we add .at(1) to the locator, it changes the behavior of waitForText().

The way the text is asserted changes depending on:
- the CSS of the page
- the assertion method used
- the selector
- the whitespaces in the HTML

```ts
import { writeFileSync } from "node:fs";
import { resolve } from "node:path";

Feature("Spans");

Scenario("text line returns", async ({ I }) => {
const file = `${resolve(process.cwd(), "examples", "returns.html")}`;
writeFileSync(file, `


1
2
3

`);
I.amOnPage(`file://${file}`);

const appLocator = locate("#app");

I.see("1 2 3", appLocator);
I.waitForText("1 2 3", 1, appLocator);

const text = await I.grabTextFrom(appLocator);
I.expect(text).toEqual("\n 1\n 2\n 3\n ");

I.see("1 2 3", appLocator.at(1));
I.waitForText("1 2 3", 1, appLocator.at(1));

const text2 = await I.grabTextFrom(appLocator.at(1));
I.expect(text2).toEqual("\n 1\n 2\n 3\n ");
});

Scenario("test boostrap styles", async ({ I }) => {
const file = `${resolve(process.cwd(), "examples", "bootstrap.html")}`;
writeFileSync(file, `

0.88678

`);
I.amOnPage(`file://${file}`);

const appLocator = locate("#app");

I.see("0 . 8 8 6 7 8", appLocator);
I.waitForText("0.88678", 1, appLocator);

const text = await I.grabTextFrom(appLocator);
I.expect(text).toEqual("0.88678");

I.see("0 . 8 8 6 7 8", appLocator.at(1));
// IDK what it expects... it just does not work the same with .at(1)!!!!
// I.waitForText("0.88678", 1, appLocator.at(1));

const text2 = await I.grabTextFrom(appLocator.at(1));
I.expect(text2).toEqual("0.88678");
});

```

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.