0

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

2 Answers 2

1

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}
Sign up to request clarification or add additional context in comments.

1 Comment

#jiri janous , it was fine.. for input alpha numeric validation using robot framework can you please try to help ex: input:32003 valid input 2: 200F9 INVALID INPUT3: 32990237449213040129348091283408719328409439184 LENGTH<=32
0

you can use regex to validate the ips.

import re

def isValidIp(ip):
    pattern = "((\d{1,3}).(\d{1,3}).(\d{1,3}).(\d{1,3}))"

    if re.match(pattern, ip):
        return True
    else:
        return False

test:


test = ["123.123.123","randomstring","123.a54.12","1234.12.1111"]

for item in test:
    print(isValidIp(item))

True
False
False
True

1 Comment

where i can place this robot code settings or variables or test cases or keywords

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.