Chromedriver not deleting scoped* dir in temp folder after test is complete

后端 未结 6 1585
野性不改
野性不改 2021-02-07 09:26

With latest chromedriver.exe running into out of disk space issues as chromedriver is not deleting the folder named scoped_* at the end of the execution. It is occupying almost

6条回答
  •  北荒
    北荒 (楼主)
    2021-02-07 10:11

    I managed this by adding deletion of temp folders that begins with "scoped_dir" after quitting driver like:

     public static void teardown_()
            {
                // quit driver
                if (driver != null)
                    driver.Quit();
    
                // delete all "scoped_dir" temp folders 
                string tempfolder = System.IO.Path.GetTempPath();
                string[] tempfiles = Directory.GetDirectories(tempfolder, "scoped_dir*", SearchOption.AllDirectories);
                foreach (string tempfile in tempfiles)
                {
                    try
                    {
                        System.IO.DirectoryInfo directory = new System.IO.DirectoryInfo(tempfolder);
                        foreach (System.IO.DirectoryInfo subDirectory in directory.GetDirectories()) subDirectory.Delete(true);
                    }
                    catch (Exception ex)
                    {
                        writeEx("File '" + tempfile + "' could not be deleted:\r\n" +
                                "Exception: " + ex.Message + ".");
                    }
                }
            } 
    

    Hope it helps!

提交回复
热议问题