To order preconditions based on execution in an automated test, you must do the following:
Establish Pre-condition Execution: You first establish the order for your precondition in your test cases. This mostly can be made through metadata supported by your test framework to state which of the precondition should be executed before others.
The Testing dependency management: Nearly every testing framework supports a mechanism through which the developer can define dependency relationships between tests. By way of example, in TestNG, you will make use of a depends On Methods attribute to ensure that some of your pre-conditions are properly taken care of by others before running.
Sorting using priority tags: Using attributes such as @Priority or @Order, you can attach priorities or weights to your pre-conditions and execute them in the sequence you prefer.
Test Orchestration: Divide your pre-conditions into different methods or classes and call them according to their order. The well known testing frameworks Pytest uses the fixtures mechanism in order to handle the execution of preconditions.
Implement Your Own Sorter: If a framework doesn't provide direct support for sorting preconditions, implement an appropriate sorter defining and ordering explicitly what has to be done.
You can ensure that your tests are running in a logical and efficient order by using the tools offered by the framework for the test or even manually arranging pre-conditions.