Ananthu R V
Ananthu R V

Reputation: 448

how to replicate browser crash for automation testing

I am currently working on a functionality were i am auto saving content while editing a post. The functionality is expected to work even on browser crash. My question is there a way to automate(selenium or similar) and test the browser crash.

Upvotes: 1

Views: 359

Answers (2)

Florent B.
Florent B.

Reputation: 42528

I would inject an exception to crash the window and work in a new window to check the recovery. It's not exactly a browser crash but close:

WebDriver driver = new FirefoxDriver();
driver.get("https://www.google.co.uk");

// crash the window
((JavascriptExecutor)driver).executeScript(
    "window.open();" +
    "window.stop();" +
    "setTimeout(function(){" +
      "document.open();" +
      "document.write('<script>throw new Error();</script>');" +
      "document.close();},0);");

// close the window
Object[] handles = driver.getWindowHandles().toArray();
driver.close();

// switch to the new window and reload the page
driver.switchTo().window(handles[1].toString());
driver.get("https://www.google.co.uk");

Upvotes: 1

Pankaj Kumar Katiyar
Pankaj Kumar Katiyar

Reputation: 1494

Few ways are:
1. Reload browser for multiple times or indefinitely.
2. Paste very big texts (text bigger than the size of input text fields) in input texts.
3. Click submit button multiple times in a quick succession.
4. Open many instances of same browser, reduce the available memory to be used by browser.
etc.. 

Hope this helps !!

Upvotes: 0

Related Questions