這是我寫的測試,我的問題是,我試圖盡可能健壯地構建它,但它有時會工作,有時會由于如下所示的原因而失敗。也許我遺漏了一些東西,如果你們中的任何一個能幫助我使測試更健壯,我將不勝感激。注意:我從代碼中刪除了敏感信息。const { getStatement, portalLogin, getDeletableList } = require("./helper.js");const user = { userName: "*****@*****.de", passWord: "*******" };const puppeteer = require("puppeteer");const headlessVal = false;const webSiteUrlLogin = "https://... .de/dashboard";const webSiteUrlMe = "https://... .de/me";// elements with classesconst change_username_button = ".change-username-button";const save_user_changes_btn = ".save-user-changes-btn";// elements with ID'sconst user_personal_title = "#user_personal_title";// [happy path] 1 user changes #user_personal_titletest("[happy path] 1 user changes #user_personal_title", async () => { //////// SETUP & LOGIN START ///////// const browser = await puppeteer.launch({ headless: headlessVal, args: ["--window-size=1920,1080"], defaultViewport: null, }); // new browser window opens const page = await browser.newPage(); // open specified url and waits for it to be loaded await page.goto(webSiteUrlLogin, { //wait until there are no more conections that traffic waitUntil: "networkidle0", }); await page.waitForNavigation({ waitUntil: "networkidle2", }); const user_local = { userName: user.userName !== undefined ? user.userName : process.env.USERNAME, passWord: user.passWord !== undefined ? user.passWord : process.env.PASSWORD, };失敗:Evaluation failed: TypeError: Cannot set property 'value' of null at __puppeteer_evaluation_script__:2:55 at ExecutionContext._evaluateInternal (node_modules/puppeteer/lib/cjs/puppeteer/common/ExecutionContext.js:217:19) at ExecutionContext.evaluate (node_modules/puppeteer/lib/cjs/puppeteer/common/ExecutionContext.js:106:16) at Object.<anonymous> (joyce_PORTAL/end-to-end/me.test.js:168:3)
如何用 puppeteer 和 jest 編寫健壯的測試?
蝴蝶不菲
2023-06-09 17:22:45