Best JavaScript code snippet using testcafe
index.js
Source:index.js  
...3727        currentTextarea = null;3728        currentTextareaCursorIndent = null;3729        eventUtils$3.unbind(this, 'blur', onTextAreaBlur, true);3730    }3731    function updateTextAreaIndent(element) {3732        if (domUtils$8.isTextAreaElement(element)) {3733            if (currentTextarea !== element) {3734                eventUtils$3.bind(element, 'blur', onTextAreaBlur, true);3735                currentTextarea = element;3736            }3737            currentTextareaCursorIndent = getLineIndentInTextarea(element);3738        }3739    }3740    function getLineIndentInTextarea(textarea) {3741        var inverseSelection = textSelection$2.hasInverseSelection(textarea);3742        var textareaValue = domUtils$8.getTextAreaValue(textarea);3743        var cursorPosition = inverseSelection ?3744            textSelection$2.getSelectionStart(textarea) :3745            textSelection$2.getSelectionEnd(textarea);3746        if (!textareaValue || !cursorPosition)3747            return 0;3748        return domUtils$8.getTextareaIndentInLine(textarea, cursorPosition);3749    }3750    function moveTextAreaCursorUp(element, withSelection) {3751        var textareaValue = domUtils$8.getTextAreaValue(element);3752        if (!textareaValue)3753            return;3754        var startPos = textSelection$2.getSelectionStart(element);3755        var endPos = textSelection$2.getSelectionEnd(element);3756        var hasInverseSelection = textSelection$2.hasInverseSelection(element);3757        var partBeforeCursor = textareaValue.substring(0, hasInverseSelection ? startPos : endPos);3758        var lastLineBreakIndex = partBeforeCursor.lastIndexOf('\n');3759        var partBeforeLastLineBreak = partBeforeCursor.substring(0, lastLineBreakIndex);3760        if (currentTextareaCursorIndent === null || currentTextarea !== element)3761            updateTextAreaIndent(element);3762        lastLineBreakIndex = partBeforeLastLineBreak.lastIndexOf('\n');3763        var newPosition = Math.min(lastLineBreakIndex + 1 + currentTextareaCursorIndent, partBeforeLastLineBreak.length);3764        moveTextAreaCursor(element, startPos, endPos, hasInverseSelection, newPosition, withSelection);3765    }3766    function moveTextAreaCursorDown(element, withSelection) {3767        var textareaValue = domUtils$8.getTextAreaValue(element);3768        if (!textareaValue)3769            return;3770        var startPos = textSelection$2.getSelectionStart(element);3771        var endPos = textSelection$2.getSelectionEnd(element);3772        var hasInverseSelection = textSelection$2.hasInverseSelection(element);3773        var cursorPosition = hasInverseSelection ? startPos : endPos;3774        var partAfterCursor = textareaValue.substring(cursorPosition);3775        var firstLineBreakIndex = partAfterCursor.indexOf('\n');3776        var nextLineStartIndex = firstLineBreakIndex === -1 ? partAfterCursor.length : firstLineBreakIndex + 1;3777        var partAfterNewIndent = partAfterCursor.substring(nextLineStartIndex);3778        var newPosition = cursorPosition + nextLineStartIndex;3779        firstLineBreakIndex = partAfterNewIndent.indexOf('\n');3780        var maxIndent = firstLineBreakIndex === -1 ? partAfterNewIndent.length : firstLineBreakIndex;3781        if (currentTextareaCursorIndent === null || currentTextarea !== element)3782            updateTextAreaIndent(element);3783        newPosition = Math.min(newPosition + currentTextareaCursorIndent, newPosition + maxIndent);3784        moveTextAreaCursor(element, startPos, endPos, hasInverseSelection, newPosition, withSelection);3785    }3786    function moveTextAreaCursor(element, startPos, endPos, hasInverseSelection, newPosition, withSelection) {3787        var newStart = null;3788        var newEnd = null;3789        if (withSelection) {3790            if (startPos === endPos) {3791                newStart = startPos;3792                newEnd = newPosition;3793            }3794            else if (!hasInverseSelection) {3795                newStart = startPos;3796                newEnd = newPosition;3797            }3798            else {3799                newStart = endPos;3800                newEnd = newPosition;3801            }3802        }3803        else3804            newEnd = newStart = newPosition;3805        textSelection$2.select(element, newStart, newEnd);3806    }3807    function setElementValue(element, value, position) {3808        if (domUtils$8.isInputElement(element) && element.type === 'number') {3809            if (value.charAt(0) === '-' && value.charAt(1) === '.')3810                value = value.substring(1);3811            if (value.charAt(value.length - 1) === '.')3812                value = value.substring(0, value.length - 1);3813        }3814        domUtils$8.setElementValue(element, value);3815        textSelection$2.select(element, position, position);3816        eventSimulator$b.input(element);3817    }3818    function submitFormOnEnterPressInInput(form, inputElement) {3819        var buttons = form.querySelectorAll('input, button');3820        var submitButton = null;3821        var i = null;3822        for (i = 0; i < buttons.length; i++) {3823            if (!submitButton && buttons[i].type === 'submit' && !buttons[i].disabled) {3824                submitButton = buttons[i];3825                break;3826            }3827        }3828        if (submitButton)3829            eventSimulator$b.click(submitButton);3830        else if (domUtils$8.blocksImplicitSubmission(inputElement)) {3831            var formInputs = form.getElementsByTagName('input');3832            var textInputs = [];3833            for (i = 0; i < formInputs.length; i++) {3834                if (domUtils$8.blocksImplicitSubmission(formInputs[i]))3835                    textInputs.push(formInputs[i]);3836            }3837            // NOTE: the form is submitted on enter press if there is only one input of the following types on it3838            //  and this input is focused (http://www.w3.org/TR/html5/forms.html#implicit-submission)3839            if (textInputs.length === 1 && textInputs[0] === inputElement) {3840                var isInputValid = inputElement.validity.valid;3841                if (isInputValid && eventSimulator$b.submit(form))3842                    form.submit();3843            }3844        }3845    }3846    //shortcuts3847    function selectAll(element) {3848        if (domUtils$8.isEditableElement(element))3849            textSelection$2.select(element);3850        return Promise$9.resolve();3851    }3852    function backspace(element) {3853        if (domUtils$8.isTextEditableElementAndEditingAllowed(element)) {3854            var startPos = textSelection$2.getSelectionStart(element);3855            var endPos = textSelection$2.getSelectionEnd(element);3856            var value = domUtils$8.getElementValue(element).replace(/\r\n/g, '\n');3857            if (endPos === startPos) {3858                if (startPos > 0) {3859                    setElementValue(element, value.substring(0, startPos - 1) +3860                        value.substring(endPos, value.length), startPos - 1);3861                }3862            }3863            else3864                setElementValue(element, value.substring(0, startPos) + value.substring(endPos, value.length), startPos);3865        }3866        if (domUtils$8.isContentEditableElement(element))3867            textSelection$2.deleteSelectionContents(element);3868        return Promise$9.resolve();3869    }3870    function del(element) {3871        if (domUtils$8.isTextEditableElementAndEditingAllowed(element)) {3872            var startPos = textSelection$2.getSelectionStart(element);3873            var endPos = textSelection$2.getSelectionEnd(element);3874            var value = domUtils$8.getElementValue(element).replace(/\r\n/g, '\n');3875            if (endPos === startPos) {3876                if (startPos < value.length) {3877                    setElementValue(element, value.substring(0, startPos) +3878                        value.substring(endPos + 1, value.length), startPos);3879                }3880            }3881            else {3882                setElementValue(element, value.substring(0, startPos) +3883                    value.substring(endPos, value.length), startPos);3884            }3885        }3886        if (domUtils$8.isContentEditableElement(element))3887            textSelection$2.deleteSelectionContents(element);3888        return Promise$9.resolve();3889    }3890    function left(element) {3891        var startPosition = null;3892        var endPosition = null;3893        if (domUtils$8.isSelectElement(element))3894            selectElement.switchOptionsByKeys(element, 'left');3895        if (isRadioButtonNavigationRequired(element))3896            return focusAndCheckNextRadioButton(element, true);3897        if (domUtils$8.isTextEditableElement(element)) {3898            startPosition = textSelection$2.getSelectionStart(element) || 0;3899            endPosition = textSelection$2.getSelectionEnd(element);3900            var newPosition = startPosition === endPosition ? startPosition - 1 : startPosition;3901            textSelection$2.select(element, newPosition, newPosition);3902            updateTextAreaIndent(element);3903        }3904        if (domUtils$8.isContentEditableElement(element)) {3905            startPosition = textSelection$2.getSelectionStart(element);3906            endPosition = textSelection$2.getSelectionEnd(element);3907            // NOTE: we only remove selection3908            if (startPosition !== endPosition) {3909                var selection = textSelection$2.getSelectionByElement(element);3910                var inverseSelection = textSelection$2.hasInverseSelectionContentEditable(element);3911                var startNode = inverseSelection ? selection.focusNode : selection.anchorNode;3912                var startOffset = inverseSelection ? selection.focusOffset : selection.anchorOffset;3913                var startPos = { node: startNode, offset: startOffset };3914                textSelection$2.selectByNodesAndOffsets(startPos, startPos, true);3915            }3916        }3917        return Promise$9.resolve();3918    }3919    function right(element) {3920        var startPosition = null;3921        var endPosition = null;3922        if (domUtils$8.isSelectElement(element))3923            selectElement.switchOptionsByKeys(element, 'right');3924        if (isRadioButtonNavigationRequired(element))3925            return focusAndCheckNextRadioButton(element, false);3926        if (domUtils$8.isTextEditableElement(element)) {3927            startPosition = textSelection$2.getSelectionStart(element);3928            endPosition = textSelection$2.getSelectionEnd(element);3929            var newPosition = startPosition === endPosition ? endPosition + 1 : endPosition;3930            if (startPosition === domUtils$8.getElementValue(element).length)3931                newPosition = startPosition;3932            textSelection$2.select(element, newPosition, newPosition);3933            updateTextAreaIndent(element);3934        }3935        if (domUtils$8.isContentEditableElement(element)) {3936            startPosition = textSelection$2.getSelectionStart(element);3937            endPosition = textSelection$2.getSelectionEnd(element);3938            //NOTE: we only remove selection3939            if (startPosition !== endPosition) {3940                var selection = textSelection$2.getSelectionByElement(element);3941                var inverseSelection = textSelection$2.hasInverseSelectionContentEditable(element);3942                var endNode = inverseSelection ? selection.anchorNode : selection.focusNode;3943                var endOffset = inverseSelection ? selection.anchorOffset : selection.focusOffset;3944                var startPos = { node: endNode, offset: endOffset };3945                textSelection$2.selectByNodesAndOffsets(startPos, startPos, true);3946            }3947        }3948        return Promise$9.resolve();3949    }3950    function up(element) {3951        if (domUtils$8.isSelectElement(element))3952            selectElement.switchOptionsByKeys(element, 'up');3953        if (isRadioButtonNavigationRequired(element))3954            return focusAndCheckNextRadioButton(element, true);3955        if (browserUtils$b.isWebKit && domUtils$8.isInputElement(element))3956            return home(element);3957        if (domUtils$8.isTextAreaElement(element))3958            moveTextAreaCursorUp(element, false);3959        return Promise$9.resolve();3960    }3961    function down(element) {3962        if (domUtils$8.isSelectElement(element))3963            selectElement.switchOptionsByKeys(element, 'down');3964        if (isRadioButtonNavigationRequired(element))3965            return focusAndCheckNextRadioButton(element, false);3966        if (browserUtils$b.isWebKit && domUtils$8.isInputElement(element))3967            return end(element);3968        if (domUtils$8.isTextAreaElement(element))3969            moveTextAreaCursorDown(element, false);3970        return Promise$9.resolve();3971    }3972    function home(element, withSelection) {3973        if (domUtils$8.isTextEditableElement(element)) {3974            var startPos = textSelection$2.getSelectionStart(element);3975            var endPos = textSelection$2.getSelectionEnd(element);3976            var inverseSelection = textSelection$2.hasInverseSelection(element);3977            var referencePosition = null;3978            var isSingleLineSelection = !domUtils$8.isTextAreaElement(element) ? true :3979                domUtils$8.getTextareaLineNumberByPosition(element, startPos) ===3980                    domUtils$8.getTextareaLineNumberByPosition(element, endPos);3981            if (isSingleLineSelection)3982                referencePosition = inverseSelection ? endPos : startPos;3983            else3984                referencePosition = inverseSelection ? startPos : endPos;3985            var valueBeforeCursor = domUtils$8.getElementValue(element).substring(0, referencePosition);3986            var lastLineBreakIndex = valueBeforeCursor.lastIndexOf('\n');3987            var newPosition = lastLineBreakIndex === -1 ? 0 : lastLineBreakIndex + 1;3988            var newStartPos = null;3989            var newEndPos = null;3990            if (isSingleLineSelection) {3991                newStartPos = newPosition;3992                newEndPos = withSelection ? referencePosition : newPosition;3993                textSelection$2.select(element, newEndPos, newStartPos);3994            }3995            else if (!inverseSelection)3996                textSelection$2.select(element, startPos, newPosition);3997            else3998                textSelection$2.select(element, endPos, newPosition);3999        }4000        return Promise$9.resolve();4001    }4002    function end(element, withSelection) {4003        if (domUtils$8.isTextEditableElement(element)) {4004            var startPos = textSelection$2.getSelectionStart(element);4005            var endPos = textSelection$2.getSelectionEnd(element);4006            var inverseSelection = textSelection$2.hasInverseSelection(element);4007            var referencePosition = null;4008            var isSingleLineSelection = !domUtils$8.isTextAreaElement(element) ? true :4009                domUtils$8.getTextareaLineNumberByPosition(element, startPos) ===4010                    domUtils$8.getTextareaLineNumberByPosition(element, endPos);4011            if (isSingleLineSelection)4012                referencePosition = inverseSelection ? endPos : startPos;4013            else4014                referencePosition = inverseSelection ? startPos : endPos;4015            var valueAsterCursor = domUtils$8.getElementValue(element).substring(referencePosition);4016            var firstLineBreakIndex = valueAsterCursor.indexOf('\n');4017            var newPosition = referencePosition;4018            var newStartPos = null;4019            var newEndPos = null;4020            newPosition += firstLineBreakIndex === -1 ? valueAsterCursor.length : firstLineBreakIndex;4021            if (isSingleLineSelection) {4022                newStartPos = withSelection ? referencePosition : newPosition;4023                newEndPos = newPosition;4024                textSelection$2.select(element, newStartPos, newEndPos);4025            }4026            else if (!inverseSelection)4027                textSelection$2.select(element, startPos, newPosition);4028            else4029                textSelection$2.select(element, endPos, newPosition);4030        }4031        return Promise$9.resolve();4032    }4033    function esc(element) {4034        if (domUtils$8.isSelectElement(element))4035            selectElement.collapseOptionList();4036        return Promise$9.resolve();4037    }4038    function shiftUp(element) {4039        if (browserUtils$b.isWebKit && domUtils$8.isInputElement(element))4040            return shiftHome(element);4041        if (domUtils$8.isTextAreaElement(element))4042            moveTextAreaCursorUp(element, true);4043        return Promise$9.resolve();4044    }4045    function shiftDown(element) {4046        if (browserUtils$b.isWebKit && domUtils$8.isInputElement(element))4047            return shiftEnd(element);4048        if (domUtils$8.isTextAreaElement(element))4049            moveTextAreaCursorDown(element, true);4050        return Promise$9.resolve();4051    }4052    function shiftLeft(element) {4053        if (domUtils$8.isTextEditableElement(element)) {4054            var startPos = textSelection$2.getSelectionStart(element);4055            var endPos = textSelection$2.getSelectionEnd(element);4056            if (startPos === endPos || textSelection$2.hasInverseSelection(element))4057                textSelection$2.select(element, endPos, Math.max(startPos - 1, 0));4058            else4059                textSelection$2.select(element, startPos, Math.max(endPos - 1, 0));4060            updateTextAreaIndent(element);4061        }4062        return Promise$9.resolve();4063    }4064    function shiftRight(element) {4065        if (domUtils$8.isTextEditableElement(element)) {4066            var startPos = textSelection$2.getSelectionStart(element);4067            var endPos = textSelection$2.getSelectionEnd(element);4068            var valueLength = domUtils$8.getElementValue(element).length;4069            if (startPos === endPos || !textSelection$2.hasInverseSelection(element))4070                textSelection$2.select(element, startPos, Math.min(endPos + 1, valueLength));4071            else4072                textSelection$2.select(element, endPos, Math.min(startPos + 1, valueLength));4073            updateTextAreaIndent(element);4074        }4075        return Promise$9.resolve();4076    }4077    function shiftHome(element) {4078        return home(element, true);4079    }4080    function shiftEnd(element) {4081        return end(element, true);4082    }4083    function enter(element) {4084        if (domUtils$8.isSelectElement(element))4085            selectElement.collapseOptionList();4086        //submit form on enter pressed4087        if (domUtils$8.isInputElement(element)) {...key-press-simulator.js
Source:key-press-simulator.js  
...146                partBeforeSelection = textareaValue.substring(0, hasInverseSelection ? start : end),147                topIndex            = partBeforeSelection.lastIndexOf('\n'),148                top                 = partBeforeSelection.substring(0, topIndex);149            if (curTextareaCursorIndent === null || curTextareaElement !== element)150                updateTextAreaIndent(element);151            var newPosition = Math.min(top.lastIndexOf('\n') + 1 + curTextareaCursorIndent, top.length);152            moveTextAreaCursor(element, start, end, hasInverseSelection, newPosition, withSelection);153        }154    }155    function moveTextAreaCursorDown (element, withSelection) {156        var textareaValue = element.value;157        if (textareaValue) {158            var hasInverseSelection = textSelection.hasInverseSelection(element),159                start               = textSelection.getSelectionStart(element),160                end                 = textSelection.getSelectionEnd(element),161                last                = textareaValue.substring(hasInverseSelection ? start : end),162                nextIndex           = last.indexOf('\n') === -1 ? last.length : last.indexOf('\n') + 1,163                bottom              = last.substring(nextIndex),164                newPosition         = (hasInverseSelection ? start : end) + nextIndex,165                maxIndent           = bottom.indexOf('\n') === -1 ? bottom.length : bottom.indexOf('\n');166            if (curTextareaCursorIndent === null || curTextareaElement !== element)167                updateTextAreaIndent(element);168            if (curTextareaCursorIndent >= maxIndent)169                newPosition += maxIndent;170            else171                newPosition += curTextareaCursorIndent;172            moveTextAreaCursor(element, start, end, hasInverseSelection, newPosition, withSelection);173        }174    }175    function moveTextAreaCursor (element, start, end, hasInverseSelection, newPosition, withSelection) {176        var newStart = null,177            newEnd   = null,178            inverse  = null;179        if (withSelection) {180            if (start === end) {181                if (newPosition < start) {182                    newStart = newPosition;183                    newEnd   = start;184                    inverse  = true;185                }186                else {187                    newStart = start;188                    newEnd   = newPosition;189                }190            }191            else {192                if (!hasInverseSelection) {193                    if (newPosition < start) {194                        newStart = newPosition;195                        newEnd   = start;196                        inverse  = true;197                    }198                    else {199                        newStart = start;200                        newEnd   = newPosition;201                    }202                }203                else {204                    if (newPosition > end) {205                        newStart = end;206                        newEnd   = newPosition;207                    }208                    else {209                        newStart = newPosition;210                        newEnd   = end;211                        inverse  = true;212                    }213                }214            }215        }216        else217            newEnd = newStart = newPosition;218        textSelection.select(element, newStart, newEnd, inverse);219    }220    function setElementValue (element, value) {221        element.value = value;222        eventSimulator.input(element);223    }224    //shortcuts225    function selectAll (element, callback) {226        if (domUtils.isEditableElement(element))227            textSelection.select(element);228        callback();229    }230    function backspace (element, callback) {231        if (domUtils.isTextEditableElementAndEditingAllowed(element)) {232            var startSelection = textSelection.getSelectionStart(element),233                endSelection   = textSelection.getSelectionEnd(element),234                value          = element.value.replace(/\r\n/g, '\n');235            if (endSelection === startSelection) {236                if (startSelection > 0) {237                    setElementValue(element, value.substring(0, startSelection - 1) +238                                             value.substring(endSelection, value.length));239                    textSelection.select(element, startSelection - 1, startSelection - 1);240                }241            }242            else {243                setElementValue(element, value.substring(0, startSelection) +244                                         value.substring(endSelection, value.length));245                textSelection.select(element, startSelection, startSelection);246            }247        }248        else if (domUtils.isContentEditableElement(element))249            textSelection.deleteSelectionContents(element);250        callback();251    }252    function del (element, callback) {253        if (domUtils.isTextEditableElementAndEditingAllowed(element)) {254            var startSelection = textSelection.getSelectionStart(element),255                endSelection   = textSelection.getSelectionEnd(element),256                value          = element.value.replace(/\r\n/g, '\n');257            if (endSelection === startSelection) {258                if (startSelection < value.length) {259                    setElementValue(element, value.substring(0, startSelection) +260                                             value.substring(endSelection + 1, value.length));261                    textSelection.select(element, startSelection, startSelection);262                }263            }264            else {265                setElementValue(element, value.substring(0, startSelection) +266                                         value.substring(endSelection, value.length));267                textSelection.select(element, startSelection, startSelection);268            }269        }270        else if (domUtils.isContentEditableElement(element))271            textSelection.deleteSelectionContents(element);272        callback();273    }274    function left (element, callback) {275        var startSelection = null,276            endSelection   = null;277        if (domUtils.isTextEditableElement(element)) {278            startSelection = textSelection.getSelectionStart(element);279            endSelection   = textSelection.getSelectionEnd(element);280            var newPosition = startSelection ?281                              startSelection === endSelection ? startSelection - 1 : startSelection :282                              0;283            textSelection.select(element, newPosition, newPosition);284            updateTextAreaIndent(element);285        }286        else if (domUtils.isContentEditableElement(element)) {287            startSelection = textSelection.getSelectionStart(element);288            endSelection   = textSelection.getSelectionEnd(element);289            //NOTE: we only remove selection290            if (startSelection !== endSelection) {291                var selection        = textSelection.getSelectionByElement(element),292                    inverseSelection = textSelection.hasInverseSelectionContentEditable(element),293                    startNode        = inverseSelection ? selection.focusNode : selection.anchorNode,294                    startOffset      = inverseSelection ? selection.focusOffset : selection.anchorOffset;295                textSelection.selectByNodesAndOffsets(startNode, startOffset, startNode, startOffset, true, false);296            }297        }298        callback();299    }300    function right (element, callback) {301        var startSelection = null,302            endSelection   = null;303        if (domUtils.isTextEditableElement(element)) {304            startSelection = textSelection.getSelectionStart(element);305            endSelection   = textSelection.getSelectionEnd(element);306            var newPosition = startSelection === element.value.length ?307                              startSelection :308                              startSelection === endSelection ? startSelection + 1 : endSelection;309            textSelection.select(element, newPosition, newPosition);310            updateTextAreaIndent(element);311        }312        else if (domUtils.isContentEditableElement(element)) {313            startSelection = textSelection.getSelectionStart(element);314            endSelection   = textSelection.getSelectionEnd(element);315            //NOTE: we only remove selection316            if (startSelection !== endSelection) {317                var selection        = textSelection.getSelectionByElement(element),318                    inverseSelection = textSelection.hasInverseSelectionContentEditable(element),319                    endNode          = inverseSelection ? selection.anchorNode : selection.focusNode,320                    endOffset        = inverseSelection ? selection.anchorOffset : selection.focusOffset;321                textSelection.selectByNodesAndOffsets(endNode, endOffset, endNode, endOffset, true, false);322            }323        }324        callback();325    }326    function up (element, callback) {327        if (browserUtils.isWebKit && element.tagName && element.tagName.toLowerCase() === 'input') {328            home(element, callback);329            return;330        }331        if (element.tagName && element.tagName.toLowerCase() === 'textarea')332            moveTextAreaCursorUp(element, false);333        callback();334    }335    function down (element, callback) {336        if (browserUtils.isWebKit && element.tagName && element.tagName.toLowerCase() === 'input') {337            end(element, callback);338            return;339        }340        if (element.tagName && element.tagName.toLowerCase() === 'textarea') {341            moveTextAreaCursorDown(element, false);342        }343        callback();344    }345    function home (element, callback, withSelection) {346        if (domUtils.isTextEditableElement(element)) {347            var elementValue           = element.value,348                selectionStartPosition = textSelection.getSelectionStart(element),349                selectionEndPosition   = textSelection.getSelectionEnd(element),350                inverseSelection       = textSelection.hasInverseSelection(element),351                isSingleLineSelection  = element.tagName.toLocaleLowerCase() !== 'textarea' ? true :352                                         domUtils.getTextareaLineNumberByPosition(element, selectionStartPosition) ===353                                         domUtils.getTextareaLineNumberByPosition(element, selectionEndPosition),354                referencePosition      = null;355            if (isSingleLineSelection)356                referencePosition = inverseSelection ? selectionEndPosition : selectionStartPosition;357            else358                referencePosition = inverseSelection ? selectionStartPosition : selectionEndPosition;359            var partBefore  = elementValue.substring(0, referencePosition),360                newPosition = partBefore.lastIndexOf('\n') === -1 ? 0 : partBefore.lastIndexOf('\n') + 1;361            if (isSingleLineSelection)362                textSelection.select(element, newPosition, withSelection ? referencePosition : newPosition, withSelection);363            else364                textSelection.select(element, inverseSelection ? newPosition : selectionStartPosition, inverseSelection ? selectionEndPosition : newPosition, inverseSelection);365        }366        callback();367    }368    function end (element, callback, withSelection) {369        if (domUtils.isTextEditableElement(element)) {370            var elementValue           = element.value,371                selectionStartPosition = textSelection.getSelectionStart(element),372                selectionEndPosition   = textSelection.getSelectionEnd(element),373                inverseSelection       = textSelection.hasInverseSelection(element),374                isSingleLineSelection  = element.tagName.toLocaleLowerCase() !== 'textarea' ? true :375                                         domUtils.getTextareaLineNumberByPosition(element, selectionStartPosition) ===376                                         domUtils.getTextareaLineNumberByPosition(element, selectionEndPosition),377                referencePosition      = null;378            if (isSingleLineSelection)379                referencePosition = inverseSelection ? selectionEndPosition : selectionStartPosition;380            else381                referencePosition = inverseSelection ? selectionStartPosition : selectionEndPosition;382            var partAfter   = elementValue.substring(referencePosition),383                newPosition = referencePosition;384            newPosition += partAfter.indexOf('\n') === -1 ? partAfter.length : partAfter.indexOf('\n');385            if (isSingleLineSelection)386                textSelection.select(element, withSelection ? referencePosition : newPosition, newPosition);387            else388                textSelection.select(element, inverseSelection ? newPosition : selectionStartPosition, inverseSelection ? selectionEndPosition : newPosition, inverseSelection);389        }390        callback();391    }392    function shiftUp (element, callback) {393        if (browserUtils.isWebKit && element.tagName && element.tagName.toLowerCase() === 'input') {394            shiftHome(element, callback);395            return;396        }397        if (element.tagName && element.tagName.toLowerCase() === 'textarea')398            moveTextAreaCursorUp(element, true);399        callback();400    }401    function shiftDown (element, callback) {402        if (browserUtils.isWebKit && element.tagName && element.tagName.toLowerCase() === 'input') {403            shiftEnd(element, callback);404            return;405        }406        if (element.tagName && element.tagName.toLowerCase() === 'textarea')407            moveTextAreaCursorDown(element, true);408        callback();409    }410    function shiftLeft (element, callback) {411        if (domUtils.isTextEditableElement(element)) {412            var start = textSelection.getSelectionStart(element),413                end   = textSelection.getSelectionEnd(element);414            if (start === end || textSelection.hasInverseSelection(element))415                textSelection.select(element, Math.max(start - 1, 0), end, true);416            else417                textSelection.select(element, start, Math.max(end - 1, 0), end - 1 < start);418            updateTextAreaIndent(element);419        }420        callback();421    }422    function shiftRight (element, callback) {423        if (domUtils.isTextEditableElement(element)) {424            var start = textSelection.getSelectionStart(element),425                end   = textSelection.getSelectionEnd(element);426            if (start === end || !textSelection.hasInverseSelection(element))427                textSelection.select(element, start, Math.min(end + 1, element.value.length));428            else429                textSelection.select(element, Math.min(start + 1, element.value.length), end, start + 1 < end);430            updateTextAreaIndent(element);431        }432        callback();433    }434    function shiftHome (element, callback) {435        home(element, callback, true);436    }437    function shiftEnd (element, callback) {438        end(element, callback, true);439    }440    function enter (element, callback) {441        //submit form on enter pressed442        if (/input/i.test(element.tagName)) {443            if (!browserUtils.isIE)444                elementEditingWatcher.processElementChanging(element);...shortcuts.js
Source:shortcuts.js  
...45    var partBeforeCursor        = textareaValue.substring(0, hasInverseSelection ? startPos : endPos);46    var lastLineBreakIndex      = partBeforeCursor.lastIndexOf('\n');47    var partBeforeLastLineBreak = partBeforeCursor.substring(0, lastLineBreakIndex);48    if (currentTextareaCursorIndent === null || currentTextarea !== element)49        updateTextAreaIndent(element);50    lastLineBreakIndex = partBeforeLastLineBreak.lastIndexOf('\n');51    var newPosition    = Math.min(lastLineBreakIndex + 1 + currentTextareaCursorIndent, partBeforeLastLineBreak.length);52    moveTextAreaCursor(element, startPos, endPos, hasInverseSelection, newPosition, withSelection);53}54function moveTextAreaCursorDown (element, withSelection) {55    var textareaValue = element.value;56    if (!textareaValue)57        return;58    var startPos            = textSelection.getSelectionStart(element);59    var endPos              = textSelection.getSelectionEnd(element);60    var hasInverseSelection = textSelection.hasInverseSelection(element);61    var cursorPosition      = hasInverseSelection ? startPos : endPos;62    var partAfterCursor     = textareaValue.substring(cursorPosition);63    var firstLineBreakIndex = partAfterCursor.indexOf('\n');64    var nextLineStartIndex  = firstLineBreakIndex === -1 ? partAfterCursor.length : firstLineBreakIndex + 1;65    var partAfterNewIndent  = partAfterCursor.substring(nextLineStartIndex);66    var newPosition         = cursorPosition + nextLineStartIndex;67    firstLineBreakIndex = partAfterNewIndent.indexOf('\n');68    var maxIndent       = firstLineBreakIndex === -1 ? partAfterNewIndent.length : firstLineBreakIndex;69    if (currentTextareaCursorIndent === null || currentTextarea !== element)70        updateTextAreaIndent(element);71    newPosition = Math.min(newPosition + currentTextareaCursorIndent, newPosition + maxIndent);72    moveTextAreaCursor(element, startPos, endPos, hasInverseSelection, newPosition, withSelection);73}74function moveTextAreaCursor (element, startPos, endPos, hasInverseSelection, newPosition, withSelection) {75    var newStart = null;76    var newEnd   = null;77    if (withSelection) {78        if (startPos === endPos) {79            newStart = startPos;80            newEnd   = newPosition;81        }82        else if (!hasInverseSelection) {83            newStart = startPos;84            newEnd   = newPosition;85        }86        else {87            newStart = endPos;88            newEnd   = newPosition;89        }90    }91    else92        newEnd = newStart = newPosition;93    textSelection.select(element, newStart, newEnd);94}95function setElementValue (element, value) {96    if (value.charAt(0) === '-' && value.charAt(1) === '.')97        value = value.substring(1);98    if (value.charAt(value.length - 1) === '.')99        value = value.substring(0, value.length - 1);100    element.value = value;101    eventSimulator.input(element);102}103function submitFormOnEnterPressInInput (form, inputElement) {104    var buttons      = form.querySelectorAll('input, button');105    var submitButton = null;106    var i            = null;107    for (i = 0; i < buttons.length; i++) {108        if (!submitButton && buttons[i].type === 'submit' && !buttons[i].disabled) {109            submitButton = buttons[i];110            break;111        }112    }113    if (submitButton)114        eventSimulator.click(submitButton);115    else if (domUtils.blocksImplicitSubmission(inputElement)) {116        var formInputs = form.getElementsByTagName('input');117        var textInputs = [];118        for (i = 0; i < formInputs.length; i++) {119            if (domUtils.blocksImplicitSubmission(formInputs[i]))120                textInputs.push(formInputs[i]);121        }122        // NOTE: the form is submitted on enter press if there is only one input of the following types on it123        //  and this input is focused (http://www.w3.org/TR/html5/forms.html#implicit-submission)124        if (textInputs.length === 1 && textInputs[0] === inputElement) {125            var isInputValid = browserUtils.isSafari || !inputElement.validity || inputElement.validity.valid;126            if (isInputValid && eventSimulator.submit(form))127                form.submit();128        }129    }130}131//shortcuts132function selectAll (element) {133    if (domUtils.isEditableElement(element))134        textSelection.select(element);135    return Promise.resolve();136}137function backspace (element) {138    if (domUtils.isTextEditableElementAndEditingAllowed(element)) {139        var startPos = textSelection.getSelectionStart(element);140        var endPos   = textSelection.getSelectionEnd(element);141        var value    = element.value.replace(/\r\n/g, '\n');142        if (endPos === startPos) {143            if (startPos > 0) {144                setElementValue(element, value.substring(0, startPos - 1) +145                                         value.substring(endPos, value.length));146                textSelection.select(element, startPos - 1, startPos - 1);147            }148        }149        else {150            setElementValue(element, value.substring(0, startPos) +151                                     value.substring(endPos, value.length));152            textSelection.select(element, startPos, startPos);153        }154    }155    if (domUtils.isContentEditableElement(element))156        textSelection.deleteSelectionContents(element);157    return Promise.resolve();158}159function del (element) {160    if (domUtils.isTextEditableElementAndEditingAllowed(element)) {161        var startPos = textSelection.getSelectionStart(element);162        var endPos   = textSelection.getSelectionEnd(element);163        var value    = element.value.replace(/\r\n/g, '\n');164        if (endPos === startPos) {165            if (startPos < value.length) {166                setElementValue(element, value.substring(0, startPos) +167                                         value.substring(endPos + 1, value.length));168                textSelection.select(element, startPos, startPos);169            }170        }171        else {172            setElementValue(element, value.substring(0, startPos) +173                                     value.substring(endPos, value.length));174            textSelection.select(element, startPos, startPos);175        }176    }177    if (domUtils.isContentEditableElement(element))178        textSelection.deleteSelectionContents(element);179    return Promise.resolve();180}181function left (element) {182    var startPosition = null;183    var endPosition   = null;184    if (domUtils.isSelectElement(element))185        selectElement.switchOptionsByKeys(element, 'left');186    if (domUtils.isTextEditableElement(element)) {187        startPosition = textSelection.getSelectionStart(element) || 0;188        endPosition   = textSelection.getSelectionEnd(element);189        var newPosition = startPosition === endPosition ? startPosition - 1 : startPosition;190        textSelection.select(element, newPosition, newPosition);191        updateTextAreaIndent(element);192    }193    if (domUtils.isContentEditableElement(element)) {194        startPosition = textSelection.getSelectionStart(element);195        endPosition   = textSelection.getSelectionEnd(element);196        // NOTE: we only remove selection197        if (startPosition !== endPosition) {198            var selection        = textSelection.getSelectionByElement(element);199            var inverseSelection = textSelection.hasInverseSelectionContentEditable(element);200            var startNode        = inverseSelection ? selection.focusNode : selection.anchorNode;201            var startOffset      = inverseSelection ? selection.focusOffset : selection.anchorOffset;202            var startPos         = { node: startNode, offset: startOffset };203            textSelection.selectByNodesAndOffsets(startPos, startPos, true);204        }205    }206    return Promise.resolve();207}208function right (element) {209    var startPosition = null;210    var endPosition   = null;211    if (domUtils.isSelectElement(element))212        selectElement.switchOptionsByKeys(element, 'right');213    if (domUtils.isTextEditableElement(element)) {214        startPosition = textSelection.getSelectionStart(element);215        endPosition   = textSelection.getSelectionEnd(element);216        var newPosition = startPosition === endPosition ? endPosition + 1 : endPosition;217        if (startPosition === element.value.length)218            newPosition = startPosition;219        textSelection.select(element, newPosition, newPosition);220        updateTextAreaIndent(element);221    }222    if (domUtils.isContentEditableElement(element)) {223        startPosition = textSelection.getSelectionStart(element);224        endPosition   = textSelection.getSelectionEnd(element);225        //NOTE: we only remove selection226        if (startPosition !== endPosition) {227            var selection        = textSelection.getSelectionByElement(element);228            var inverseSelection = textSelection.hasInverseSelectionContentEditable(element);229            var endNode          = inverseSelection ? selection.anchorNode : selection.focusNode;230            var endOffset        = inverseSelection ? selection.anchorOffset : selection.focusOffset;231            var startPos         = { node: endNode, offset: endOffset };232            textSelection.selectByNodesAndOffsets(startPos, startPos, true);233        }234    }235    return Promise.resolve();236}237function up (element) {238    if (domUtils.isSelectElement(element))239        selectElement.switchOptionsByKeys(element, 'up');240    if (browserUtils.isWebKit && domUtils.isInputElement(element))241        return home(element);242    if (domUtils.isTextAreaElement(element))243        moveTextAreaCursorUp(element, false);244    return Promise.resolve();245}246function down (element) {247    if (domUtils.isSelectElement(element))248        selectElement.switchOptionsByKeys(element, 'down');249    if (browserUtils.isWebKit && domUtils.isInputElement(element))250        return end(element);251    if (domUtils.isTextAreaElement(element))252        moveTextAreaCursorDown(element, false);253    return Promise.resolve();254}255function home (element, withSelection) {256    if (domUtils.isTextEditableElement(element)) {257        var startPos          = textSelection.getSelectionStart(element);258        var endPos            = textSelection.getSelectionEnd(element);259        var inverseSelection  = textSelection.hasInverseSelection(element);260        var referencePosition = null;261        var isSingleLineSelection = !domUtils.isTextAreaElement(element) ? true :262                                    domUtils.getTextareaLineNumberByPosition(element, startPos) ===263                                    domUtils.getTextareaLineNumberByPosition(element, endPos);264        if (isSingleLineSelection)265            referencePosition = inverseSelection ? endPos : startPos;266        else267            referencePosition = inverseSelection ? startPos : endPos;268        var valueBeforeCursor  = element.value.substring(0, referencePosition);269        var lastLineBreakIndex = valueBeforeCursor.lastIndexOf('\n');270        var newPosition        = lastLineBreakIndex === -1 ? 0 : lastLineBreakIndex + 1;271        var newStartPos        = null;272        var newEndPos          = null;273        if (isSingleLineSelection) {274            newStartPos = newPosition;275            newEndPos   = withSelection ? referencePosition : newPosition;276            textSelection.select(element, newEndPos, newStartPos);277        }278        else if (!inverseSelection)279            textSelection.select(element, startPos, newPosition);280        else281            textSelection.select(element, endPos, newPosition);282    }283    return Promise.resolve();284}285function end (element, withSelection) {286    if (domUtils.isTextEditableElement(element)) {287        var startPos          = textSelection.getSelectionStart(element);288        var endPos            = textSelection.getSelectionEnd(element);289        var inverseSelection  = textSelection.hasInverseSelection(element);290        var referencePosition = null;291        var isSingleLineSelection = !domUtils.isTextAreaElement(element) ? true :292                                    domUtils.getTextareaLineNumberByPosition(element, startPos) ===293                                    domUtils.getTextareaLineNumberByPosition(element, endPos);294        if (isSingleLineSelection)295            referencePosition = inverseSelection ? endPos : startPos;296        else297            referencePosition = inverseSelection ? startPos : endPos;298        var valueAsterCursor    = element.value.substring(referencePosition);299        var firstLineBreakIndex = valueAsterCursor.indexOf('\n');300        var newPosition         = referencePosition;301        var newStartPos         = null;302        var newEndPos           = null;303        newPosition += firstLineBreakIndex === -1 ? valueAsterCursor.length : firstLineBreakIndex;304        if (isSingleLineSelection) {305            newStartPos = withSelection ? referencePosition : newPosition;306            newEndPos   = newPosition;307            textSelection.select(element, newStartPos, newEndPos);308        }309        else if (!inverseSelection)310            textSelection.select(element, startPos, newPosition);311        else312            textSelection.select(element, endPos, newPosition);313    }314    return Promise.resolve();315}316function esc (element) {317    if (domUtils.isSelectElement(element))318        selectElement.collapseOptionList();319    return Promise.resolve();320}321function shiftUp (element) {322    if (browserUtils.isWebKit && domUtils.isInputElement(element))323        return shiftHome(element);324    if (domUtils.isTextAreaElement(element))325        moveTextAreaCursorUp(element, true);326    return Promise.resolve();327}328function shiftDown (element) {329    if (browserUtils.isWebKit && domUtils.isInputElement(element))330        return shiftEnd(element);331    if (domUtils.isTextAreaElement(element))332        moveTextAreaCursorDown(element, true);333    return Promise.resolve();334}335function shiftLeft (element) {336    if (domUtils.isTextEditableElement(element)) {337        var startPos = textSelection.getSelectionStart(element);338        var endPos   = textSelection.getSelectionEnd(element);339        if (startPos === endPos || textSelection.hasInverseSelection(element))340            textSelection.select(element, endPos, Math.max(startPos - 1, 0));341        else342            textSelection.select(element, startPos, Math.max(endPos - 1, 0));343        updateTextAreaIndent(element);344    }345    return Promise.resolve();346}347function shiftRight (element) {348    if (domUtils.isTextEditableElement(element)) {349        var startPos = textSelection.getSelectionStart(element);350        var endPos   = textSelection.getSelectionEnd(element);351        if (startPos === endPos || !textSelection.hasInverseSelection(element))352            textSelection.select(element, startPos, Math.min(endPos + 1, element.value.length));353        else354            textSelection.select(element, endPos, Math.min(startPos + 1, element.value.length));355        updateTextAreaIndent(element);356    }357    return Promise.resolve();358}359function shiftHome (element) {360    return home(element, true);361}362function shiftEnd (element) {363    return end(element, true);364}365function enter (element) {366    if (domUtils.isSelectElement(element))367        selectElement.collapseOptionList();368    //submit form on enter pressed369    if (domUtils.isInputElement(element)) {...Using AI Code Generation
1import { Selector } from 'testcafe';2test('My first test', async t => {3    const textarea = Selector('#developer-name');4        .typeText(textarea, 'Peter Parker')5        .click('#submit-button')6        .expect(Selector('#article-header').innerText).eql('Thank you, Peter Parker!');7});8test('My second test', async t => {9    const textarea = Selector('#developer-name');10        .typeText(textarea, 'Peter Parker')11        .click('#submit-button')12        .expect(Selector('#article-header').innerText).eql('Thank you, Peter Parker!');13});14import { Selector } from 'testcafe';15test('My first test', async t => {16    const textarea = Selector('#developer-name');17        .typeText(textarea, 'Peter Parker')18        .click('#submit-button')19        .expect(Selector('#article-header').innerText).eql('Thank you, Peter Parker!');20});21    ('My second test', async t => {22    const textarea = Selector('#developer-name');23        .typeText(textarea, 'Peter Parker')24        .click('#submit-button')25        .expect(Selector('#article-header').innerText).eql('Thank you, Peter Parker!');26});27import { Selector } from 'testcafe';28test('My first test', async t => {29    const textarea = Selector('#Using AI Code Generation
1import { updateTextAreaIndent } from 'testcafe-browser-tools';2test('My Test', async t => {3    await updateTextAreaIndent('developer-name', 4);4});5import { updateTextAreaIndent } from 'testcafe-browser-tools';6test('My Test', async t => {7    await updateTextAreaIndent('developer-name', 4);8});9import { updateTextAreaIndent } from 'testcafe-browser-tools';10test('My Test', async t => {11    await updateTextAreaIndent('developer-name', 4);12});13import { updateTextAreaIndent } from 'testcafe-browser-tools';14test('My Test', async t => {15    await updateTextAreaIndent('developer-name', 4);16});17import { updateTextAreaIndent } from 'testcafe-browser-tools';18test('My Test', async t => {19    await updateTextAreaIndent('developer-name', 4);20});21import { updateTextAreaIndent } from 'testcafe-browser-tools';22test('My Test', async t => {23    await updateTextAreaIndent('developer-name', 4);24});25import { updateTextAreaIndent } from 'testcafe-browser-tools';26test('My Test', async t => {Using AI Code Generation
1import { Selector } from 'testcafe';2test('My test', async t => {3        .click('#tried-test-cafe')4        .expect(Selector('#tried-test-cafe').value).eql('on')5        .typeText(Selector('#comments').updateTextAreaIndent(4), 'Hello world!');6});7import { Selector } from 'testcafe';8export default class SelectorBuilder {9    constructor (nodeBuilder, options) {10        this.nodeBuilder = nodeBuilder;11        this.options    = options;12    }13    _createSelector () {14        return Selector(this.nodeBuilder, this.options);15    }16    updateTextAreaIndent (indent) {17        return this._createSelector().addCustomDOMProperties({18            updateTextAreaIndent: node => {19                node.value = node.value.split('\n').map(line => '    ' + line).join('\n');20            }21        });22    }23}24import { Selector } from 'testcafe';25export default class SelectorBuilder {26    constructor (nodeBuilder, options) {27        this.nodeBuilder = nodeBuilder;28        this.options    = options;29    }30    _createSelector () {31        return Selector(this.nodeBuilder, this.options);32    }33    updateTextAreaIndent (indent) {34        return this._createSelector().addCustomDOMProperties({35            updateTextAreaIndent: node => {36                node.value = node.value.split('\n').map(line => '    ' + line).join('\n');37            }38        });39    }40}41import { Selector } from 'testcafe';42export default class SelectorBuilder {43    constructor (nodeBuilder, options) {44        this.nodeBuilder = nodeBuilder;45        this.options    = options;46    }47    _createSelector () {48        return Selector(this.nodeBuilder, this.options);49    }50    updateTextAreaIndent (indent) {51        return this._createSelector().addCustomDOMProperties({52            updateTextAreaIndent: node => {Using AI Code Generation
1import { ClientFunction } from 'testcafe';2const updateTextAreaIndent = ClientFunction((selector, value) => {3    const el = document.querySelector(selector);4    el.value = value;5    el.dispatchEvent(new Event('input', { bubbles: true }));6});7test('test', async t => {8        .click('#tryhome > div:nth-child(1) > div > div > div.w3-right > button')9        .switchToIframe('#iframeResult')10        .click('#myTextarea')11        .expect('textarea').eql('textarea');12    await updateTextAreaIndent('#myTextarea', 'test');13        .expect('textarea').eql('textarea');14});Using AI Code Generation
1import { Selector } from 'testcafe';2const textarea = Selector('textarea');3test('My test', async t => {4        .typeText(textarea, 'Hello')5        .typeText(textarea, 'World', { replace: true })6        .typeText(textarea, 'Hello', { caretPos: 5 })7        .typeText(textarea, 'World', { caretPos: 5, replace: true })8        .typeText(textarea, 'Hello', { caretPos: 0 })9        .typeText(textarea, 'World', { caretPos: 0, replace: true })10        .typeText(textarea, 'Hello', { caretPos: -1 })11        .typeText(textarea, 'World', { caretPos: -1, replace: true })12        .typeText(textarea, 'Hello', { caretPos: 100 })13        .typeText(textarea, 'World', { caretPos: 100, replace: true })14        .typeText(textarea, 'Hello', { caretPos: -100 })15        .typeText(textarea, 'World', { caretPos: -100, replace: true })16        .typeText(textarea, 'Hello', { caretPos: 5 })17        .typeText(textarea, 'World', { caretPos: 5, replace: true })18        .typeText(textarea, 'Hello', { caretPos: 5 })19        .typeText(textarea, 'World', { caretPos: 5, replace: true })20        .typeText(textarea, 'Hello', { caretPos: 5 })21        .typeText(textarea, 'World', { caretPos: 5, replace: true })22        .typeText(textarea, 'Hello', { caretPos: 5 })23        .typeText(textarea, 'World', { caretPos: 5, replace: true })24        .typeText(textarea, 'Hello', { caretPos: 5 })25        .typeText(textarea, 'World', { caretPos: 5, replace: true })26        .typeText(textarea, 'Hello', { caretPos: 5 })27        .typeText(textarea, 'World', { caretPos: 5, replace: true })28        .typeText(textarea, 'Using AI Code Generation
1import { ClientFunction } from 'testcafe';2const updateTextAreaIndent = ClientFunction(() => {3  testCafe.core.editors[0].updateTextAreaIndent();4});5test('Test1', async t => {6    .click('#textarea')7    .pressKey('tab')8    .pressKey('tab')9    .pressKey('enter')10    .typeText('#textarea', 'line2')11    .pressKey('enter')12    .typeText('#textarea', 'line3')13    .pressKey('enter')14    .typeText('#textarea', 'line4')15    .pressKey('enter')16    .typeText('#textarea', 'line5')17    .pressKey('enter')18    .typeText('#textarea', 'line6')19    .pressKey('enter')20    .typeText('#textarea', 'line7')21    .pressKey('enter')22    .typeText('#textarea', 'line8')23    .pressKey('enter')24    .typeText('#textarea', 'line9')25    .pressKey('enter')26    .typeText('#textarea', 'line10')27    .pressKey('enter')28    .typeText('#textarea', 'line11')29    .pressKey('enter')30    .typeText('#textarea', 'line12')31    .pressKey('enter')32    .typeText('#textarea', 'line13')33    .pressKey('enter')34    .typeText('#textarea', 'line14')35    .pressKey('enter')36    .typeText('#textarea', 'line15')37    .pressKey('enter')38    .typeText('#textarea', 'line16')39    .pressKey('enter')40    .typeText('#textarea', 'line17')41    .pressKey('enter')42    .typeText('#textarea', 'line18')43    .pressKey('enter')44    .typeText('#textarea', 'line19')45    .pressKey('enter')46    .typeText('#textarea', 'line20')47    .pressKey('enter')48    .typeText('#textarea', 'line21')49    .pressKey('enter')50    .typeText('#textarea', 'line22')51    .pressKey('enter')52    .typeText('#textarea', 'line23')53    .pressKey('enter')54    .typeText('#textarea', 'lineUsing AI Code Generation
1import { ClientFunction, t } from 'testcafe';2test('Test', async t => {3    await t.typeText('textarea', 'test');4    await updateTextAreaIndent('textarea', 4);5    await t.expect('textarea').value === '    test';6});7const updateTextAreaIndent = ClientFunction((selector, indent) => {8    const textEditor = window['%hammerhead%'].sandbox.node.win.TextEditor;9    const textArea = document.querySelector(selector);10    return textEditor.updateTextAreaIndent(textArea, indent);11});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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
