Let's say you are automating the demo application. There could be many scenarios you want to automate, such as searching for products, adding products to the shopping cart, checkout, returns, and so on. For all these actions, one common thing is to have to log into the demo application in each of the test cases. So, logging into the application in every test case of yours will increase the overall test execution time significantly. To reduce the execution time of your test cases, you can actually skip signing in for every test case. This can be done by signing in once and writing all the cookies of that domain into a file. From the next login onward, you can actually load the cookies from the file and add them to the driver.
To fetch all the cookies that are loaded for a web page, WebDriver provides the following method:
driver.manage().getCookies()
This...