Wrong context set when using within

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

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
55/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
冷清
技术栈
javascript, playwright
领域
testing-qa

调研方向

首先跟踪 _getContext 函数和 within 的实现,然后使用 waitForEnabled 运行提供的 modal 示例。检查相关的 waitForDisabled、waitNumberOfVisibleElements、waitForValue 和 waitForText 行为。当 within('.modal-dialog') 使用预期的页面或 frame 上下文,并且这些 helper 能够在代码块内运行而不会出现上下文错误时,即表示完成。

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

描述

stale

Description

After updating to CodeceptJS version 3.6.10 (also occurring in 3.7.0), we noticed that the within functionality no longer works correctly when used with a selector like .modal-dialog. Instead of setting the context to a page or frame object, it sets it to a locator object, which causes an error when trying to execute certain functions.

The error encountered:

context.waitForFunction is not a function

This error occurred in the waitForEnabled function, which expects context to be a page object, but instead it is passed as a locator because of the changes introduced with: #4557
Other helper functions that we found that produce the same error: waitForDisabled, waitNumberOfVisibleElements, waitForValue.
We also observed other functions like waitForText not working correctly inside within (e.g. not finding text inside the within context although it was obviously there).
Specifically this line in the _getContext function breaks this use case, since it now returns this.context even if it is a locator object:

  async _getContext() {
    if ((this.context && this.context.constructor.name === 'FrameLocator') || this.context) {
      return this.context
    }
...

Everything worked fine again after reverting the changes that were introduced by this commit.

Steps to Reproduce

  1. Use the within function with a selector such as .modal-dialog.
  2. Attempt to run a command inside the within block, like waitForEnabled.
  3. Observe the error message.
Example test case:
Feature('Modal Test');

Scenario('Test modal within', async ({ I }) => {
  I.amOnPage('https://example.com'); 
  I.click('.open-modal');
  within('.modal-dialog', async () => {
   I.waitForEnabled('.button')
  });
});

Details

  • CodeceptJS version: 3.6.10 and 3.7.0
  • NodeJS Version: 23.7.0
  • playwright-core version: 1.49.1
主要语言
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 摘要。