If / else condition for char length

hi, i’m new with this tools
i tried to make a test case in this website Execute Automation

what i want to know, is there any possible to make a test case for check input length in username like if the char input >40 i want to show message error

what should i do ?
i type the username and then i get the value or what ?

thanks before

Hi Jimmy,

Try this:

//lets say you will going to use this string value as your input
String input = "qweasdzxcqweasdzxc"

//check if >40
Assert.assertTrue(input.length() < 40)
if > 40 the test will stop and will give you a failed result
else test will continue

if (input.length() < 40)
     WebUI.setText(findTestObject("your_input_field"), input)
     //throw your error

Hope that helps. . . :slight_smile:


what is assert ? it’s that custom keyword ?

Assert’s are checks, it is a class. . .

there’s a lot of methods inside… Try to play with it…

you can use it by importing junit.framework.assert

import junit.framework.Assert

ok ok. i get it :slight_smile:
thanks a lot Arnel


If that helps you, don’t forget to mark it as a solution to this problem or give a like for future users to use this as a reference if they encounter the same scenario. . .

Thanks. . . .

yeah i tried first, if is success then i’ll mark it as a solution

sorry Arnel
i wanna ask about assert

String input = “admin”

WebUI.setText(findTestObject(‘Page_Execute Automation/input_Login_UserName’), input)

Assert.assertFalse(input.length() > 3)

this is how to use assert to get error result ?

Just a little refactoring from your code. . .

String input = “admin”

Assert.assertFalse(input.length() > 3)

WebUI.setText(findTestObject(‘Page_Execute Automation/input_Login_UserName’), input)

Checks or asserts should happen first before the event. . . . but depends on some cases...
You need to check if the condition is true or false before proceeding to the next step.

Works like an if / else statement because it compares and accept bool values but it is compressed into a one-liner code.

Hope that answers your question . . .:slight_smile:

ok thanks
you really helped me


You’re welcome. . .