如何在codemirror编辑器中使用cypress .type()进行输入?

问题描述 投票:2回答:1

我正在为Codemirror编辑器编写一些cypress测试。我使用cypress输入输入字段。

我试图在CodeMirror编辑器中实现cy.type()。我在codemirror中拥有的数据位于span中。

<pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &lt; h1 &gt; Welcome to your web project canvas! &lt; /h1&gt;</span></pre> 

柏树规范代码cy.get('pre.CodeMirror-line')。type('赛普拉斯HTML数据')

我无法使用cypress键入一些数据。

如果有人可以帮忙,我将不胜感激?

codemirror cypress firepad
1个回答
2
投票

您没有在规范代码中定位正确的元素。你正在做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 })
  })
})
© www.soinside.com 2019 - 2024. All rights reserved.