"Programs should be written for people to read, and only incidentally
for machines to execute".
-- "Structure and Interpretation of Computer Programs" by Abelson and Sussman
UI automation code is just another piece of "code" hence all the code best practices applies in the same way.
If I have to pick one thing, I would say code shouldn't read like code, it should read like a natural language in the business domain(DSL) on higher layers(test scripts/page object public methods in the automation framework).
All the statements inside a function should be on the same level of abstraction.
Example:
class AddAttendeePage
def add_attendee_with_details
fill_in('user_email',with:'[email protected]')
fill_in('user_first_name', with: 'test')
fill_in('user_last_name', with: 'test')
fill_order_form
click_add_attendee
end
def fill_order_form
# ...
end
def click_add_attendee
# ...
end
end
The add_attendee_with_details method here brakes the rule.
The fill_in(‘order_user_email’, :with => ‘[email protected]’)
part is more detailed than the fill_order_form
part, so the code inside the add_attendee_with_details
written on a different level of abstraction.
All the basic 'code' semantics(loops/if/switch) should be deeply buried in the lowest layers of the framework.
If NOT, these are one of most obvious code smells to me that code is not structured properly in different layers in the framework which makes code maintenance a hell due to multiple reasons on multiple levels in the long term.