From the course: Learning Selenium
Unlock the full course today
Join today to access over 24,100 courses taught by industry experts.
Clean test code with variables - Selenium Tutorial
From the course: Learning Selenium
Clean test code with variables
- [Instructor] This chapter is all about design principles and how to create tests that are reusable and maintainable over time. Having clean and readable test is one good way to make that happen. Whenever possible try to minimize the lines of code per test class and to not repeat steps over and over. If after writing a test there are some lines that are repetitive, this is an indication that they can be extracted into reusable variables and methods. Let's take a deeper look at the test that we have been working on in this course, and see if there's anything that would be good to extract. First I notice that there is a lot of string input when sending keys to the elements on lines 14, 17, 20, and 28. It is a good idea to extract their strings into variables that they can be easily reused in the future and changed later if needed. I'll do that now starting with the user name. At the top of my class I'm going to define a global variable called username, and what I'm going to do is copy…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.