我正在为Codemirror编辑器编写一些cypress
测试。我使用cypress
输入输入字段。
我试图在CodeMirror编辑器中实现cy.type()
。我在codemirror中拥有的数据位于span中。
<pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> < h1 > Welcome to your web project canvas! < /h1></span></pre>
柏树规范代码cy.get('pre.CodeMirror-line')。type('赛普拉斯HTML数据')
我无法使用cypress键入一些数据。
如果有人可以帮忙,我将不胜感激?
您没有在规范代码中定位正确的元素。你正在做cy.get('pre.CodeMirror-line')
,但<pre>
标签不是一个cy.type()
-able元素。
您需要获取隐藏的CodeMirror <textarea>
。这可以使用.CodeMirror textarea
选择。以下JS是适用于codemirror.net
的演示规范:
describe('Codemirror', () => {
it('can be tested using textarea', () => {
cy.visit('https://codemirror.net/')
// CodeMirror's editor doesn't let us clear it from the
// textarea, but we can read the Window object and then
// invoke `setValue` on the editor global
cy.window().then(win => {
win.editor.setValue("")
})
cy.get('.CodeMirror textarea')
// we use `force: true` below because the textarea is hidden
// and by default Cypress won't interact with hidden elements
.type('test test test test', { force: true })
})
})