We came across Cookiecutter when working at a client. It is a tool that helps you create new projects based on templates. We decided to try it with our test automation framework. We have provided all the code used in this project on GitHub so that you can follow along.
What is Cookiecutter?
Cookiecutter is a command-line utility that creates projects from templates i.e. cookiecutters. Cookiecutter saves you lot of time which requires to modify all the stuff you need to do to start a new Project. We created a Cookiecuttter template for our test automation framework that is based on the page object model. The resulting framework template repository is here. This repo is helpful for you to customize and set up Qxf2 framework for your project. Also, it will eliminate the need to manually edit various references which you will need when using our framework in your project.
How to setup Cookiecutter
Setup for Cookiecutter is very easy and simple. Just use the following command to install it.
pip install cookiecutter
How to generate Qxf2’s Page Object Model Framework Boilerplate quickly
Note: To use Cookiecutter for generating boilerplate of our Qxf2’s page object model, we recommend to get set up with python 3.7.x as our automation script is written for python 3.
To generate boilerplate you need to follow 2 steps:
Step 1: Traverse to the directory where you want to create a project. There are 2 ways to get the Qxf2 page object model template.
- Run the cookiecutter command, passing in the link to cookiecutter-pypackage’s HTTPS clone URL like this:
cookiecutter https://github.com/rohandudam/Qxf2_POM_Template_using_Cookiecutter.git
- Another approach would be to clone it to your local and run the cookiecutter below command:
cookiecutter <path of the cloned repo>
(For example – cookiecutter c:/code/Qxf2_POM_Template_using_Cookiecutter)
Step 2: After the above command is executed following parameters will be prompted to be filled
- directory_name [Qxf2_POM]: <Google Automation> ( Mention the project Directory name)
- project_url [https://www.qxf2.com]:<https://www.google.co.in> (Mention the project URL which you want to jumpon)
- page_object_name [tutorial_main_page]: <main_page> (Mention the first page object name)
- page_object_class_name [Tutorial_Main_Page]: <Main_Page> (Mention the same page object name but start with capital letter as shown the example)
Run sample test
For testing the generated boilerplate, switch to generated boilerplate and use the following command:
pytest -s -k current_url
This command will run the test test_check_current_url.py and check if it landed on provided url by user. If test gets PASS without any error, it means the page object model is ready for automation and working fine.
Note: Before running the above command, you need to read the README.md file present under generated boilerplate folder. Follow steps to setup with Qxf2 framework.
References
1. Cookiecutter documentation
2. Qxf2’s test automation framework
I love technology and learning new things. I explore both hardware and software. I am passionate about robotics and embedded systems which motivate me to develop my software and hardware skills. I have good knowledge of Python, Selenium, Arduino, C and hardware design. I have developed several robots and participated in robotics competitions. I am constantly exploring new test ideas and test tools for software and hardware. At Qxf2, I am working on developing hardware tools for automated tests ala Tapster. Incidentally, I created Qxf2’s first robot. Besides testing, I like playing cricket, badminton and developing embedded gadget for fun.