I\'m getting the chrome didn\'t shut down correctly error message when I reopen a chrome browser in my selenium framework.
In the framework I\'m opening the browser
Did you set exit_type:Normal, I'm currently doing that before the test start, and or after the test ends and it Works. on C#
public static void FixChromeSingleProfile(string dataDir)
{
FileStream fs = new FileStream(dataDir, FileMode.OpenOrCreate);
StreamReader sr = new StreamReader(fs);
string json = sr.ReadToEnd();
sr.Close();
fs.Close();
dynamic jsonDe = JsonConvert.DeserializeObject(json);
if (jsonDe.profile.exit_type != "Normal")
{
jsonDe.profile.exit_type = "Normal";
string r = JsonConvert.SerializeObject(jsonDe);
StreamWriter sw = new StreamWriter(dataDir, false);
sw.Write(r);
sw.Close();
}
}
This solution is in Python and works 100% but you should be able to implement this in Java as well. I just call the close_windows
function every time I am finished using Selenium.
def close_windows():
windows = driver.window_handles
for w in windows:
driver.switch_to.window(w)
driver.close()
driver.quit()
close_windows()
As per your code it would be tough to analyze the reason behind the error chrome didn't shut down correctly without knowing your framework structure. Perhaps a more details about how code block was invoked (i.e. main() or TestNG) would have helped us.
Having said that there still seems some more factors to look at as follows :
As you are using an existing Chrome Profile through user-data-dir as per the documentation ChromeDriver - WebDriver for Chrome the path should point the profile directory as follows :
options.add_argument("user-data-dir=C:/Users/xw20/AppData/Local/Google/Chrome/User Data/Profile 2")
Here you can find a detailed discussion at How to open a Chrome Profile through Python
driver.close();
and always invoke driver.quit()
within tearDown(){}
method to close & destroy the WebDriver and Web Client instances gracefully.@Test
.