How to validate IP address using Robot Framework
Example: 192.168.101.12
Conditions:
- Number of characters
- String should not exceed 15 characters
- Allow only numeric characters
Advertisement
Answer
Builtin library has a keyword for matching regexes. You can use Should Match Regexp to validate the ip. Here is an example I made with a regexp from this answer
JavaScript
x
9
1
***Variables***
2
${correct_ip} 192.168.101.12
3
${false_ip} 999.999.999.999
4
${ip_regexp} ^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]).){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$
5
*** Test Cases ***
6
test
7
Should Match Regexp ${correct_ip} ${ip_regexp}
8
Should Not Match Regexp ${false_ip} ${ip_regexp}
9