nightwatch
nightwatch copied to clipboard
element.find() cause memory leak when using custom command inside page specified command
Description of the bug/issue
I'm using custom command inside page specified command, I pass "@searchBar"
page element to custom command argument selector
and in the custom command, I use this.api.element.find(by.css(selector))
. This will cause memory leak. Can git clone the sample repo, and run in local to reproduce. I think I shouldn't use by.css()
to wrap the page element, but at least can throw some errors
Steps to reproduce
git clone https://github.com/Terence625/nightwatch-test.git
Sample test
// googlePage.ts
const googleCommands = {
searchFor: function (this: NightwatchClient, searchTerm: string) {
return this.search("@searchBar", searchTerm);
},
};
module.exports = {
url: "https://google.com",
commands: [googleCommands],
elements: {
searchBar: "textarea[name=q]",
},
};
// search.ts
export default class Search {
async command(this: NightwatchClient, selector: string, searchTerm: string) {
await this.api.element(by.css(selector)).setValue(searchTerm);
}
}
// google.ts
const home: NightwatchTests = {
"Google search test": async() => {
const google = browser.page.googlePage();
await google.searchFor("nightwatch");
},
};
export default home;
Command to run
npx nightwatch nightwatch/google.ts --verbose
### Verbose Output
```fundamental
→ Running command: search ({name, __index, __selector, locateStrategy, pseudoSelector, parent, resolvedElement, abortOnFailure, suppressNotFoundErrors, timeout...}, 'nightwatch')
→ Running command: element.find ()
<--- Last few GCs --->
[981:0x118008000] 62863 ms: Mark-Compact 4044.3 (4130.3) -> 4029.0 (4130.8) MB, 1883.7 / 0.0 ms (average mu = 0.079, current mu = 0.002) allocation failure; scavenge might not succeed
[981:0x118008000] 64710 ms: Mark-Compact 4044.7 (4130.8) -> 4029.5 (4131.6) MB, 1844.5 / 0.0 ms (average mu = 0.042, current mu = 0.002) allocation failure; scavenge might not succeed
<--- JS stacktrace --->
FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
Nightwatch Configuration
No response
Nightwatch.js Version
3.1.0
Node Version
19.9
Browser
No response
Operating System
No response
Additional Information
No response