Protractor (and more widely, Selenium) is generally meant for automating the kinds of tests a non-technical end user would be capable of performing themselves. Having said that, there are times when it may be useful to simulate various error conditions on the server. You have a couple options:
onPrepare script: Use the
onPrepare
script to do as much backend setup work as you can, if it's possible to do so ahead of time. Set theonPrepare
property inside of your protractor config file (see sample here) to point to your prepare script, where you can set up records in the database, create files, or whatever else you may need to do.Use protractor.addMockModule: This allows you to essentially mock your backend API by adding a module to load before Angular whenever Protractor.get is called. See the blog post for a sample (search for "Beyond the basics"):
http://product.moveline.com/testing-angular-apps-end-to-end-with-protractor.htmlConfigure test-only routes on the server: As a last resort, you can configure some routes on the server that are only accessible in a dev environment that perform whatever backend processing you might need from within your end-to-end test. For instance, if you're using Node.js with Express.js, you might do something like the below.
Test-only routes:
// Store your server-side e2e methods in this file
var e2eBackend = require('./test/e2eBackend');
if (app.get('env') === "development") {
app.get('/e2e/simulateCrash', e2eBackend.simulateCrash);
// etc.
}