我正在写一些cypress
测试 Codemirror 编辑器。我有用cypress
在输入字段中键入。
我正在努力实现cy.type()
在 CodeMirror 编辑器中。我在 codemirror 中的数据位于范围内。
<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')
, but a <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 })
})
})
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)