How to use _updateSelectionAfterDeletionContent method in Testcafe

Best JavaScript code snippet using testcafe

index.js

Source:index.js Github

copy

Full Screen

...3155 startPos: contentEditable$1.calculateNodeAndOffsetByPosition(element, 0),3156 endPos: contentEditable$1.calculateNodeAndOffsetByPosition(element, 0)3157 };3158 }3159 function _updateSelectionAfterDeletionContent(element, selection) {3160 var startNode = selection.startPos.node;3161 var startParent = nativeMethods$6.nodeParentNodeGetter.call(startNode);3162 var hasStartParent = startParent && startNode.parentElement;3163 var browserRequiresSelectionUpdating = browserUtils$8.isChrome && browserUtils$8.version < 58 || browserUtils$8.isSafari;3164 if (browserRequiresSelectionUpdating || !hasStartParent || !domUtils$7.isElementContainsNode(element, startNode)) {3165 selection = _getSelectionInElement(element);3166 if (textSelection$1.hasInverseSelectionContentEditable(element)) {3167 selection = {3168 startPos: selection.endPos,3169 endPos: selection.startPos3170 };3171 }3172 }3173 selection.endPos.offset = selection.startPos.offset;3174 return selection;3175 }3176 function _typeTextInElementNode(elementNode, text, offset) {3177 var nodeForTyping = document.createTextNode(text);3178 var textLength = text.length;3179 var selectPosition = { node: nodeForTyping, offset: textLength };3180 var parent = nativeMethods$6.nodeParentNodeGetter.call(elementNode);3181 if (domUtils$7.getTagName(elementNode) === 'br')3182 parent.insertBefore(nodeForTyping, elementNode);3183 else if (offset > 0)3184 elementNode.insertBefore(nodeForTyping, elementNode.childNodes[offset]);3185 else3186 elementNode.appendChild(nodeForTyping);3187 textSelection$1.selectByNodesAndOffsets(selectPosition, selectPosition);3188 }3189 function _typeTextInChildTextNode(element, selection, text) {3190 var startNode = selection.startPos.node;3191 // NOTE: startNode could be moved or deleted on textInput event. Need ensure startNode.3192 if (!domUtils$7.isElementContainsNode(element, startNode)) {3193 selection = _excludeInvisibleSymbolsFromSelection(_getSelectionInElement(element));3194 startNode = selection.startPos.node;3195 }3196 var startOffset = selection.startPos.offset;3197 var endOffset = selection.endPos.offset;3198 var nodeValue = startNode.nodeValue;3199 var selectPosition = { node: startNode, offset: startOffset + text.length };3200 startNode.nodeValue = nodeValue.substring(0, startOffset) + text +3201 nodeValue.substring(endOffset, nodeValue.length);3202 textSelection$1.selectByNodesAndOffsets(selectPosition, selectPosition);3203 }3204 function _excludeInvisibleSymbolsFromSelection(selection) {3205 var startNode = selection.startPos.node;3206 var startOffset = selection.startPos.offset;3207 var endOffset = selection.endPos.offset;3208 var firstNonWhitespaceSymbolIndex = contentEditable$1.getFirstNonWhitespaceSymbolIndex(startNode.nodeValue);3209 var lastNonWhitespaceSymbolIndex = contentEditable$1.getLastNonWhitespaceSymbolIndex(startNode.nodeValue);3210 if (startOffset < firstNonWhitespaceSymbolIndex && startOffset !== 0) {3211 selection.startPos.offset = firstNonWhitespaceSymbolIndex;3212 selection.endPos.offset = endOffset + firstNonWhitespaceSymbolIndex - startOffset;3213 }3214 else if (endOffset > lastNonWhitespaceSymbolIndex && endOffset !== startNode.nodeValue.length) {3215 selection.startPos.offset = startNode.nodeValue.length;3216 selection.endPos.offset = endOffset + startNode.nodeValue.length - startOffset;3217 }3218 return selection;3219 }3220 // NOTE: https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/beforeinput_event3221 // The `beforeInput` event is supported only in Chrome-based browsers and Safari3222 // The order of events differs in Chrome and Safari:3223 // In Chrome: `beforeinput` occurs before `textInput`3224 // In Safari: `beforeinput` occurs after `textInput`3225 function simulateBeforeInput(element, text, needSimulate) {3226 if (needSimulate)3227 return eventSimulator$9.beforeInput(element, text);3228 return true;3229 }3230 // NOTE: Typing can be prevented in Chrome/Edge but can not be prevented in IE11 or Firefox3231 // Firefox does not support TextInput event3232 // Safari supports the TextInput event but has a bug: e.data is added to the node value.3233 // So in Safari we need to call preventDefault in the last textInput handler but not prevent the Input event3234 function simulateTextInput(element, text) {3235 var forceInputInSafari;3236 function onSafariTextInput(e) {3237 e.preventDefault();3238 forceInputInSafari = true;3239 }3240 function onSafariPreventTextInput(e) {3241 if (e.type === 'textInput')3242 forceInputInSafari = false;3243 }3244 if (browserUtils$8.isSafari) {3245 listeners$2.addInternalEventListener(window, ['textInput'], onSafariTextInput);3246 eventSandbox.on(eventSandbox.EVENT_PREVENTED_EVENT, onSafariPreventTextInput);3247 }3248 var isInputEventRequired = browserUtils$8.isFirefox || eventSimulator$9.textInput(element, text) || forceInputInSafari;3249 if (browserUtils$8.isSafari) {3250 listeners$2.removeInternalEventListener(window, ['textInput'], onSafariTextInput);3251 eventSandbox.off(eventSandbox.EVENT_PREVENTED_EVENT, onSafariPreventTextInput);3252 }3253 return isInputEventRequired || browserUtils$8.isIE11;3254 }3255 function _typeTextToContentEditable(element, text) {3256 var currentSelection = _getSelectionInElement(element);3257 var startNode = currentSelection.startPos.node;3258 var endNode = currentSelection.endPos.node;3259 var needProcessInput = true;3260 var needRaiseInputEvent = true;3261 var textInputData = text;3262 text = text.replace(WHITE_SPACES_RE, String.fromCharCode(160));3263 // NOTE: some browsers raise the 'input' event after the element3264 // content is changed, but in others we should do it manually.3265 var onInput = function () {3266 needRaiseInputEvent = false;3267 };3268 // NOTE: IE11 raises the 'textinput' event many times after the element changed.3269 // The 'textinput' should be called only once3270 function onTextInput(event, dispatched, preventEvent) {3271 preventEvent();3272 }3273 // NOTE: IE11 does not raise input event when type to contenteditable3274 var beforeContentChanged = function () {3275 needProcessInput = simulateTextInput(element, textInputData);3276 needRaiseInputEvent = needProcessInput && !browserUtils$8.isIE11;3277 listeners$2.addInternalEventListener(window, ['input'], onInput);3278 listeners$2.addInternalEventListener(window, ['textinput'], onTextInput);3279 };3280 var afterContentChanged = function () {3281 nextTick()3282 .then(function () {3283 if (needRaiseInputEvent)3284 eventSimulator$9.input(element);3285 listeners$2.removeInternalEventListener(window, ['input'], onInput);3286 listeners$2.removeInternalEventListener(window, ['textinput'], onTextInput);3287 });3288 };3289 if (!startNode || !endNode || !domUtils$7.isContentEditableElement(startNode) ||3290 !domUtils$7.isContentEditableElement(endNode))3291 return;3292 if (!domUtils$7.isTheSameNode(startNode, endNode)) {3293 textSelection$1.deleteSelectionContents(element);3294 // NOTE: after deleting the selection contents we should refresh the stored startNode because3295 // contentEditable element's content could change and we can no longer find parent elements3296 // of the nodes. In MSEdge, 'parentElement' for the deleted element isn't undefined3297 currentSelection = _updateSelectionAfterDeletionContent(element, currentSelection);3298 startNode = currentSelection.startPos.node;3299 }3300 if (!startNode || !domUtils$7.isContentEditableElement(startNode) || !domUtils$7.isRenderedNode(startNode))3301 return;3302 if (!simulateBeforeInput(element, text, browserUtils$8.isChrome))3303 return;3304 beforeContentChanged();3305 if (needProcessInput)3306 needProcessInput = simulateBeforeInput(element, text, browserUtils$8.isSafari);3307 if (needProcessInput) {3308 // NOTE: we can type only to the text nodes; for nodes with the 'element-node' type, we use a special behavior3309 if (domUtils$7.isElementNode(startNode))3310 _typeTextInElementNode(startNode, text);3311 else...

Full Screen

Full Screen

type-text.js

Source:type-text.js Github

copy

Full Screen

...88 textSelection.deleteSelectionContents(element);89 // NOTE: after deleting the selection contents we should refresh the stored startNode because90 // contentEditable element's content could change and we can no longer find parent elements91 // of the nodes. In MSEdge, 'parentElement' for the deleted element isn't undefined92 currentSelection = _updateSelectionAfterDeletionContent(element, currentSelection);93 startNode = currentSelection.startPos.node;94 }95 if (!startNode || !domUtils.isContentEditableElement(startNode) || !domUtils.isRenderedNode(startNode))96 return;97 // NOTE: we can type only to the text nodes; for nodes with the 'element-node' type, we use a special behavior98 if (domUtils.isElementNode(startNode)) {99 _typeTextInElementNode(startNode, text);100 afterContentChanged();101 return;102 }103 currentSelection = _excludeInvisibleSymbolsFromSelection(currentSelection);104 startNode = currentSelection.startPos.node;105 var startOffset = currentSelection.startPos.offset;106 var endOffset = currentSelection.endPos.offset;...

Full Screen

Full Screen

type-char.js

Source:type-char.js Github

copy

Full Screen

...87 textSelection.deleteSelectionContents(element);88 // NOTE: after deleting the selection contents we should refresh the stored startNode because89 // contentEditable element's content could change and we can no longer find parent elements90 // of the nodes. In MSEdge, 'parentElement' for the deleted element isn't undefined91 currentSelection = _updateSelectionAfterDeletionContent(element, currentSelection);92 startNode = currentSelection.startPos.node;93 }94 if (!startNode || !domUtils.isContentEditableElement(startNode) || !domUtils.isRenderedNode(startNode))95 return;96 // NOTE: we can type only to the text nodes; for nodes with the 'element-node' type, we use a special behavior97 if (domUtils.isElementNode(startNode)) {98 _typeCharInElementNode(startNode, text);99 afterContentChanged();100 return;101 }102 currentSelection = _excludeInvisibleSymbolsFromSelection(currentSelection);103 startNode = currentSelection.startPos.node;104 var startOffset = currentSelection.startPos.offset;105 var endOffset = currentSelection.endPos.offset;...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1import { Selector } from 'testcafe';2test('My first test', async t => {3 .typeText('#developer-name', 'Peter')4 .click('#submit-button')5 .takeScreenshot();6});7import { Selector } from 'testcafe';8test('My first test', async t => {9 .typeText('#developer-name', 'Peter')10 .click('#submit-button')11 .takeScreenshot();12});13 .typeText('#developer-name', 'Peter')14 .selectText('#developer-name')15 .pressKey('delete')16 .takeScreenshot();17 .typeText('#developer-name', 'Peter')18 .selectText('#developer-name')19 .pressKey('delete')20 .takeScreenshot();

Full Screen

Using AI Code Generation

copy

Full Screen

1import { Selector } from 'testcafe';2test('My first test', async t => {3 const textarea = Selector('#developer-name');4 .typeText(textarea, 'Peter')5 .click('#submit-button')6 .wait(5000);7});8await t.click('#download-button');9await t.click('#download-button').wait(5000);10await t.click('#download-button').wait(5000).wait(Selector('#download-button').exists);11await t.click('#download-button').wait(5000).wait(Selector('#download-button').exists).wait(5000);12await t.click('#download-button').wait(5000).wait(Selector('#download-button').exists).wait(5000).wait(Selector('#download-button').exists);13await t.click('#download-button').wait(5000).wait(Selector('#download-button').exists).wait(5000).wait(Selector('#download-button').exists).wait(5000);14await t.click('#download-button').wait(5000).wait(Selector('#download-button').exists).wait(5000).wait(Selector('#download-button').exists).wait(5000).wait

Full Screen

Using AI Code Generation

copy

Full Screen

1import { ClientFunction } from 'testcafe';2test('Test', async t => {3 .typeText('#lst-ib', 'test')4 .pressKey('ctrl+a delete')5 .expect(await ClientFunction(() => document.activeElement.value)()).eql('');6});7 .typeText('#lst-ib', 'test')8 .pressKey('ctrl+a delete')9 .expect(await ClientFunction(() => document.activeElement.value)()).eql('');

Full Screen

Using AI Code Generation

copy

Full Screen

1import { Selector } from 'testcafe';2test('My first test', async t => {3 .typeText('body', 'Hello, world!')4 .click('body')5 .pressKey('ctrl+a delete')6 .expect(Selector('body').innerText).eql('Hello, world!');7});

Full Screen

Using AI Code Generation

copy

Full Screen

1import { Selector } from 'testcafe';2test('My first test', async t => {3 .typeText('#developer-name', 'Peter')4 .click('#tried-test-cafe')5 .click('#submit-button');6});7export default class TestCafe {8 constructor (selector) {9 this.selector = selector;10 }11 async _updateSelectionAfterDeletionContent (startPos, endPos) {12 const { left, top, width, height } = await this.selector.getBoundingClientRect();13 await this.selector.with({ visibilityCheck: true })()14 .rightClick()15 .rightClick()

Full Screen

Using AI Code Generation

copy

Full Screen

1var selection = window.getSelection();2var range = selection.getRangeAt(0);3selection._updateSelectionAfterDeletionContent(range.startContainer, range.startOffset, range.endContainer, range.endOffset);4Selection.prototype._updateSelectionAfterDeletionContent = function (startContainer, startOffset, endContainer, endOffset) {5 var curDocument = domUtils.findDocument(startContainer);6 var curWindow = domUtils.findWindow(curDocument);7 var isStartContainerText = domUtils.isTextNode(startContainer);8 var isEndContainerText = domUtils.isTextNode(endContainer);9 var startContainerParent = startContainer.parentNode;10 var endContainerParent = endContainer.parentNode;11 var startContainerParentText = startContainerParent.textContent;12 var endContainerParentText = endContainerParent.textContent;13 var startContainerParentLength = startContainerParentText.length;14 var endContainerParentLength = endContainerParentText.length;15 var isStartContainerParentLastChild = startContainerParent === startContainerParentParent.lastChild;16 var isEndContainerParentLastChild = endContainerParent === endContainerParentParent.lastChild;17 var startContainerParentParent = startContainerParent.parentNode;18 var endContainerParentParent = endContainerParent.parentNode;19 var startContainerParentParentText = startContainerParentParent.textContent;20 var endContainerParentParentText = endContainerParentParent.textContent;21 var startContainerParentParentLength = startContainerParentParentText.length;22 var endContainerParentParentLength = endContainerParentParentText.length;23 var isStartContainerParentParentLastChild = startContainerParentParent === startContainerParentParentParent.lastChild;24 var isEndContainerParentParentLastChild = endContainerParentParent === endContainerParentParentParent.lastChild;25 var startContainerParentParentParent = startContainerParentParent.parentNode;26 var endContainerParentParentParent = endContainerParentParent.parentNode;27 var startContainerParentParentParentText = startContainerParentParentParent.textContent;28 var endContainerParentParentParentText = endContainerParentParentParent.textContent;

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Testcafe automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful