18 January 2026:


This forum is now archived and is in read-only mode. Please continue discussions on our improved new Sahi Pro Community forum.



Sahi Pro is an enterprise grade test automation platform which can automate web, mobile, API, windows and java based applications and SAP.

dynamic regular expression in _link

robyrobotrobyrobot Members
edited November -1 in Sahi - Open Source
Hi All,

I need to test if a page contains a link that match some regular expression builded by external data es:
var $username = "docente0001"; // I got "username0001" from a query to a excell file
_assertExisits(_link(/$username/, "is not a " + $username + "home page!");

When I run my test the assert always fails on a page that contains a link similar to this:

<a id="mylink">Wellcome docente0001 in your home page</a>

I need a regular expression because text inside link could change

Any ideas ?

Cheers

Roby

Comments

  • narayannarayan Administrators
    Roby you can convert a string to a regular expression via new RegExp(string)
    var $username = "docente0001"; 
    
    _assertExisits(_link(new RegExp($username)),  "is not a " + $username + "home page!");
    
  • narayan wrote:
    Roby you can convert a string to a regular expression via new RegExp(string)
    var $username = "docente0001"; 
    
    _assertExisits(_link(new RegExp($username)),  "is not a " + $username + "home page!");
    

    thanks for the fast reply narayan,

    it works fine for me now ;-)

    Cheers

    Roby
Sign In or Register to comment.