Optimization Techniques: Part 2

Discover what you can do with ternary operators and environment variables in Selenium and try them out yourself.

Avoid if-else block

Usually, programmers write test scripts in a similar fashion to application coding. Though there is nothing with this approach but the simpler and more concise code yields easier to read test scripts, which ultimately helps in debugging. Therefore, it advised writing one line of test statements for one user operation. A good example of this would be the use of a ternary operator ? :, which cut shorts 7 lines of code statements to only 3 as demonstrated below:

Get hands-on with 1200+ tech skills courses.