问题标签 [jest-puppeteer]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
207 浏览

javascript - When is an elementHandle not an elementHandle

In the puppeteer api docs an ElementHandle is defined:

So given an ElementHandle I should be able to do all the basic functions you can do with the page: .click, .$$, .$x, .hover, etc

The same doc defines page.$x(expression)

So I have the following that returns an array of ElementHandles:

I actually get 5 items in the array as expected. So I need to loop through this list and check the ElementHandles for an svg object that has the id='locationChecked'. Then click it if it does. (all but the 4th one has this id currently)

The problem is two fold.

First: When it loops through the 5 ElementHandles in the Array, it always finds/evaluates the 'locationChecked' object, even when on the 4th it is not there.

Second: when it executes the cameraSelectionBox.click(); It always click the first one.

This tells me that it's probably ignoring the scope of the ElementHandle and using the entire page instead. and then executing on the first one it finds for each pass of the array.

What can i do to ensure the scope stays within the ElementHandle being used?

0 投票
1 回答
26 浏览

javascript - 将范围限制为 elementHandles 数组(用于选择/单击/等)

我正在使用 --> arrayOfHandles = await page.$x({SOME XPATH EXPRESSION}); 创建一个 elementHandles 数组进行循环并将循环中的范围限制为每个句柄:但它不起作用!!!!!!

给定以下代码片段:

每次页面加载cameraList都是不同的。有时更多或更少的相机。有时 svg id="marker-icon" 表示没有可用的位置。

我需要收集摄像机列表并仅单击具有位置的摄像机的复选框。这是我所拥有的:

即使它在列表中循环了预期的次数(告诉我它找到并创建了一个相机行数组),它总是只点击列表中的第一个。此外,在没有它的行上应该跳过它,但它没有。在我看来,范围不起作用,它仍在根据“页面”进行检查

0 投票
0 回答
275 浏览

puppeteer - 如何使用 puppetter 在隐身模式下测试应用程序?

当我尝试使用以下代码时,它会以隐身模式启动第二个窗口。

当我尝试下面的代码时,它会启动隐身模式。但以常规 chrome 模式打开 url

0 投票
0 回答
340 浏览

javascript - jest-puppeteer:从窗口访问 IndexedDB

我正在尝试从窗口对象访问 indexedDB,但是我不断收到以下错误。

DOMException: Failed to execute 'open' on 'IDBFactory': access to the Indexed Database API is denied in this context.

这就是我试图做到的方式。

我还设置--allow-file-access-from-files为 args 中的一部分jest-puppeteer.config.js并设置browserContext: 'default'

我仍然无法让它工作!有没有人有同样的问题?

0 投票
1 回答
1007 浏览

javascript - Puppeteer: input field selected by ID returns undefined

enter image description here

Above, you can see the input element with the #account_email selector. But a jest functional test which awaits selection and typing in this field fails every time. I can't understand why.

Is there a syntax error below? Is this type of selection prone to error? Any advice on fixing this is welcome.

0 投票
1 回答
48 浏览

jestjs - Puppeteer:每次访问页面时存储和访问上下文或元数据

我正在尝试使用@xstate/testpuppeteer 和 jest 并结合它来自动生成结果。使用 jest 的beforeAllafterAll挂钩,我正在调用page.setRequestInterception并注册一个回调来拦截网络请求并模拟它们的响应。

XState 生成我想要测试的路径,并且我可以从每条路径中确定测试是否想要测试 API 失败或成功时应该发生的情况。我被困在如何正确地将其传达给 puppeteer 并在我的请求处理程序中访问该信息。

0 投票
1 回答
581 浏览

visual-studio-code - Jest Puppeteer - 为其设置 Visual Studio 代码

我打算设置 env 以在 Visual Studio Code IDE 中进行测试。我遇到的问题是任何 XXX.test.js 文件中的 VS Code 都不知道什么是browser变量page。我收到这样的错误:

这是否仅与我正在使用的 IDE 有关?这个IDE的一些插件?或者也许这是正常的jest-puppeteer,我需要习惯它?

运行时的整个测试工作正常,但似乎 IDE 只知道什么是page.

我现在正在研究这个简单的例子,我只是在学习这个,但我正在尝试同时为它设置 env。我的Network.test.js文件看起来像这样。文件顶部根本没有导入或需要。

稍后我需要将其切换到 Typescript,我认为这也是一个挑战。现在我只想专注于纯 javascript 方法。

如何摆脱这个实际上不是错误的IDE错误?

0 投票
1 回答
1018 浏览

testing - Jest + puppeteer 最佳架构实践

我刚刚进入了使用 puppeteer 和 jest 进行测试的世界,我想知道在文件夹架构和逻辑方面的最佳实践是什么。

我以前从未做过测试,我想我对不同的原则和概念以及它们如何组合在一起有点迷失了。

我学会了基于页面对象模型进行测试,所以我的每个页面都有类,而且我的每个模块(或组件)也有类。例如,在我的应用程序中,标题或登录模式是组件。

然后我每页或每个组件都有一个测试文件。(例如landingPage.tests.js文件,它使用文件中的 LandingPage 类的模型LandingPage.js

这是一个具体的例子:我有不同的登录案例,我想测试它们。例如,我想测试与“普通”用户连接,该过程只是登录然后密码。然后我需要与已激活 2FA 的用户或使用 SSO 的公司的用户一起进行测试。

我首先考虑将我的不同测试放在authentication.tests.js不同的describe块中,认为它每次都会打开一个新选项卡,但它不会......我在隐身模式下使用 puppeteer 以确保每个选项卡都是一个独立的会话。


所以我的问题是:

  • 做这些测试套件的最佳地点在哪里?

  • 我是否应该有“描述”页面的测试文件(例如,按钮必须存在,这样的文本必须在此处等)并且还有“场景类型”测试文件(对用户的一组上下文操作,例如对于我不同的登录案例)?

这是authentication.tests.js,我想在其中测试我所有不同的登录方式:

谢谢,如果这听起来令人困惑,我很抱歉,就像我说的那样,我正试图弄清楚这一切是如何结合在一起的。

0 投票
0 回答
148 浏览

jestjs - puppeteer page.goto api 无法加载 URL

我正在我当前的项目中设置集成测试工作流程。为此,我正在使用 jest-puppeteer 并在 typescript 中编写测试用例。但await page.goto(url, {waitUntil:'networkidle2'})无法加载任何 URL。我已经重现了这个问题,请参考这个包https://github.com/Dip686/jest-puppeteer-ts

在此处输入图像描述

0 投票
1 回答
163 浏览

javascript - xpath-puppeteer- 无法点击元素

我正在尝试在 puppeteer 上使用 xpath 单击元素。它实际上并没有抛出任何错误,只是木偶师不会点击元素。我不知道我的代码是否有问题。我将展示我试图点击的元素以及我制作的 2 个解决方案。任何帮助将不胜感激。

这是我试图点击的元素。

第一个解决方案

第二种解决方案