I create a new project, i have npm: '9.8.1',node: '18.18.0. I followed the quickstart. I tried running the example:
describe('Google', () => {
beforeAll(async () => {
await page.goto('https://google.com');
});
it('should be titled "Google"', async () => {
await expect(page.title()).resolves.toMatch('Google');
});
});
the test passed but puppeteer opens a lot of browsers.
while in my test:
Tests.js
const Puppeteer = require("puppeteer");
const fs = require('fs');
beforeAll(async () => {
const path = process.env.VAR_ENV;
const jsonFilePath = path;
const jsonData = fs.readFileSync(jsonFilePath, 'utf-8');
const dati = JSON.parse(jsonData);
await page.goto(dati.URL)
const coockie_button = 'button[class="amecp_button-accetto iubenda-cs-accept-btn"]';
const searchSelector = 'input[id="gz-header-search-input"]';
await page.waitForSelector(coockie_button);
await page.click(coockie_button, { clickCount: 1 });
await page.waitForSelector(searchSelector);
await page.click(searchSelector, { clickCount: 1 });
await page.type(searchSelector, dati.Recipe);
await page.keyboard.press("Enter");
});
it("Given 'Hello World!', return 'Hello World!'", async () => {
expect('hello').toBe('hello');
});
The test failed and gives me this error: ReferenceError: page is not defined. So I don't know what the problem is.
I tried a lot of things also to reinstall all modules but nothing. This is my json file for configuration:
package.json
"name": "jest-puppeteer-test",
"version": "1.0.0",
"description": "",
"main": "index.js",
"type": "module",
"scripts": {
"test": "jest",
"test_p": "cross-env VAR_ENV=C:/src/Prova/config/Test_config.json jest Test",
"produzione": "cross-env VAR_ENV=C:/src/Prova/config/Produzione_config.json jest Test"
},
"author": "",
"license": "ISC",
"devDependencies": {
"jest": "^29.7.0",
"jest-puppeteer": "^9.0.0",
"puppeteer": "^21.3.5"
},
"dependencies": {
"es6": "^0.0.7",
"expect-puppeteer": "^9.0.0",
"jest-environment-puppeteer": "^9.0.0"
}
}
jest-puppeteer.config.js
module.exports = {
launch: {
headless: false
},
browserContext: 'default'
}
jest.config.js
module.exports = {
preset: "jest-puppeteer",
verbose: true
};