All selenium tests create profiles on the temp
folder(temporary directory) and browsers apart from firefox spawn separate
processes(.exe's) that are not tied with the java process that spawns selenium.
driver.quit() usually does the trick of
clearing the temp folders and kills the processes associated with the tests.But
there has been several issues around this and it does not work particularly
with older versions of selenium webdriver.
As per Issue 1934 the firefox problem of deleting
the temp folders seems to have been solved.But it does not work in standard
manner for other browsers. Stackoverflow has many
questions related to this and the only reasonable way to solve this is to clear
the temp folder and kill the process by external means.
Again if we write boilerplate code using Java File I/O to
delete files in temp folder, it is a pain to recurse and delete all the files
and also the folders. Fortunately Apache Commons IO has a way to deal with
this.I have a made a test cleanup method of my own which deletes all files from
temp ignoring the ones that cannot be deleted and kills the process names that
you specify to it.
Link to the code :
https://github.com/Madusudanan/Selenium/blob/master/TestCleanup.java
Let me know in case of any suggestions or issues.
Let me know in case of any suggestions or issues.