Trying to grab current url during Web test

2 posts, 0 answers
  1. April
    April avatar
    10 posts
    Member since:
    Oct 2016

    Posted 08 Nov 2018 Link to this post

    I'm trying to grab the current url during a test and append some text on the end of it, to navigate to a certain page.

    For context, we have both a production and debug server. I figured it would be easier instead of toggling between the debug/prod urls in a NavigateTo step (which would also defeat the purpose of continuous integration because we would have to manually change it).

    However, what I came up with, I'm getting a compiler error:

    ...tstest.cs(56,33) : error CS0103: The name 'HttpContext' does not exist in the current context

    The namespace that is supposed to be used according to Microsoft is System.Web. 

    This is the code block that I'm using:

                      string currentUrl = HttpContext.Current.Request.Url.AbsoluteUri;
                
           //Append the /share to the url
           string urlWeWant = currentUrl + "/share";
                
           //Navigate to the url
           ActiveBrowser.NavigateTo(urlWeWant);
  2. Elena
    Admin
    Elena avatar
    1155 posts

    Posted 09 Nov 2018 Link to this post

    Hi April,

    I reviewed the shared resource you have referred to and it doesn't seem to be working in the context you intend to use that. As far as I understood this can be used for individual HTTP requests. 

    Anyways, what will be required for you to cover the current requirement and take the current URL, is the Browser class and its Url property. 

    Apart from that, I would like to share an article with you explaining how you could use BaseURL in Test Studio as I guess this will be of interest for you. 

    I hope the shared notes will be useful for you. And, of course, in case you have any troubles or further questions, please let me know.

    Regards,
    Elena Tsvetkova
    Progress Telerik
     
    The New Release of Telerik Test Studio Is Here! Download, install,
    and send us your feedback!
Back to Top