Protractor Hooks can be used to write code which will automatically executed when running tests. Specifically we can write before and after hooks for our protractor tests. We can use before hooks to execute code before any given test is executed and similar the same concept would apply to a test for the after hook. The after hook can be used to run code after a test has finished running.
Protractor Hooks Video Tutorial
As part of the before hook we can write code to help with the setup of tests. Similarly for after hooks we can write code to help clean up tests.