Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Inconsistent assert behavior for text

未关闭
#5,278 2 条评论 1 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
35/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
停滞
领域
testing-qa

调研方向

先使用 examples/returns.html 和 examples/bootstrap.html 运行提供的场景,然后将 I.see、I.waitForText 和 I.grabTextFrom 与 #app 和 #app.at(1) 进行比较。跟踪每个 assertion 从何处获取文本,以及如何对其进行规范化。当这些方法、选择器、空白和样式场景中的预期文本行为都已定义且保持一致时,即视为完成。

由索引模型根据 Issue 内容生成。

描述

stale

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
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, `
  <div id="app">
    <span>1</span>
    <span>2</span>
    <span>3</span>
  </div>
  `);
  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, `
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css">
<div class="d-flex align-items-baseline lh-1 monospace-numbers" id="app"><span class="text-nowrap fs-21 lh-1">0</span><span class="text-nowrap fs-21 lh-1">.</span><span class="text-nowrap fs-21 lh-1">8</span><span class="text-nowrap fs-21 lh-1">8</span><span class="text-nowrap fs-48 lh-1">6</span><span class="text-nowrap fs-48 lh-1">7</span><span class="text-nowrap fs-18 lh-1 align-self-start mt-1">8</span></div>
  `);
  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");
});

主要语言
JavaScript
星标
4.2k
派生
756
平均合并
2 天 9 小时
30 天内合并 PR
16

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

codeceptjs/CodeceptJS 的其他 Issue

查看 codeceptjs/CodeceptJS 的全部 Issue

相似的 Issue

更多 JavaScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。