Skip to main content

Package to hold driver and locator methods for selenium

Project description

Selpy

Selpy module is to have all the common methods that will be used in functional UI automation in Page Object Model. Selpy also powered to have snapshot feature that will save the data from UI to a file if needed. This in turn reduces the test data maintenance efforts.

License: GPL v3 Made with Python StackOverflow Contributions Welcome email me

alt text

Installation

Add this line to your application's requirements.txt file:

selpy==<version>

And then execute:

pip3 install -r requirements.txt

Or install it yourself as:

pip3 install selpy

Usage

This module is built to replace the library methods in Selpy-Python framework. This allows us to share the methods among different teams and completely ignore the repetitive work. For more details on Page object model for functional UI automation verify Selpu Python Documentation page.

Adding new methods

Add all the new methods inside /selpy/ path and add import the class inside __init__.py file in the same path so that the newly added class can be imported by using this module.

Require and Include

To import this module use,

import selpy

To import specific class in this module use,

from selpy.driver import Driver

Detailing the module

Driver

Driver file holds all the common actions that are executed by the driver. Initiate the driver by,

driver = Driver()

The driver will hold the selenium webdriver object.

For configuring the driver capabilities, one has to specify the details in the global_data.yml in Selpy-Python.

Locator

This class is to declare the selenium locators in Page Object Model. You can declare the locators as follows,

class AmazonHomePageLocator:
    # Static locators
    amazon_logo = Locator("css selector", "div#nav-logo a[aria-label='Amazon']")
    amazon_search_categories = Locator("css selector", "div.nav-search-scope select.nav-search-dropdown")

    def __init__(self):
        print("Locators for Amazon home page")

    # Dynamic locators
    @staticmethod
    def amazon_search_category_list(string):
        return Locator("xpath", "//select[contains(@class,'nav-search-dropdown')]//option[text()='%s']" % string)

To use the Locator method we need to pass the type of locator and the actual locator element. Type of locator has to be mentioned in the following way to allow selpy to process the locator.

CSS - 'css selector'
XPATH - 'xpath'
ID - 'id'
NAME - 'name'
LINK TEXT - 'link text'
PARTIAL LINK TEXT - 'partial link text'
TAG NAME - 'tag name'
CLASS NAME - 'class name'

Store

This class is to store the run time configurations for this module. Kind of a memcached or redis for our framework. Centralized run time data which are needed by other modules are being stored here and retrived by other modules.

Variable

This is where the actual snap feature logic is present. In order to save the UI data in to the dynamic file one has to run the tests with,

snap=1 pytest

But, only this will not ensure the data is getting saved in to dynamic file. One has to script their automation code in such a way that snap feature is supported. For example one can look in to Selpy-Python framework inside Tests/amazon.py

Upon running the tests in normal mode pytest the dynamic data will not be overridden rather it will assert the data present in UI with the dynamic data file.

To get this feature running smoothly and to access the variables in smoother way, one has to configure the following params in their framework in pytest_configure method (so that these path variables will be set on initiating the pytest).

from selpy.store import Store

def pytest_configure(config):
    # Configuring the selpy with data path location
    Store.global_data_path = os.path.dirname(os.path.abspath(__file__)).replace("/Tests", "") + '/Data/GlobalData/global_data.yml'
    Store.static_data_path = os.path.dirname(os.path.abspath(__file__)).replace("/Tests", "") + '/Data/TestData/'
    Store.dynamic_data_path = os.path.dirname(os.path.abspath(__file__)).replace("/Tests", "") + '/Data/DynamicData/'

To publish a module in pypi

  1. Install the following dependencies
python3 -m pip install --user --upgrade setuptools wheel
  1. In the root directory of your newly created module run,
python3 setup.py sdist bdist_wheel
  1. Then add the username and password and upload to the pypi server,
python3 -m twine upload -u <username> -p <password> --repository-url https://upload.pypi.org/legacy/ dist/* --verbose

Ensure that you have deleted the old files from your dist directory.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/nareshnavinash/selpy/. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

Authors

License

The gem is available as open source under the terms of the GPL-3.0 License.

Code of Conduct

Everyone interacting in the Teber project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

selpy-0.1.1.tar.gz (8.0 kB view hashes)

Uploaded Source

Built Distribution

selpy-0.1.1-py3-none-any.whl (36.3 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page