Creating Selenium test cases can result in an unmaintainable project. One of the reasons is that too many duplicated code is used. Duplicated code could be caused by duplicated functionality and this will result in duplicated usage of locators. The disadvantage of duplicated code is that the project is less maintainable. If some locator will change, you have to walk through the whole test code to adjust locators where necessary. By using the page object model we can make non-brittle test code and reduce or eliminate duplicate test code. Beside of that it improves the readability and allows us to create interactive documentation. Last but not least, we can create tests with less keystroke. An implementation of the page object model can be achieved by separating the abstraction of the test object and the test scripts.
- code reusabity
- Code maintainability
- Object Repository
- Readability
- Efficient & Scalable
- High Setup Time & Effort
- Skilled labor
- Specific
The overall project structure should look like this now:
The files we should be interested in at this point are:
- Base.py base file defines all the basic function of selnium which is used in this project.
- locators.py locator file defines all the locators used in this project.
- pages.py Page file defines all the functions used in testpages according to page.
- testCases.py From the name itself it is cleared that this file defines all the testcase which is implemented.
- testpages.py This is the main file by executing this file all the test script will run accordingly defined in testcases.
- users.py User file defines all the credentials of user. like login etc.
type the below command
python3 <testpages.py>