How to validate IP address using Robot Framework

Issue

How to validate IP address using Robot Framework

Example: 192.168.101.12

Conditions:

  1. Number of characters
  2. String should not exceed 15 characters
  3. Allow only numeric characters

Solution

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

***Variables***
${correct_ip}    192.168.101.12
${false_ip}      999.999.999.999
${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])$
*** Test Cases ***  
test 
    Should Match Regexp    ${correct_ip}    ${ip_regexp}
    Should Not Match Regexp    ${false_ip}    ${ip_regexp}

Answered By – Jiri Janous

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published