Rah*_*wal 7 codemirror firepad cypress
我正在cypress为 Codemirror Editor编写一些测试。我已经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>
Run Code Online (Sandbox Code Playgroud)
cypress 规范代码 cy.get('pre.CodeMirror-line') .type('Cypress HTML Data')
我无法使用 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 })
})
})
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1259 次 |
| 最近记录: |