【发布时间】:2021-12-05 23:54:41
【问题描述】:
我正在使用 Cypress 在 React 中编写一些 e2e 测试。我让它在我的本地开发环境中正常工作,但是当测试在 GitHub Action 管道中运行时它失败了。
我认为这是因为我正在尝试访问影子 Dom 元素,并且在运行操作时由于某种原因无法正常工作。
这是我的测试:
it('Should be able to click add to list button',
{ includeShadowDom: true },
() => {
cy.get('.IPEX_HSD_product_sheet_add_to_bag')
.shadow()
.find('kompis-icon-button', { includeShadowDom: true })
.shadow()
.find('button')
.click();
}
);
这是我的柏树配置:
{
"baseUrl": "http://127.0.0.1:3000/#/",
"includeShadowDom": true,
"defaultCommandTimeout": 10000,
"fixturesFolder": false,
"integrationFolder": "./test/e2e",
"pluginsFile": false,
"supportFile": "./test/cypress.support.ts",
"testFiles": "**/*.test.ts",
"video": false
}
这些是我的 package.json 中的脚本:
"cypress:open": "cypress open --config-file ./test/cypress.config.json",
"test:e2e": "cypress run --headed --config-file ./test/cypress.config.json",
"test:e2e:ci": "start-server-and-test serve http://localhost:3000 test:e2e"
这是来自我的 workflow.yml:
- name: Install dependencies and cache them. Run E2E tests against production build ????
uses: cypress-io/github-action@v2
with:
build: npm run build
start: npm start
command: npm run test:e2e:ci
cache-key: node-modules-${{ hashFiles('package-lock.json') }}
如您所见,我已尽可能添加 includeShadowDom: true ,但似乎没有效果。
我得到的错误是:
AssertionError: Timed out retrying after 10000ms: Expected to find element: `kompis-icon-button`, but never found it. Queried from element: <kompis-add-to-bag.IPEX_HSD_product_sheet_add_to_bag>
这是源 HTML:
【问题讨论】:
-
可以添加元素的html吗?
-
@AlapanDas 是的,我已经添加了。
标签: reactjs cypress github-actions