codeceptjs / codeceptjs/CodeceptJS

Wrong context set when using within

未關閉
#4,840 1 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視
stale
主要語言
JavaScript
星號
4.2k
分支
757
平均合併
2 天 9 小時
30 天內合併 PR
16

描述

## 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:
```plaintext
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:

```javascript
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:
```javascript
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

貢獻指南

開啟貢獻指南

評估

這個 Issue 還沒有評估資料。

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。