codeceptjs / codeceptjs/CodeceptJS

Inconsistent assert behavior for text

オープン
#5,278 コメント 2 件 リアクション 1 件 担当者 0 名 GitHub で見る
stale
主要言語
JavaScript
スター
4.2k
フォーク
757
平均マージ
2日 9時間
マージ済み PR(30日)
16

説明

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");
});

```

コントリビューションガイド

コントリビューションガイドを開く

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。