Luis Pablo Lopez Luis Pablo Lopez - 2 months ago 7x
AngularJS Question

Protractor: How to expect browser url to equal url that have an id after registering new user?

I'm making some tests in Protractor and encountered a little problem:

I made a test to register a new user, when I finish registering it the url will be something like this:


So, my question is, how can I manage to get the ID of the new user to get a true in my test? Something like this:


How can I do this? If it's possible of course.


In your case, User_Id will be generated dynamically. So you need to write some customized code to pick the new user_id and use it in expect condition. You can follow below code snippet:


      var startIndex=(url.indexOf("user/"))+5;
      var endIndex=(url.indexOf(startIndex))+2;
      var user_id=url.substr(startIndex,endIndex);
      //it will return exactly user_id value