Package: pybehave-selenium-test-framework
PyTestBehave Test Automation Framework____          ____         _                                 ____         _               _                       
|  _ \  _   _ | __ )   ___ | |__    __ _ __   __  ___        / ___|   ___ | |  ___  _ __  (_) _   _  _ __ ___   
| |_) || | | ||  _ \  / _ \| '_ \  / _` |\ \ / / / _ \ _____ \___ \  / _ \| | / _ \| '_ \ | || | | || '_ ` _ \  
|  __/ | |_| || |_) ||  __/| | | || (_| | \ V / |  __/|_____| ___) ||  __/| ||  __/| | | || || |_| || | | | | |
|_|     \__, ||____/  \___||_| |_| \__,_|  \_/   \___|       |____/  \___||_| \___||_| |_||_| \__,_||_| |_| |_|
        |___/PyBehave-Seleniumis a powerful test automation framework designed to provide a comprehensive solution for testing user interfaces and APIs. It leverages the power ofBehaveframework,Pythonprogramming language andSeleniumWebDriverto allow the creation robust and maintainable automated tests.HighlightsBehaviour-Driven Development (BDD) Support- allows testers to write tests in a human-readable format usingGherkinsyntax, making it easier to collaborate with stakeholders and ensure test coverage.UI and API Testing- supports testing both UIs and APIs, usingSeleniumWebDriverto interact with web browsers andPythonrequestslibrary to send API requests and validate responses.Robustness- when user interfaces are not 100% reliable, sometimes laggy, rendering speed varies, the core test logic will identify if elements are not present or clickable, back-off and attempt to retry a configurable number of times, and even perform browser refreshes if configured, to ensure the best attempt to execute the behaviour is performed.Cross-browser Support- compatible with various web browsers, including Chrome and Edge; allowing tests to run across multiple browsers ensuring application compatibility and consistent behaviour. Note: the version of the web driver used must be compatible with the browser version installed.Test Data Management- supports data-driven testing, allowing tests to read test data from externaltemplatefiles and useJinja2templating engine to substitute in test specific data.Test Reporting and Logging- support generatingallureandbehavextest reports to provide insight into test failures, captures screenshots of test failures for analysis; outputs clear log messages for every test action to aid debugging and troubleshooting.Extensibility and Customisation- designed to be extensible and provides a simple, but flexible design for further customisation and integration of further third-party libraries.Design OverviewThe design is split into two sections -Test SuiteandFramework Layer.Test Suite - where the Gherkin style features are written with supporting step definitions calling down to page actions which orchestrate the test behaviour. This is where most business behaviour will be developed, making use of the framework layer.Framework Layer - contains the common re-usable functionality which drives the browser, contains common libs, provides logging and reporting.Directory StructureDirectory / FileDescriptionfeaturesTheGherkinstyle feature files for defining BDD testsfeatures/stepsThe step definitions backing theGherkintestsfeatures/environment.pyDefault test environment, can be overridden and customisedsupport/facadesTest logic facade actions potentially interacting across one or more pagessupport/pageactionsThe specific page actions, inheriting common actions from theBasePagesupport/coreThe coreElementActionwhich performs all the lower level selenium functionalitysupport/locatorsLocator descriptors and types used for identifying web elementssupport/builderThe templating builders to create supporting test datasupport/test_settings.jsonDefault test settings, can be overridden and customiseddriversThe web drivers for supported browsersreportsThe json files generated with Allure reportsscreenshotsThe screenshots taken from failed testsrequirements.txtFile containing all the Python package dependenciesRunning the TestsPre-requisitesInstall the required system dependencies.sudo apt-get install requirements.system.Install the required Python module dependencies.sudo pip install -r requirements.txt.Install the latest stable version of the web drivers you wish to use indrivers.Running the Example TestAn example testlogin.featurehas been created to demonstrate a simple working test. It provides a username and password to login to a website, verifies the login and attempts to log the user out.behave features/example/login.featureNote: A compatible web driver will need to be available in thedriversfolder and configured in thetest-settings.jsonfile.The example login highlights the test suite and framework layers - a user definedGherkintest with backing test logic; interacting with the web browser through the frameworkBasePage.+---------------+     +---------------+     +----------------+     +--------------+    +------------------+
| login.feature | <-> | loginsteps.py | <-> | loginaction.py | <-> | loginpage.py | -> | loginlocators.py |
+---------------+     +---------------+     +----------------+     +--------------+    +------------------+
                                                                          |
                                                                   +-------------+     +------------------+     +-------------+
                                                                   | basepage.py | <-> | elementaction.py | <-> | Web Browser |
                                                                   +-------------+     +------------------+     +-------------+There are also example tests fordatabaseconnectivity andAPIrequests.Logging OutputWhen running tests each step is logged in a format to assist with understanding the execution and with debugging issues.Feature: Example Login # features/example/login.feature:4
2024-02-14 18:17:13 INFO     Scenario <Scenario "Login to demo site"> - starting
2024-02-14 18:17:13 INFO     Edge browser
2024-02-14 18:17:13 INFO     Web driver: drivers/msedgedriver

  Scenario: Login to demo site                                  # features/example/login.feature:6
    Given I have navigated to url "https://demo.applitools.com" # features/steps/example/login_steps.py:9 0.342s
    When I enter username "Operator" and password "Password"    # features/steps/example/login_steps.py:16
2024-02-14 18:17:20 INFO     Login user Operator - start
2024-02-14 18:17:20 INFO     Checking element '//input[@id='username']' (XPATH) is clickable
2024-02-14 18:17:20 INFO     Clicked on element 'XPATH, //input[@id='username']'
2024-02-14 18:17:22 INFO     Typed text Operator on element XPATH, //input[@id='username']
2024-02-14 18:17:22 INFO     Checking element '//input[@id='password']' (XPATH) is clickable
2024-02-14 18:17:22 INFO     Clicked on element 'XPATH, //input[@id='password']'
2024-02-14 18:17:24 INFO     Typed text ***** on element XPATH, //input[@id='password']
2024-02-14 18:17:24 INFO     Checking element '//a[@id='log-in']' (XPATH) is clickable
2024-02-14 18:17:24 INFO     Clicked on element 'XPATH, //a[@id='log-in']'
2024-02-14 18:17:25 INFO     Login user Operator - complete
2024-02-14 18:17:25 INFO     Repeat until locator 'XPATH, //div[@class='logged-user-w']' is displayed
2024-02-14 18:17:25 INFO     Locator 'XPATH, //div[@class='logged-user-w']' displayed
    Then I can verify the items are present                     # features/steps/example/login_steps.py:23 0.134s
      | item               | Get text returned Financial Overview for element XPATH, //h6[@class='element-header']
      | Financial Overview | Completed step <then "I can verify the items are present">
    And I logout                                                # features/steps/example/login_steps.py:31
2024-02-14 18:17:26 INFO     Checking element '//a[@id='log-out']' (XPATH) is clickable
2024-02-14 18:17:31 WARNING  Unable to click on element 'XPATH, //a[@id='log-out']'
2024-02-14 18:17:31 INFO     Pausing for 5 seconds
2024-02-14 18:17:36 INFO     Retry clicking on element 'XPATH, //a[@id='log-out']'
2024-02-14 18:17:41 WARNING  Unable to click on element 'XPATH, //a[@id='log-out']'
2024-02-14 18:17:42 INFO     Scenario <Scenario "Login to demo site"> - complete

1 feature passed, 0 failed, 0 skipped
1 scenario passed, 0 failed, 0 skipped
4 steps passed, 0 failed, 0 skipped, 0 undefined
Took 0m22.608sPre-commit checksRuns hooks on every commit to automatically point out issues in code. Run$ pre-commit installto setup the git hook scriptshttps://pre-commit.com/blackBlack is the uncompromising Python code formatter. Runblack **/*.pyhttps://pypi.org/project/black/pylintPylint is a static code analyser for Python. Runpylint *.pyhttps://pypi.org/project/pylint/Run example test without allure reportingbehave features/example/login.featureRun example test with allure reportingbehave -f allure_behave.formatter:AllureFormatter -o reports/ features/example/login.featureRunning the Tests from DockerBuild the docker image:docker build -t [IMAGE_NAME]:[IMAGE_TAG] .To execute tests in a docker container, run the following.docker run -it -v /tmp/reports:/src/reports [IMAGE_NAME]:[IMAGE_TAG] behave features/example/login.featureView Test ReportsTo view Allure test reports, run the command:allure serve /tmp/reports.Note: You will need to install Allure Report fromhttps://allurereport.org/.Selenium Grid (currently not fully implemented)Selenium Grid will be used with Azure Kubernetes Service (AKS) to auto-scale when running the tests. Using AKS and KEDA (Kubernetes Event-driven Autoscaling) will monitor the Selenium test queue and scale nodes accordingly.Running tests against Selenium GridTo run tests against Selenium Grid you need to be able to access the Hub UI. At the moment this has to be done using Kubernetes port-forwarding but in the future can be updated to expose the hub via a load balancer. Runkubectl -n selenium port-forward svc/selenium-hub 4444to port forward the Hub to localhost:4444To use Selenium Grid update the settings.json to use the 'GRID' test runner by setting the property"test_runner": "GRID". Once this has been set, the tests will try and run against a remote browser. You'll also need to set"selenium_grid_endpoint": "http://localhost:4444/wd/hub"to tell it where the Hub is.To run the tests, you can run the exact same commands as described in the previous section. This won't however make use of the multiple worker feature of Selenium Grid. To run the tests in parallel, run the below command.Future Feature EnhancementsSupport concurrent running against multiple browser typesSelenium GridIntegration with Azure keyvaultReferenceshttps://behave.readthedocs.io/en/stable/https://www.selenium.dev/documentation/webdriver/https://github.com/Azure-Samples/selenium-grid-aks-kedahttps://allurereport.org/