Skip to content
/ qxf2-page-object-model Public template

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, BrowserStack, Slack, TestRail, etc. This repository is developed and maintained by Qxf2 Services.

License

Notifications You must be signed in to change notification settings

qxf2/qxf2-page-object-model

Repository files navigation

Python version GitHub Maintenance CircleCI BrowserStack Status GitHub stars GitHub forks GitHub repo size GitHub last commit Codacy Badge


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

 

Qxf2 automation framework

 

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.

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!

Looking for ways to automate your UI and API tests quickly and effectively? You've come to the right place. By harnessing AI and code auto-generation capabilities, we've developed solutions that significantly decrease the time needed to create a fully functional test suite. For further information, please refer to the following links.


Setup

The setup for our open-sourced Python test automation framework is fairly simple. 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

Above links redirects to our github wiki pages.

Optional steps for integrating with third-party tools:


Repository details

Directory structure of our current Templates

   ./

   |_ conf: For all configurations files
   
   |_ core_helpers: Contains our web app and mobile app helpers and DriverFactory  

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

   |_ integrations: Contains cross-browsers (BrowserStack, SauceLabs, Lambdatest), reporting tools (TestRail, Tesults) and reporting channel integrations (Slack, Gmail) 

   |_ log: Log files for all tests

   |_ page_objects: Contains our PageFactory, different Page Objects examples

   |_ screenshots: For screenshots

   |_ tests: Put your tests here

   |_ utils: All utility modules (ssh_util, compare csv, compare images, Base Logger, etc) are kept in this folder

   |_ conftest.py: Configuration file to add different fixtures used in py.test

   |_ .env and .env.remote: For credential details. Refer env_conf and env_remote file and rename it to .env and .env_conf. 

For more details about the structure, refer our wiki page here


COMMANDS FOR RUNNING TESTS

a) General Command

python -m pytest [options]

Options

  • --app_url
    Runs against a specific URL.
    Example:
    python -m pytest --app_url http://YOUR_localhost_URL
    This will run against your local instance.

  • --remote_flag
    Runs tests on Browserstack/LambdaTest/Sauce Labs.
    Example:
    python -m pytest -s --remote_flag Y --app_url https://qxf2.com

  • --browser all
    Runs the tests against multiple browsers.
    Example:
    python -m pytest --browser all
    This will run each test against the list of browsers specified in the conf/browser_os_name_conf.py file (e.g., Firefox and Chrome).

  • --ver / --os_name / --os_version
    Runs against different browser versions, OS platform and OS versions.
    Example:
    python -m pytest --ver 120 --os_name windows --os_version 11 --remote_flag y
    This will run each test with default browser (chrome) and provided combination (browser version 120 windows 11)

  • -h
    Displays help for more options.
    Example:
    python -m pytest -h

  • -k
    Runs tests matching the given substring expression.
    Example:
    python -m pytest -k table
    This will trigger tests that match the pattern, such as test_example_table.py.

  • --slack_flag
    Posts pytest reports on the Slack channel.
    Example:
    python -m pytest --slack_flag Y -v > log/pytest_report.log
    This will send the pytest-report on configued slack channel at the end of test run.

  • -n
    Runs tests in parallel.
    Example:
    python -m pytest -n 3 -v
    This will run three tests in parallel.

  • --tesults
    Reports test results to Tesults.
    Example:
    python -m pytest tests/test_example_form.py --tesults Y

  • --interactive_mode_flag
    Runs the tests interactively.
    Example:
    python -m pytest tests/test_example_form.py --interactive_mode_flag Y
    This option allows the user to pick the desired configuration to run the test from a menu displayed.

    Note: If you wish to run the test in interactive mode on Git Bash for Windows, set your bash alias by adding the following command to .bashrc:
    alias python='winpty python.exe'

  • --summary
    Summarizes the pytest results in an HTML report.
    Example:
    python -m pytest -k example_table --summary y
    Note: You need to provide your OPENAI_API_KEY using export OPENAI_API_KEY=<your-key>.

b) Specific Commands

  • Standalone Test
    python -m pytest tests/test_example_form.py

  • Run Against Specific Browser
    python -m pytest tests/test_example_form.py --browser Chrome

  • API Test
    python -m pytest tests/test_api_example.py
    Note: Ensure the sample cars-api is available at qxf2/cars-api repository before running the API test.

  • Mobile Test Run on Browserstack/Sauce Labs
    python -m pytest tests/test_mobile_bitcoin_price --mobile_os_version <android version> --device_name <simulator> --app_path <.apk location on local> --remote_flag Y
    Note: For running tests on Browserstack/Sauce Labs, update the Browser_Plaform, Username and AccessKey in .env.remote from your Browserstack/Sauce Labs account. Refer our wiki page for more details: Integrate our Python Selenium automation framework with Cloud Services

  • Run Test along with Tesults
    python -m pytest tests/test_example_form.py --tesults Y
    Note: For running the test along with Tesults, update the .env file with target_token and run the above command. Refer env_conf file for configuration.

  • Run Tests along with ReportPortal
    python -m pytest -k example --reportportal
    Note: For running the test along with ReportPortal, update the .env file with ReportPortal credential details and run the above command. Refer our wiki page for more details: Integration with ReportPortal

  • Run Tests along with TestRail
    python -m pytest -k example --testrail_flag Y --test_run_id <testrail run id>
    Note: For running the test along with TestRail, update the .env file with TestRail credential details and run the above command. Refer our wiki page for more details: Integrate our Python test automation framework with Testrail

  • Post test results on Slack
    pytest -k example_form --slack_flag y -v > log/pytest_report.log
    Note: For setup and other details, refer our wiki page: Post Python automation test results on Slack

  • Email pytest report with Gmail
    pytest -s -v --email_pytest_report y --html=log/pytest_report.html
    Note: For setup and other details, refer our wiki page: Email pytest report with Gmail


ISSUES?

a) If Python complains about an "Import" exception, please 'pip3 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

e) The Edge in Windows can not be downloaded automatically to the local cache (~/.cache/selenium) by Selenium Manager as it requires administrative access. When Edge is attempted to installed with Selenium Manager it will through edge can only be installed in Windows with administrator permissions.


Continuous Integration and Support

This project uses:

  1. BrowserStack for testing our web and mobile based tests on cloud across different platform and browsers.

  2. CircleCI for continuous integration.


NEED HELP?

Struggling to get your GUI automation going? You can hire Qxf2 Services to help. Contact us at [email protected]

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, BrowserStack, Slack, TestRail, etc. This repository is developed and maintained by Qxf2 Services.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages