From the course: Learning Selenium

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Clean test code with functions

Clean test code with functions - Selenium Tutorial

From the course: Learning Selenium

Start my 1-month free trial

Clean test code with functions

- [Instructor] There are just a couple more extractions I want to make in order to make the test cleaner and easier to read. Looking through the test again, I notice that there are multiple actions that are repeated. Those actions are finding the element and sending the keys to that element. So what I will do here is to break up these actions into methods in order to make my test more readable and reusable. I'll start by focusing on where we enter the user name and define a method to enter the user name. This method will take in a user name parameter. And in the body of the method, I will paste the two lines that enter the user name. Now, on lines 22 and 23, I can replace these with the name of the method and call that here, passing in the username parameter. Next I'm going to move on and extract these two lines into a method called enter_email, which will take in an email as a parameter. And in the body of this method, I will paste those two lines that enter the email, and then I can…

Contents