Logging out and closing the browser

Taking out the trash

The process is now automated! Well done, you!

Let's still do some housekeeping and clean up after ourselves. Maria told us that after completing her task, she logs out and closes her browser. This might not come as a huge surprise for you anymore, but our robot can do this thing, too!

Let's add a new keyword Log out and close the browser and add it to our task.

So, two things. Log out. Close the browser. You already know about the Click Element keyword, so let's go with that for the logout. Pick again the element:

Log out element in the Inspector

Save the locator. The keyword should now look like this:

Click Element ready and in place

How do we close the browser? There's a keyword for that, too (thanks again, Selenium!), add that too.

Close Browser added


Tearing things down

Almost. One more detail before the class is dismissed. We want to ensure that the logout and closing of the browser happens even if some part of our process fails and the robot fails to reach the end of the task. To do it, we use a special Teardown section.

Toggle Teardown active on from the top of the task and add the Log out and close the browser keyword there by dragging it on the Teardown section.

Teardown in place

What if we decided to leave out the Teardown? In that case, the logout and closing of the browser would not happen if one of our keywords happened to fail during execution. Using the Teardown section and giving our keyword as the argument, we ensure that no matter what, at least the cleanup step always happens. Neat!

It is done!

Our robot is now finished.

If we run it, we will see that it logs out and closes the browser at the end. Such a polite robot!

You can now also check how you robot looks like in the flow view. Open flow view by clicking on the "Flow" button on the top of the editor. In the flow view, you can zoom and drill down into keywords and switch between tasks. The flow block diagram is generated directly from the robot code, so it is updated when you edit your robot and does not need or create any extra files in your robot folder.

Flow view

The flow view can be useful in particular for understanding the structure of complex robots, as well as for communicating how the robot works to experts and decision-makers.

What we learned

  • The Teardown section ensures your process does not leave a mess behind. Such as an open browser.