Forum Discussion

TestingHobo's avatar
TestingHobo
Contributor
10 years ago
Solved

How do i validate a URL redirect

Hi

 

I am currently trying to validate a URL redirect, we have a process that if you navigate to http on login it will redirect you to https.

I am using javascript but i am unalble to use indexOf in an if statement.

In short i want to know how i can say:

 

var Page = Sys.Browser("*").Page("*");
var url = Page.URL
IF (url == "https*")

{

//do something

Log.Message(url, "Page redirectd to https")

}

  • You can use a property checkpoint for the URL property:

     

    var redirected = aqObject.CheckProperty(Page, "URL", cmpStartsWith, "https://");
    // The checkpoint posts a log entry

    if (redirected) { // Do something } 

     

3 Replies

  • HKosova's avatar
    HKosova
    SmartBear Alumni (Retired)

    You can use a property checkpoint for the URL property:

     

    var redirected = aqObject.CheckProperty(Page, "URL", cmpStartsWith, "https://");
    // The checkpoint posts a log entry

    if (redirected) { // Do something } 

     

  • Ryan_Moran's avatar
    Ryan_Moran
    Valued Contributor
    var Page = Sys.Browser("*").Page("*");
    var url = Page.URL
    
    var searchresult = RegExp("^https.*$", "i").exec(url);
    if (searchresult && searchresult.index == 0) {
      Log.Message(url, "Page redirectd to https");
      //do stuff
    }

    Regular Expression Syntax

     

    You could replace https.* with a variable as well.

     

    var searchresult = RegExp("^" + someVar + "$", "i").exec(url);