1

In e2e testing, I want to simulate user typing in a input field. My input field has a maxlength in it. I want the maxlength to be consider, but I have not succeed to find a solution to it. Here's what I've tried:

<input type="text" id="myField" maxlength="10" ng-model="myModel" />
<span>{{myModel}}</span>    

1) input("myModel").enter("ABCDEFGHIJKLMNOPQRSTUVWXYZ"). Both the myField input and the myModel model are set to "ABCDEFGHIJKLMNOPQRSTUVWXYZ". Expected result: "ABCDEFGHIJ"

2) element("#myField").val("ABCDEFGHIJKLMNOPQRSTUVWXYZ"). The myField input is set to "ABCDEFGHIJ". Which is perfect! But the myModel is null.

Do you guys have a solution for this? I don't want to use ngMaxlength since I want to prevent to use to typing more than 10 caracters.

Many thanks!

1 Answer 1

1

You could extend angular-scenario dsl and use a function similar to this one to inject a value in ngModelController

function typeIn(element, str) {
    var maxlength = parseInt(element.attr('maxlength'), 10);
    var value = element.val() + str;

    if (maxlength !== NaN) {
        value = value.substr(0, maxlength);
    }

    element.val(value);
    element.controller('ngModel').$setViewValue(value);
    element.scope().$apply();
}

http://jsfiddle.net/nxNm9/1/

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.