all project files are created in the src folder of the Eclipse project:
The src folder includes
- test classes (HomePageScripts.java)
- page object classes (HomePage.java and ResultsPage.java)
- any other project files
This can be corrected easily by creating folders in the project for specific purposes:
Example
framework folder
page object class folder
locator class folder
test scripts folder
Solution
Before working on the project folder structure, lets investigate a bit the project:
- source java files are stored in the src folder
- class files (created when the source files are compiled; the class files are needed for executing the code) are stored in the bin folder
The classpath file has 2 rules for this:
- first rule says that the source files are in the src folder
- the second rule says that, by default, all class files are created in the bin folder
Multiple steps are needed for getting the correct project structure:
1. remove the existing classpath entries
2. create a test folder under the src folder: src/test
3. add the following classpath entry
This rule means that for all java files from src/test, the class files will be created under target/test-classes.
4. build the project.
the target/test-classes folders are created as a result of the project build:
5. create the com.testproject.java package under the src/test folder:
6. move the HomePageScripts.java file to src/test/com/testproject/java
7. build the project
8. the following folders are added under target/test-classes: com/testproject/java
the HomePageScript.class file is stored in target/test-classes/com/testproject/java:
9. similarly, create a main folder under src
10. add a new entry to classpath for the src/main folder
This rule says that for all java files stored under src/main, the class files will be created under target/classes.
11. build the project
12. the target/classes folder is created
13. add the following package to src/main: com.testproject.java.framework.pageobject
14. move the page object class (HomePage.java) to the src/main/com/testproject/java/framework/pageobject
15. build the project and confirm that the class file is created in target/classes/com/testproject/java/framework/pageobject:
16. add the following package to src/main: com.testproject.java.framework.locators
17. move the Locators.java file to src/main/com/testproject/java/framework/locators
18. build the project
19. confirm that the Locators.class file is created in target/classes/com/testproject/java/framework/locators
20. open all java files and add the packages where different classes are stored:
21. run the project
At this moment, the project structure is much better than when we started:
SRC
MAIN --> folder used for framework files
COM
TESTPROJECT
JAVA
FRAMEWORK
LOCATORS
Locators.java
PAGEOBJECTS
HomePage.java
TEST --> folder used for the test scripts
COM
TESTPROJECT
JAVA
HomePageScripts.java