Score:1

How to write in a ckdeditor textarea with Cypress?

br flag

i'm trying to create a new node in Drupal 9. But all my attempts so far have failed when it comes to writing the body text. The body text is a Ckeditor5 field. I can't write there with Cypress.

I tried the following line with the following error: "Cannot read properties of undefined (reading 'instances')"

  cy.window().then(win => {win.CKEDITOR.instances["html_body"].setData("<p>HTML body</p>");});

After several attempts, i tried the jQuery way, so far this solution wont raise any error, but the textarea remains in blank without any text:

cy.get('.ck-editor__editable').then($editable => {$editable.focus().html('<p>HTML body</p>');});

how can i set text into this field with Cypress?

leandro713 avatar
br flag
I have searched on the internet for the issue and everyone says that ckeditor uses an iframe, but I cannot find any iframe anywhere. :-(
leymannx avatar
ne flag
Never heard of Cypress
Kevin avatar
in flag
You probably have to wait for the page to be ready, its possible the actual editor hasn't finished loading yet.
apaderno avatar
us flag
Isn't [Cypress](https://www.cypress.io/) a JavaScript component testing framework? Are you testing the node creation form?
leandro713 avatar
br flag
yessir to both questions
cn flag
Pretty sure I remember reading cke5 doesn't use iframes any more
Score:1
cn flag

Drupal keeps a list of the active CKEditor 5 instances in JS, you can get them from there. For example to fill all the editors on the page:

cy.window().then(win => {
  win.Drupal.CKEditor5Instances.forEach(editor => editor.setData('<p>Test</p>'))
})
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.