如何在 codemirror 编辑器中使用 cypress .type() 进行输入?
How to type using cypress .type() inside the codemirror editor?
我正在为 Codemirror 编辑器编写一些 cypress
测试。我已经使用 cypress
在输入字段中输入。
我正在尝试在 CodeMirror 编辑器中实现 cy.type()
。我在 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('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 })
})
})
我正在为 Codemirror 编辑器编写一些 cypress
测试。我已经使用 cypress
在输入字段中输入。
我正在尝试在 CodeMirror 编辑器中实现 cy.type()
。我在 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('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 })
})
})