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

How to initialize page to a known state?

7 Answers 104 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Bruce Hochstetler
Top achievements
Rank 2
Bruce Hochstetler asked on 20 Mar 2009, 10:32 PM
Hi,

I have a page that retains its state between runs. So for instance in my page it has multi-level tabs and a splitter, if the user closes the top of the page via the splitter then closes the browser; on restart I load the page in the same state, splitter pane closed. This is also the same for the tabs; when it's restarted, the same tab selection is made. All of this is done with cookies (maybe theres a way to clear the cookies before navigating!)

How would I place the page into a known state?   Ideally I would want the splitter pane opened, and tab selections on tab 0, then start testing from that point on.

Thanks,
Bruce

7 Answers, 1 is accepted

Sort by
0
Missing User
answered on 20 Mar 2009, 11:11 PM
Hello Bruce Hochstetler,

Currently WebUI Test Studio does not have built in features for handling cookies, but it is something we are looking to implement in a future version of the product.

However, you can delete the cookies with a custom code step. Creating a custom code step is described in this video: http://www.artoftest.com/VideoPlayer.aspx?video/WorkingWithCode.swf

From here you can add the following code:

System.Net.CookieCollection cookies = ActiveBrowser.Cookies.GetCookies("MyCookiesURL");
foreach (System.Net.CookieCookie cookie in cookies){
ActiveBrowser.Cookies.DeleteCookie(cookie);}

Or if they are local host cookies the following line will do:
Manager.ActiveBrowser.Cookies.DeleteCookie("local");

For more information on cookies, please refer to this guide under the Cookie Support heading: http://www.artoftest.com/Resources/WebAii/Documentation/topicsindex.aspx

Please let us know if this is what you are looking for or if there is something else you had in mind.

Best wishes,
Nelson Sin
the Telerik team


Check out Telerik Trainer , the state of the art learning tool for Telerik products.
0
Bruce Hochstetler
Top achievements
Rank 2
answered on 20 Mar 2009, 11:47 PM
Hi Nelson Sin,

Thanks for the quick response. I took a look at the demo. So what I need to do is add a code step prior to navigating to my page, but I don't see how that will work if I already navigated to the page first. BTW, I'm testing with 'localhost' so I'm trying the following as you suggested; if I can figure out where to put it.

Manager.ActiveBrowser.Cookies.DeleteCookie(
"local");

Any ideas?

Also when I add a code page, the template file I get includes 'using Microsoft.VisualStudio.TestTools.UnitTesting;' which is generating an error. I looked for it with the 'Add Reference' dialog, but it's not obvious which component it is. I have VS2008 PRO installed. I've been poking around on the web and it seems this assembly is part of the team addition; I tried including Microsoft.VisualStudio.QualityTools.UnitTestFramework, but this didn't resolve the issue.

Sorry I put the assembly in my web app and not the test project references... so I resolved that problem.

Thanks,
Bruce
0
Bruce Hochstetler
Top achievements
Rank 2
answered on 21 Mar 2009, 12:09 AM
Hi Nelson Sin,

I went ahead and added a code-step and placed it after the navigate step. When I try to run test I get an error...

"Can't execute tests with code behind outside Visual Studio!"

What I'm I doing wrong here?

Still not sure where to put the clear cookie command?

Thanks,
Bruce
0
Faris
Top achievements
Rank 1
answered on 21 Mar 2009, 04:56 AM
Bruce -

Compile your project and try executing your test from the TestView. [Test->Windows->TestView]. Does that solve your issue?
0
Bruce Hochstetler
Top achievements
Rank 2
answered on 23 Mar 2009, 03:47 PM
Hi,

Yes that will work, but it does not explain the issue. With this solution, I can't test from the Test Explorer as I generate the test.

Thanks,
Bruce
0
Konstantin Petkov
Telerik team
answered on 24 Mar 2009, 01:44 PM
Hello Bruce,

You are correct about this problem. We were able to fix the issue so please download the just uploaded latest internal build, uninstall the previous build and install this one. Please, accept our apologies for the temporary inconvenience.

Can you please confirm you don't get the error with this new build on your end? Thank you!

Greetings,
Konstantin Petkov
the Telerik team

Check out Telerik Trainer , the state of the art learning tool for Telerik products.
0
Bruce Hochstetler
Top achievements
Rank 2
answered on 24 Mar 2009, 08:43 PM
Hi Konstantin,

Yes indeed the latest build (2009.1.324) fixes the problem. I'm now able to do the quick test feature instead of running the test from 'Test View'.

Also the page initialization that I was originally asking about works as suggested. Initially I wasn't sure if it should be the first step performed or immediately after the navigate. It seemed to me that clearing the cookies prior to navigating shouldn't work - it just didn't seem right. Anyway, the first step I perform is the cookie cleanup and needless to say I was somewhat surprised it worked!

Thanks,
Bruce
Tags
General Discussions
Asked by
Bruce Hochstetler
Top achievements
Rank 2
Answers by
Missing User
Bruce Hochstetler
Top achievements
Rank 2
Faris
Top achievements
Rank 1
Konstantin Petkov
Telerik team
Share this question
or