This is a migrated thread and some comments may be shown as answers.

Cann't launch the page that has encoded reserved characters in URL

3 Answers 20 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Yan
Top achievements
Rank 1
Yan asked on 13 Aug 2011, 01:41 AM
// Launch the page
ActiveBrowser.NavigateTo("http://localhost/myapp/object/display/ObjRef/%2F%2FMainSite%2F5100.MT1");

A decoded the URL string, "http://localhost/myapp/object/display/ObjRef///MainSite/5100.MT1", was sent to the browser and resulted in an error.

Thanks.
Yan

3 Answers, 1 is accepted

Sort by
0
Plamen
Telerik team
answered on 15 Aug 2011, 12:09 PM
Hello Yan,

I'm sorry you are running into this problem. It is a well known problem caused by the .Net logic we use and not by some implementation specific to Test Studio. The culprit is this URI class and more specifically:
By default, any reserved characters in the URI are escaped in accordance with RFC 2396. This behavior changes if International Resource Identifiers or International Domain Name parsing is enabled in which case reserved characters in the URI are escaped in accordance with RFC 3986 and RFC 3987.
  
As part of canonicalization in the constructor for some schemes, escaped representations are compacted. The schemes for which URI will compact escaped sequences include the following: file, http, https, net.pipe, and net.tcp. For all other schemes, escaped sequences are not compacted. For example: if you percent encode the two dots ".." as "%2E%2E" then the URI constructor will compact this sequence for some schemes. For example, the following code sample shows a URI constructor for the http scheme. 
  
Copy 
 Uri uri = new Uri("http://myUrl/%2E%2E/%2E%2E"); Console.WriteLine(uri.AbsoluteUri); Console.WriteLine(uri.PathAndQuery); When this code is executed, it returns the following output with the escaped sequence compacted.
  
Copy 
Previous customers have worked around the issue by creating a page with hyperlinks in it. By clicking a link with the URL, the issue was bypassed.
 
I hope this helps!

Best wishes,
Plamen
the Telerik team
Vote for Telerik Test Studio at the Annual Automation Honors Voting!
0
Adam
Top achievements
Rank 1
answered on 08 Oct 2013, 02:19 AM
This is a really frustrating bug.  Fortunately, you don't have to create a separate page with hyperlinks just to work around it.  Assuming your page has at least one anchor on it, the following extension method that we use should get you what you're needing.  It just hijacks an anchor, changes its href, and clicks it.  And of course if your home page has no hyperlinks, then you should be able to just as easily use jQuery (or plain JavaScript) to create and attach one). 

public static void GoToHash(this BaseTest B, string hash, string userLogin = BaseSettings.AutomatedTesterLoginValue)
{
    B.Manager.LaunchNewBrowser();
    B.ActiveBrowser.NavigateTo(BaseSettings.websiteRoot);
 
    B.ActiveBrowser.Actions.InvokeScript("var a = jQuery('a:visible:first');a.attr('href', '" + BaseSettings.websiteRoot + userLogin + hash + "');a[0].click();");
}
0
Velin Koychev
Telerik team
answered on 09 Oct 2013, 10:25 AM
Hi Adam,

Thank you for sharing this solution and helping others. We really appreciate it. 

I have also updated your Telerik points.

Regards,
Velin Koychev
Telerik
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
Tags
General Discussions
Asked by
Yan
Top achievements
Rank 1
Answers by
Plamen
Telerik team
Adam
Top achievements
Rank 1
Velin Koychev
Telerik team
Share this question
or