Comments (9)
@deepankarn Does the beforeInitialPageLoad
callback work for your use case? It seems that you can do the login actions before the initial page load.
from memlab.
I am getting an error, "interaction failed" when I use "beforeInnitialPageLoad". In my website I have to do the initial page load. When I do the initial page load, the website redirects to ADFS for entering the username & password. Once the user enters the username & password, the website redirects it to the actual landing page. Hope that helps.
from memlab.
@deepankarn Consider using the following scenario template.
let theUrlAfterLogin;
async function beforeInitialPageLoad(page) {
await page.goto(loginUrl);
// input login credentials and get the url after login is successful
theUrlAfterLogin = ...
}
function url() {
return theUrlAfterLogin;
}
// action where we want to detect memory leaks
async function action(page) {
}
// action where we want to go back to the step before
async function back(page) {
}
module.exports = {beforeInitialPageLoad, action, back, url};
If it doesn't work, please share your test scenario code (without the actual url and credentials) so that we can try to debug it
from memlab.
code in scenario.js file
let theUrlAfterLogin;
async function beforeInitialPageLoad(page) {
await page.goto("https://XYZ");
// input login credentials and get the url after login is successful
await page.waitForSelector('input[id=userNameInput]');
await page.$eval('#userNameInput', el => el.value = 'tw\schuser1');
await page.waitForSelector('input[id=passwordInput]');
await page.$eval('#passwordInput', el => el.value = 'xxxxx');
await page.click('[id="submitButton"]');
theUrlAfterLogin = "https://XYZ"
}
function url() {
return theUrlAfterLogin;
}
// action where we want to detect memory leaks
async function action(page) {
}
// action where we want to go back to the step before
async function back(page) {
}
module.exports = {beforeInitialPageLoad, action, back, url};
OUTPUT FROM MEMLAB
C:\Users\dneogi>memlab run --scenario C:\Users\dneogi\AppData\Local\Temp\memlab\scenario.js
'command' is not recognized as an internal or external command,
operable program or batch file.
Cannot read property 'startsWith' of undefined
total time: 905ms
snapshot meta data invalid or missing
Use memlab help
or memlab <COMMAND> -h
to get helper text
from memlab.
@deepankarn I apologize for the issue in the template I provided earlier. Unfortunately, memlab does not currently support using a dynamically generated url after evaluating beforeInitialPageLoad. However, since your use case involves a url that is always the same, you can try using this revised code template:
async function beforeInitialPageLoad(page) {
await page.goto("https://xyz/");
// input login credentials and get the url after login is successful
await page.waitForSelector('input[id=userNameInput]');
await page.$eval('#userNameInput', el => el.value = 'tw\schuser1');
await page.waitForSelector('input[id=passwordInput]');
await page.$eval('#passwordInput', el => el.value = 'xxxxx');
await page.click('[id="submitButton"]');
}
function url() {
return "https://xyz/";
}
// action where we want to detect memory leaks
async function action(page) {
}
// action where we want to go back to the step before
async function back(page) {
}
module.exports = {beforeInitialPageLoad, action, back, url};
from memlab.
Thank you Jackson, I was able to run the modified code but was not able to login to my website. The snapshots that was captured by the MemLab tool did not show that the login credentials were sent to the website.
async function beforeInitialPageLoad(page) {
await page.goto("https://XYZ/");
// input login credentials and get the url after login is successful
await page.waitForSelector('input[id=userNameInput]');
await page.$eval('#userNameInput', el => el.value = 'tw\schuser1');
await page.waitForSelector('input[id=passwordInput]');
await page.$eval('#passwordInput', el => el.value = 'XXXXX');
await page.click('[id="submitButton"]');
}
function url() {
return "https://XYZ/";
}
// action where we want to detect memory leaks
async function action(page) {
}
// action where we want to go back to the step before
async function back(page) {
}
module.exports = {beforeInitialPageLoad, action, back, url};
from memlab.
@deepankarn It seems that the login process in the beforeInitialPageLoad
callback did not complete successfully. If you are running memlab, you can try adding the --debug --headful
flags to pause after the url
callback and view the page in Chromium. This may help you troubleshoot the issue.
from memlab.
I was finally able to make the code work but got the below error -
============================ CODE =====================================
async function isPageLoaded(page) {
await page.goto("https://twr1dweb4.rd.allscripts.com/TWClient/");
// input login credentials and get the url after login is successful
await page.waitForSelector('input[id=userNameInput]');
await page.$eval('#userNameInput', el => el.value = 'tw\schuser1');
await page.waitForSelector('input[id=passwordInput]');
await page.$eval('#passwordInput', el => el.value = 'xxxxxx');
await page.click('[id="submitButton"]');
return true;
}
function url() {
return "https://twr1dweb4.rd.allscripts.com/TWClient/";
}
// action where we want to detect memory leaks
async function action(page) {
}
// action where we want to go back to the step before
async function back(page) {
}
module.exports = {isPageLoaded, action, back, url};
======================== ERROR ===================================
C:\Users\dneogi>memlab run --scenario C:\Users\dneogi\AppData\Local\Temp\memlab\scenario.js --debug --headful
'command' is not recognized as an internal or external command,
operable program or batch file.
page-load(baseline)[s1] > action-on-page(target)[s2] > revert(final)[s3]
Press Enter (or Return) to continue step-2:
(node:11932) UnhandledPromiseRejectionWarning: Error: Cannot accept dialog which is already handled!
at assert (C:\Users\dneogi\AppData\Roaming\npm\node_modules\memlab\node_modules\puppeteer\lib\cjs\puppeteer\common\assert.js:26:15)
at Dialog.accept (C:\Users\dneogi\AppData\Roaming\npm\node_modules\memlab\node_modules\puppeteer\lib\cjs\puppeteer\common\Dialog.js:79:32)
at BrowserInfo. (C:\Users\dneogi\AppData\Roaming\npm\node_modules\memlab\node_modules@memlab\core\dist\lib\BrowserInfo.js:113:26)
at Generator.next ()
at C:\Users\dneogi\AppData\Roaming\npm\node_modules\memlab\node_modules@memlab\core\dist\lib\BrowserInfo.js:17:71
at new Promise ()
at __awaiter (C:\Users\dneogi\AppData\Roaming\npm\node_modules\memlab\node_modules@memlab\core\dist\lib\BrowserInfo.js:13:12)
at C:\Users\dneogi\AppData\Roaming\npm\node_modules\memlab\node_modules@memlab\core\dist\lib\BrowserInfo.js:106:39
at C:\Users\dneogi\AppData\Roaming\npm\node_modules\memlab\node_modules\puppeteer\lib\cjs\vendor\mitt\src\index.js:51:62
at Array.map ()
(Use node --trace-warnings ...
to show where the warning was created)
(node:11932) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict
(see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 3)
(node:11932) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
(node:11932) UnhandledPromiseRejectionWarning: Error: Cannot accept dialog which is already handled!
at assert (C:\Users\dneogi\AppData\Roaming\npm\node_modules\memlab\node_modules\puppeteer\lib\cjs\puppeteer\common\assert.js:26:15)
at Dialog.accept (C:\Users\dneogi\AppData\Roaming\npm\node_modules\memlab\node_modules\puppeteer\lib\cjs\puppeteer\common\Dialog.js:79:32)
at C:\Users\dneogi\AppData\Roaming\npm\node_modules\memlab\node_modules@memlab\api\dist\API.js:262:26
at Generator.next ()
at C:\Users\dneogi\AppData\Roaming\npm\node_modules\memlab\node_modules@memlab\api\dist\API.js:17:71
at new Promise ()
at __awaiter (C:\Users\dneogi\AppData\Roaming\npm\node_modules\memlab\node_modules@memlab\api\dist\API.js:13:12)
at C:\Users\dneogi\AppData\Roaming\npm\node_modules\memlab\node_modules@memlab\api\dist\API.js:261:39
at C:\Users\dneogi\AppData\Roaming\npm\node_modules\memlab\node_modules\puppeteer\lib\cjs\vendor\mitt\src\index.js:51:62
at Array.map ()
(node:11932) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict
(see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 4)
The page is reloaded. MemLab cannot analyze heap across page reloads. Please remove window.reload() calls, page.goto() calls, or any reload logic.
Use memlab help
or memlab <COMMAND> -h
to get helper text
from memlab.
@deepankarn It appears that your website has a pop-up dialog that is causing issues with Puppeteer when memlab tries to automatically accept it. I am unable to access the website you are testing, but one solution you could try is commenting out or adding a try-catch block around this line of code and using the local build of memlab.
Note: isPageLoaded
is called every time after url
, action
, and back
are invoked. I would recommend using beforeInitialPageLoad
to log in to the website.
from memlab.
Related Issues (20)
- Can't switch chrome version HOT 2
- Idea - Question - Discussion - Using memlab to refactor code targeting different framework philosphy HOT 1
- Question - How does it pull memory information ? HOT 1
- 老哥有点问题,本地默认安装你的仓库里面有个依赖包引入 colors 的包默认是1.4.2的 被污染的那个包 导致 启动不起来,windows 开发环境, HOT 2
- Question: Any idea about ignoring weak reference and circular reference in heap snapshot? HOT 7
- takeHeapSnapshot timed out HOT 10
- core_1.browserInfo.setPuppeteerConfig is not a function HOT 2
- Is there a way to run in scripting mode using silent? HOT 4
- Could not find Chrome (ver. 121.0.6167.85). This can occur if either 1. you did not perform an installation before running the script (e.g. `npx puppeteer browsers install chrome`) or 2. your cache path is incorrectly configured HOT 3
- Could not find Chrome (ver. 121.0.6167.85). This can occur if either 1. you did not perform an installation before running the script (e.g. `npx puppeteer browsers install chrome`) or 2. your cache path is incorrectly configured
- Keep `@memlab/*` versions in lockstep in package.json HOT 1
- how to handle Page crashed error ,when execute the run method。 HOT 1
- how to get leak info from memlab console HOT 6
- Clarify the documentation about measure mode HOT 3
- Using a basic `retainerReferenceFilter` causes Node OOM exception HOT 7
- Add ESM support for @memlab/api (and remaining) HOT 4
- Puppeteer browser.close() hangs on AWS Lambda HOT 2
- TypeError: core_1.utils.tryToMutePuppeteerWarning is not a function HOT 2
- Error occurs when executing scenarios involving dialog display HOT 1
- Need guidance on accessing elements in code using heap object ID HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from memlab.