https://github.com/dziamid/cypress-draftjs
describe('React RTE', function(){
it('i cannot simply type', function () {
cy
.visit('https://react-rte.org/demo')
.get('[contenteditable]').eq(0).type('I am typing')
.get('textarea').eq(0).contains('I am typing')
});
})
We'll take a look but we have a ton of cy.type
improvements coming in 0.20.0
which are already done. This has likely already been fixed but we'll double check today.
Can confirm, is a bug, still happens in 0.20.0
looks like issue still occurs
@dziamid Did you sort it out somehow?
I can type in draft.js component, but no events are triggered, so the text is not being persisten by the app. Tried also triggering manually the events, no luck
This is still happening in cypress 1.4.1. This is the major blocker for us adopting cypress, as our app relies heavily on draft-js
Same here, it's happening for us as well, and also a major blocker for using Cypress unfortunately. I'd love to be able to help out somehow here, is there anything we can do to help? Open to anything really, we currently just need a way to input simple text and a few key strokes like enter etc.
Fixing this would likely entail knowing the implementation of draft.js, what events they are expecting, seeing what and when events are triggered natively when typing into draft.js and comparing that to our type implementation to see what events we are not triggering or not triggering correctly.
Draft.js code: https://github.com/facebook/draft-js
Our cy.type()
code: https://github.com/cypress-io/cypress/blob/develop/packages/driver/src/cy/commands/actions/type.coffee
Also, native events will be helpful when that is out: #311
In case this information is of use to you: webdriver/selenium-based testing frameworks do not have this problem. webdriverio's setValue
works as expected
I may not understand the type()
code correctly, but could this line be to blame? Since draftjs uses contenteditable
https://github.com/cypress-io/cypress/blob/99302267dfd37cf6e8ff69b7b2542a89c9203abf/packages/driver/src/cy/commands/actions/type.coffee#L292
@WickyNilliams No, that code basically means that Cypress does not emit a change
or submit
event during typing or when pressing 'enter' on contenteditable
DOM. Those are indeed not fired when typing or pressing enter
when manually typing into draft.js (I am using their demo as reference).
I managed to get typing working by dropping down to using DOM directly. Our RichTextEditor
component fires changes on blur (only internal state is updated on change), so we needed to focus, then type, then blur the editor. Here is the code. Hope it helps someone:
export const typeIntoDraftEditor = (selector, text) => {
cy.get(selector).then(input => {
var textarea = input.get(0);
textarea.dispatchEvent(new Event("focus"));
var textEvent = document.createEvent("TextEvent");
textEvent.initTextEvent("textInput", true, true, null, text);
textarea.dispatchEvent(textEvent);
textarea.dispatchEvent(new Event("blur"));
});
};
@WickyNilliams thanks for the function! Any chance you could provide an example call please, I'm struggling to determine what selector to use. Thanks!
@dolyst sure!
Draft's Editor
component can accept a webDriverTestID
prop. This is output as a data-testid
attribute.
So, assuming an editor like:
<Editor webDriverTestID="foo" />
Then the following would work with my function above:
typeIntoDraftEditor(`[data-testid="foo"]`, "hello world")
Hope that helps :)
@WickyNilliams. Thanks very much!
@jennifer-shehane any progress?
No, we are not currently working on this. We welcome pull requests though, even if they are 'work in progress'!
Having the same issue. Many people are complaining about it. Is there any fix for that?
This issue will be fixed in upcoming patch release, along with many other cy.type improvements mentioned in #1241
Having same issue or at least a similar issue as to others here.
I am able to get Cypress to type in the JS Draft Editor, but once out of the editing state, the text is not saved, but I am able to select all remove the text.
Changes are in PR #2016 , with added support for {uparrow}
and {downarrow}
. Here's an example:
cy.visit('https://draftjs.org/')
cy.get('[contenteditable]').click()
cy.contains('.RichEditor-styleButton', 'Monospace').click()
cy.get('[contenteditable]')
.type(`
foo
bar
baz{leftarrow}{leftarrow}{uparrow}11{uparrow}22{downarrow}{downarrow}33`
.replace(/\n/g, '{enter}')
)
.should('have.prop', 'innerText', '\nfoo22\nb11ar\nbaz33\n')
Hallo! I know this is closed, but I wanted to ask the draft users on this thread if they
@averboe @MrDismal @WickyNilliams @dziamid
@brettimus on quirk is that typing {enter} does not trigger in input event. That's getting fixed in #311
Most helpful comment
I managed to get typing working by dropping down to using DOM directly. Our
RichTextEditor
component fires changes on blur (only internal state is updated on change), so we needed to focus, then type, then blur the editor. Here is the code. Hope it helps someone: