javascript组合具有到cypress的链接功能
我正在尝试使用cypress设置测试,并希望与我的自定义助手函数链接javascript组合具有到cypress的链接功能,javascript,cypress,Javascript,Cypress,我正在尝试使用cypress设置测试,并希望与我的自定义助手函数链接 const Utils = (props) => { const state = { cy: props.cy || { get: () => {} }, } const getByTestId = ((cy, dataTestId) => cy.get([data-test-id=${dataTestId}])).bind(null, state.cy) return {
const Utils = (props) => {
const state = { cy: props.cy || { get: () => {} }, }
const getByTestId = ((cy, dataTestId) => cy.get([data-test-id=${dataTestId}])).bind(null, state.cy)
return { getByTestId, }
}
我有这样的测试包装
const AutoCompleteWrapper = (cy) => {
const utils = Utils({ cy }) const { getByTestId } = utils
const autoCompleteContainerElem = () => getByTestId('autoComplete')
const autoCompleteInputElem = () => autoCompleteContainerElem().find('input')
const selectResults = () => getByTestId('autoCompleteResult')
return { autoCompleteInputElem, selectResults, }
}
使用上述设置。为了获得嵌套的数据测试id元素,我需要再次使用getByTestId包装父元素
有没有建议将自定义函数设置为可链接的
getByTestId('autoComplete')。getByTestId('childTestId')我很好奇,你想解决什么问题?这似乎比需要的复杂得多。Cypress提供了向
support/commands.js
添加自定义命令的选项。例如,您可以做的事情如下:js Cypress.Commands.add('autoCompleteInput',function(element){cy.get(`[data test id=${element}]`)。find('input')})
,但由于我不知道您试图做什么,所以无法帮助您完成实际测试文件中的下一步。它看起来是这样的:js cy.autoCompleteInput('autoComplete')//您要执行的操作
@Mr.J。我想我没有做足够的研究。我不懂指挥。这似乎解决了我的一些问题。