Print

Robot Framework Regular Expression Test and Keywords

In Selenium Robot Framework, we can use BuiltIn keywords to verify regular expression.  See the example below. 

 

Text version of this test case

 *** Test Cases ***

PatternTest
    Should Match Regexp    
 This email address is being protected from spambots. You need JavaScript enabled to view it.
     ^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$    'email validation'
    Should Match Regexp    192.168.1.1    ^([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.([01]?\\d\\d?|2[0-4]\\d|25[0-5])$    'IP Validation'
    Should Match Regexp        <("[^"]*"|'[^']*'|[^'">])*>    'Html Tag Validation'
    Should Match Regexp    ])*>    'Html Tag Validation'

Result Log 

Starting test: RegularExpressionTest.Regular-Expression-Test.PatternTest
20140726 15:57:19.465 :  FAIL : 'Html Tag Validation': '<html' does not match '<("[^"]*"|'[^']*'|[^'">])*>'
Ending test:   RegularExpressionTest.Regular-Expression-Test.PatternTest

The result indicated that "<html" is not a valid html tag, so the keyword "Should Match Regexp" failed. All other lines passed.