How to clear browser cache automatically in Selenium WebDriver?

后端 未结 5 1360
别那么骄傲
别那么骄傲 2021-01-17 17:30

How to clear browser cache before every test run? I tried with driver.manage().deleteAllCookies(); in setUp method after creating the driver instan

5条回答
  •  萌比男神i
    2021-01-17 17:53

    Using this post, How To: Execute command line in C#, get STD OUT results, I came up with this C# code to delete cookies (and as a side effect it deletes all IE browser data).

    public static void DeleteIECookiesAndData()
    {
        Process p = new Process();
        p.StartInfo.UseShellExecute = false;
        p.StartInfo.RedirectStandardOutput = true;
        p.StartInfo.FileName = "RunDll32.exe";
        p.StartInfo.Arguments = "InetCpl.cpl,ClearMyTracksByProcess 2";
        p.Start();
        p.StandardOutput.ReadToEnd();
        p.WaitForExit();
    }
    

    It isn't pretty at all, but it works. Maybe some pieces could be removed. (please let me know if you find a better way to do this).

提交回复
热议问题