Skip to content

Write Selenium and Appium tests in Python using the Page Object pattern. This Pythonic GUI and API test automation framework will help you get started with QA automation quickly. It comes with many useful integrations like - email, Slack, TestRail, etc. This repository is developed and maintained by Qxf2 Services (https://qxf2.com).

License

ajeetd/qxf2-page-object-model

 
 

Repository files navigation


A Pythonic Selenium, Appium and API test automation framework

You can use this test automation framework to write:

  1. Selenium and Python automation scripts to test web applications

  2. Appium and Python scripts for mobile automation (Android and iOS)

  3. API automation scripts to test endpoints of your web/mobile applications

This GUI and API test automation framework is developed and maintained by Qxf2 Services. This framework is written in Python and is based on the Page Object Model - a design pattern that makes it easy to maintain and develop robust tests. We have also included our API test automation framework based on the player-interface pattern in this repository. You can now write your API tests along with your Selenium and Appium tests. Please note: the API test examples are written for the sample API available at Cars API repository.

We've implemented some version of this framework at several clients. In all cases, this framework helped us write automated tests within the first week of our engagement. We hope you find this framework useful too!


Setup for our Python integration testing framework

The setup for our open-sourced Python test automation framework is fairly simple. Don't get fooled by the length of this section. We have documented the setup instructions in detail so even beginners can get started.

The setup has four parts:

  1. Prerequisites
  2. Setup for GUI/Selenium automation
  3. Setup for Mobile/Appium automation
  4. Setup for API automation

1. Prerequisites

a) Install Python 2.x

b) Add Python 2.x to your PATH environment variable

c) If you do not have it already, get pip (NOTE: Most recent Python distributions come with pip)

d) pip install -r requirements.txt to install dependencies

If you ran into some problems on step (d), please report them as an issue or email Arun(mak@qxf2.com).

2. Setup for GUI/Selenium automation

a) Get setup with your browser driver. If you don't know how to, please try:

For Chrome

For Firefox

#Note: Check Firefox version & Selenium version compatibility before downloading geckodriver.

If your setup goes well, you should be to run a simple test with this command:

  1. Chrome: pytest -k example_form -B Chrome

  2. Firefox: pytest -k example_form -B Firefox

Optional steps for integrating with third-party tools:

3. Setup for Mobile/Appium automation

a) Download and Install appium desktop app

b) Download and Install Android Studio and create an emulator

c) Install Java JDK

d) Install the appium Python client library pip install Appium-Python-Client

If your setup goes well, you should be to run a simple mobile test with this command after starting the Appium and Android emulator: pytest -k mobile_bitcoin_price -H $Emulator_OS_Version -I $Emulator_Name

Optional steps for more details on setting up appium and running tests on Android or iOS refer to below links:

4. Setup for API automation

a. Get Cars API code from repo https://github.com/qxf2/cars-api using command "git clone https://github.com/qxf2/cars-api.git"

b. Install Flask using command "pip install flask"

c. Run cars-app server using command "python cars-api/cars_app.py"

d. Run test_api_example now using command "pytest -k api -s"

Optional steps for more details on setting up API and running tests refer to below link:


Repository details

a) Directory structure of our current Templates

./

|__conf: For all configurations and credential files

|__log: Log files for all tests

|__page_objects: Contains our Base Page, different Page Objects, DriverFactory, PageFactory

|__endpoints: Contains our Base Mechanize, different End Points, API Player, API Interface

|__screenshots: For screen shots

|__tests: Put your tests in here

|__utils: All utility modules (email_util,TestRail, BrowserStack, Base Logger, post_test_reports_to_slack) are kept in this folder

COMMANDS FOR RUNNING TESTS

a)py.test [options]

-s	used to display the output on the screen			E.g: py.test -s (This will run all the tests in the directory and subdirectories)
-U  	used to run against specific URL				E.g: py.test -U http://YOUR_localhost_URL (This will run against your local instance)
-M  	used to run tests on Browserstack/Sauce Lab			E.g: py.test -s -M Y -U https://qxf2.com	
-B all	used to run the test against multiple browser 			E.g: py.test -B all(This will run each test against the list of browsers specified in the conftest.py file,firefox and chrome in our case)
-V/-O	used to run against different browser versions/os versions	E.g: py.test -V 44 -O 8 (This will run each test 4 times in different browser version(default=45 & 44) and OS(default=7 & 8) combination)
-h	help for more options 						E.g: py.test -h
-k      used to run tests which match the given substring expresion 	E.g: py.test -k table  (This will trigger test_example_table.py test)
-S	used to post pytest reports on the Slack channel		E.g: py.test -S Y -v > log/pytest_report.log
-n 	used to run tests in parallel					E.g: py.test -n 3 -v (This will run three tests in parallel)

b)python tests/test_example_form.py (can also be used to run standalone test)

c)python tests/test_example_form.py -B Chrome (to run against chrome)

d)python tests/test_api_example.py (make sure to run sample cars-api available at qxf2/cars-api repository before api test run)


ISSUES?

a) If Python complains about an "Import" exception, please 'pip install $module_name'

b) If you don't have drivers set up for the web browsers, you will see a helpful error from Selenium telling you where to go and get them

c) If your are using firefox 47 and above, you need to set up Geckodriver. Refer following link for setup: https://qxf2.com/blog/selenium-geckodriver-issue/

d) On Ubuntu, you may run into an issue installing the cryptography module. You need to sudo apt-get install libssl-dev and then run sudo pip install -r requirements.txt


NEED HELP?

Struggling to get your GUI automation going? You can hire Qxf2 Services to help. Contact us at mak@qxf2.com

About

Write Selenium and Appium tests in Python using the Page Object pattern. This Pythonic GUI and API test automation framework will help you get started with QA automation quickly. It comes with many useful integrations like - email, Slack, TestRail, etc. This repository is developed and maintained by Qxf2 Services (https://qxf2.com).

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%