I think you are missing out the definition of "Framework"
A framework is comprised of a combination of practices and tools that are designed to help QA professionals test more efficiently.
These guidelines could include coding standards, test-data handling
methods, object repositories, processes for storing test results, or
information on how to access external resources.
While these are not mandatory rules and testers can still script or
record tests without following them, using an organized framework
typically provides additional benefits that would otherwise be missed
So test frameworks are not just folder structures, it defines an overall process, tool, rules, technologies, coding standards, and so many stuff
Why we need a framework?
It makes code maintainability pretty easy. Once you have a framework that is efficient, you can code in parallel with high efficiency. For instance, you write code for drop-down selection and another engineer can reuse the code.
If you didn't have an efficient framework(naming convention and directory structure), the engineer should waste his/her effort in finding a solution that was already found out.
Why can't we reuse framework?
That is how all frameworks are being built, we take up existing frameworks and leverage it to create frameworks that are suitable for our project and team. For example TestNG, robot framework, etc.
All the test directory structures for UI tests are almost similar. Most uses page object model with folder structure like util, common, resource, report, etc. We just make changes according to different projects.
Why can't we have one fit solution?
The framework depends on organizational decisions and project complexity. For instance, the organization wants to save money by moving from VMS to containers. They want to run the selenium grid test in containers than in VMs, or sometimes the decisions may be to use the cloud.
So you have to investigate how the test-framework could be made ready for being put in CI/CD or delivering the additional requirements.
But in all cases, there will be a base framework from where we start building it.
And also test frameworks are company proprietary asset, it comes under intellectual property. You can't just share it with the public, the same as any other source code.
How to create an efficient framework?
Start from the base framework, learn from mistakes, keep evolving the solutions.
Most importantly, fail fast, meaning that you should realize the inefficiency of your framework faster. Analyze the drawback and make changes quickly, grow your test suites slowly till you are confident about the implementation.
Any Frameworks recommendation?
The framework depends on project, budget, organizational decisions and many such things. And as mentioned, frameworks are not just directory structure.
Recommendation for directory structure could be taken from GitHub or any such open source repositories. But you have to develop it in the ways you need
- So in your case, you have the base framework as testng+selelnium
- You can leverage it to a common reusable generic framework by segregating your reusable code.
Eg: in one test file you have a code to read CSV, instead of keeping it in that specific file keep in a separate package called commons so others can reuse your logic when needed
- Try to see if you can add data-driven testing in it
- Separate the project to Page objects
- When using third party tools keep the code in a different package called utils, so that others can reuse it
And mostly, you learn more as you start to do things and when things fail. Frameworks are not final, it is always evolving so don't be scared to make things go wrong.