Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to ADD more characters to a text field input without clearing the input that is already there? #2942

Closed
Mo0rBy opened this issue Oct 10, 2022 · 5 comments
Labels

Comments

@Mo0rBy
Copy link

Mo0rBy commented Oct 10, 2022

I am trying to test a "Character validation" feature for a text input. The requirement is that no more than 1000 characters are allowed in the text box, when it is at the upper limit of 1000, the User should not be able to input anymore character into the field.

I am randomly generating a string of 1000 characters, asserting that my "0 characters remaining" message is shown, and then I want to assert that no more characters can be added to the input. To do this, I want to ADD 1 more character to the end of text that is in the input field, then assert that it is not there (User typed the character, but it has not been allowed into the input). My random string is letters only, so I am adding a "1" and then asserting that the "1" is not there.

My issue is that whenever I try and input something. The field get's completely cleared. Is there anyway to ADD this extra character to what is already in the input field, without having to input all 1000 characters again + the "1" character?

@wakaleo
Copy link
Member

wakaleo commented Oct 10, 2022

Use the sendKeys() function.

@Mo0rBy
Copy link
Author

Mo0rBy commented Oct 10, 2022

SendKeys() still clears the previous value. Let me try it again and check

@Mo0rBy
Copy link
Author

Mo0rBy commented Oct 10, 2022

Yes, I'm correct, using sendKeys() still clears the value that was previously entered into the text field. I've tried Enter() and SendKeys(). Found Press() on the Javascript documentation, but I don't believe that is available within the Java libraries.

This is my code:
Initially filling the text field:

String fieldInput = RandomStringUtils.random(1000, true, false);
actor.attemptsTo(Enter.theValue(fieldInput).into(MyPage.MyField).thenHit(Keys.TAB));

Then adding the extra "1" character:

actor.attemptsTo(SendKeys.of("1").into(MyPage.MyField).thenHit(Keys.TAB));

@wakaleo
Copy link
Member

wakaleo commented Oct 10, 2022

SendKeys uses the Selenium sendKeys() command, which shouldn't clear the field first (unless you are using a very old version of Serenity).

@Mo0rBy
Copy link
Author

Mo0rBy commented Oct 10, 2022

Apologies @wakaleo , I had an extra rogue line that was clearing it, you are correct, SendKeys() is the one. Thank you!

@Mo0rBy Mo0rBy closed this as completed Oct 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants