Clearing Cache

10 posts, 0 answers
  1. Amardeep
    Amardeep avatar
    7 posts
    Member since:
    Feb 2013

    Posted 23 Sep 2013 Link to this post

    HI,

    I am currently writing a test case to open the browser and select a database in the application. When I run the test first time it put the vale in the textboxes and then select the database.

    But runnig the test second time the value selected in previous run is there and my test fails. Is there a way where the test is run every time from the start irrespective what has been run previously. I guess there should be some way to cleanup the test which is ran previosly. 

    Thanks
    Amar
    //Use ClassInitialize to run code before running the first test in the class
          [ClassInitialize()]
          public static void MyClassInitialize(TestContext testContext)
          {
          }
     
          /// <summary>
          /// Use TestInitialize to run code before running each test
          /// Initializes WebAii manager to be used by the test case.
          /// If a WebAii configuration section exists, settings will be
          /// loaded from path. Otherwise, will create a default settings
          /// object with system defaults.
          ///
          /// Note: We are passing in a delegate to the VisualStudio
          /// testContext.WriteLine() method in addition to the Visual Studio
          /// TestLogs directory as our log location. This way any logging
          /// done from WebAii (i.e. Manager.Log.WriteLine()) is
          /// automatically logged to the VisualStudio test log and
          /// the WebAii log file is placed in the same location as VS logs.
          ///
          /// If you do not care about unifying the log, then you can simply
          /// initialize the test by calling Initialize() with path parameters;
          /// that will cause the log location to be picked up from the config
          /// file if path exists or will use the default system settings (C:\WebAiiLog\)
          /// You can also use Initialize(LogLocation) to set a specific log
          /// location for this test.
          /// </summary>
          [TestInitialize()]
          public void MyTestInitialize()
          {
              #region WebAii Initialization
     
               
     
              // Pass in 'true' to recycle the browser between test methods
              Initialize(false, this.TestContext.TestLogsDir, new TestContextWriteLine(this.TestContext.WriteLine));
     
              // Set the current test method. This is needed for WebAii to discover
              // its custom TestAttributes set on methods and classes.
              // This method should always exist in [TestInitialize()] method.
               SetTestMethod(this, (string)TestContext.Properties["TestName"]);
     
              _telerikBrowser = new TelerikBrowser();
              _app = _telerikBrowser.App;
              _telerikButton = new TelerikButton(_app);
              _telerikTextBox = new TelerikTextBox(_app);
              _telerikTextBlock = new TelerikTextBlock(_app);
              #endregion
     
              //
              // Place any additional initialization here
              //
     
     
          }
     
          // Use TestCleanup to run code after each test has run
          [TestCleanup()]
          public void MyTestCleanup()
          {
     
              //
              // Place any additional cleanup here
              //
     
              #region WebAii CleanUp
     
              // Shuts down WebAii manager and closes all browsers currently running
              // after each test. This call is ignored if recycleBrowser is set
              this.CleanUp();
     
              #endregion
          }
     
          //Use ClassCleanup to run code after all tests in a class have run
          [ClassCleanup()]
          public static void MyClassCleanup()
          {
              // This will shut down all browsers if
              // recycleBrowser is turned on. Else
              // will do nothing.
     
              ShutDown();
          }
     
          #endregion
     
          /// <summary>
          /// Method to add the different values for selecting the PDB by selexting different control in TelerikCommon
          /// </summary>
          [TestMethod]
          public void AddNewPdbSelector_ValidPDB_MethodSuccessful()
          {
              String PDB = "Athene1_DB";          
               System.Threading.Thread.Sleep(4000);
               
              //click the plussy plus sign
              _telerikButton.ClickButton(ControlsDefinition.PdbAddButton);
     
              //refresh
              _app.RefreshVisualTrees();
              //populate controls
              _telerikTextBox.PutValueToTextBox(ControlsDefinition.PdbHostNameAssociatedLabelText, "AB-M4500", true);
              _telerikTextBox.PutValueToTextBox(ControlsDefinition.PdbInstanceNameAssociatedLabelText, " ", true);
              _telerikTextBox.PutValueToTextBox(ControlsDefinition.PdbInstancePortAssociatedLabelText, "0", true);
              _telerikTextBox.PutValueToTextBox(ControlsDefinition.PdbNameAssociatedLabelText, "Athene1_DB", true);
              // log a message
     
              //click the button
              _telerikButton.ClickButton(ControlsDefinition.PdbCommitButton, 4000);
     
              //refresh
              _app.RefreshVisualTrees();         
     
     
          }
    ?
  2. Daniel
    Daniel avatar
    13 posts
    Member since:
    Aug 2013

    Posted 23 Sep 2013 Link to this post

    Quick search looks like you can clear temp files, cookies, and history using the ArtOfTest framework.  Place in your before/cleanup section.

    http://www.telerik.com/automated-testing-tools/community/forums/test-studio/general-discussions/automate-browser-refresh-using-simulate-user-typing.aspx (shows browser refresh and clearing cookies, temp files, and history with code)

    http://www.telerik.com/automated-testing-tools/support/documentation/online-api-reference/html/M_ArtOfTest_WebAii_Core_Browser_ClearCache.htm

    Hope that helps!
  3. Amardeep
    Amardeep avatar
    7 posts
    Member since:
    Feb 2013

    Posted 24 Sep 2013 Link to this post

    Thanks,

    I tried to use it in TestCleanup but I am getting error:  "object reference not set to an instance of an object"


            [TestCleanup()]
            public void MyTestCleanup()
            {

                //
                // Place any additional cleanup here
                //

                #region WebAii CleanUp
              
                // Shuts down WebAii manager and closes all browsers currently running
                // after each test. This call is ignored if recycleBrowser is set
                Initialize();
                ActiveBrowser.ClearCache(ArtOfTest.WebAii.Core.BrowserCacheType.Cookies);
                ActiveBrowser.ClearCache(ArtOfTest.WebAii.Core.BrowserCacheType.History);
                ActiveBrowser.ClearCache(ArtOfTest.WebAii.Core.BrowserCacheType.TempFilesCache);
                this.CleanUp();

                #endregion
            }

    Thanks
    Amar

  4. Boyan Boev
    Admin
    Boyan Boev avatar
    1045 posts

    Posted 24 Sep 2013 Link to this post

    Hi Amardeep,

    Thank you for contacting us.

    The code you are using is absolutely correct and it should clear all these types of cache.

    Where do you receive the exception (what row)? Please send us the entire trace log so we can investigate further.

    Hope to hear from you soo.

    Regards,
    Boyan Boev
    Telerik
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
  5. Amardeep
    Amardeep avatar
    7 posts
    Member since:
    Feb 2013

    Posted 24 Sep 2013 Link to this post

    Hi,

    The error is coming on the second row of the TestCleasnUp class :
      ActiveBrowser.ClearCache(ArtOfTest.WebAii.Core.BrowserCacheType.Cookies);

    Sorry i don't have the trace file yet.

    Thanks
    Amar
  6. Boyan Boev
    Admin
    Boyan Boev avatar
    1045 posts

    Posted 25 Sep 2013 Link to this post

    Hello Amardeep,

    In order to assist you best we really need the trace log.

    Please take your time, get the the trace log and update this ticket accordingly. 

    Hope to hear from you soon.

    Regards,
    Boyan Boev
    Telerik
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
  7. Chunks
    Chunks avatar
    17 posts
    Member since:
    Nov 2011

    Posted 08 Oct 2013 Link to this post

    It appears you are trying to delete cookies , I vaguely remember running into this problem, I think I was successful with CookiesManager.DeleteCookie(url) method . I hope this helps!
  8. Boyan Boev
    Admin
    Boyan Boev avatar
    1045 posts

    Posted 09 Oct 2013 Link to this post

    Hello Chunks,

    Thank you for sharing your knowledge. We really appreciate it. 

    Regards,
    Boyan Boev
    Telerik
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
  9. Koonal
    Koonal avatar
    1 posts
    Member since:
    Aug 2011

    Posted 15 Sep 2014 Link to this post

    Hi All,

    I found this code on the net and it works fine:

    //Temporary Internet Files

    System.Diagnostics.Process.Start("rundll32.exe", "InetCpl.cpl,ClearMyTracksByProcess 8")

    //Cookies()

    System.Diagnostics.Process.Start("rundll32.exe", "InetCpl.cpl,ClearMyTracksByProcess 2")

    //History()

    System.Diagnostics.Process.Start("rundll32.exe", "InetCpl.cpl,ClearMyTracksByProcess 1")

    //Form(Data)

    System.Diagnostics.Process.Start("rundll32.exe", "InetCpl.cpl,ClearMyTracksByProcess 16")

    //Passwords

    System.Diagnostics.Process.Start("rundll32.exe", "InetCpl.cpl,ClearMyTracksByProcess 32")

    //Delete(All)

    System.Diagnostics.Process.Start("rundll32.exe", "InetCpl.cpl,ClearMyTracksByProcess 255")

    //Delete All – Also delete files and settings stored by add-ons

    System.Diagnostics.Process.Start("rundll32.exe", "InetCpl.cpl,ClearMyTracksByProcess 4351")
  10. Boyan Boev
    Admin
    Boyan Boev avatar
    1045 posts

    Posted 16 Sep 2014 Link to this post

    Hi Koonal,

    I am glad you have found a solution and thank you for sharing it with other customers.

    We really appreciate it.

    Regards,
    Boyan Boev
    Telerik
     
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
     
Back to Top