Forum Discussion

sankarinms's avatar
sankarinms
New Contributor
10 years ago

Regular expressions/property value inside a data source

How to use regular expression/property value inside data source. For example, I have an excel with the following entried:

href
http://staging?q=test
http://staging?q=test1

I need to replace the entries to http://${#Project#activeEnvironment}?q=test so that I can assert href tag using the datasource when run against different environment. Right now the assertion fails and don't see the property value getting passed. Please let me know

Thanks in advance
Sankari

2 Replies

  • sankarinms's avatar
    sankarinms
    New Contributor
    Thanks for your response


    I figured out how to pass property value inside a data source:

    In the custom properties when creating an environment i set the value of activeEnvironment=staging. Then created another environment named as production and set the value of activeEnvironment=prod

    Then in project level i declared a custom property activeEnvironment. In testcase level in setup script , did the following:

    def activeEnvironment=context.expand('${#Project#activeEnvironment}')
    log.info "activeEnvironment>> "+ activeEnvironment

    Then in excel which is a data source gave values like:
    http://${#Project#activeEnvironment}/test1


    During runtime the url gets replaced with the actual environment value . If it is staging it will be http://staging/test1
    If it is prod it is http://prod/test1

    Similarly how to use regular expression inside a data source ex: excel with many row. for example: http://(?s).*/test in the
    datasource and create an xpath assertion with expected value : ${DataSource#Expected result} and select allow wildcard, it does not recognized that the value provided in the excel is a regular expression. It fails saying match not found. Please let me know.