Skip to main content

Selenium for Python

Project description

Selenium for Python

Latest Version License Supported Python versions Build Status Coverage Status Supported Python implementations Code Style

Introduction

This package is a library designed to simplify your work with Selenium WebDriver and based on py-selenium-auto-core solution.

Supported browsers

  • Chrome

Note: Support for popular browsers will be expanded in the future

Supported Python Versions

  • Python 3.7-3.9

Installation

If you have pip on your system, you can simply install or upgrade the Python bindings:

pip install -U py-selenium-auto

Alternately, you can download the source distribution from PyPI, unarchive it, and run:

python setup.py install

Template

To start the project using this solution, you can look into py-selenium-auto-template .

Quick start

  1. Add the dependency in your project
  2. Create conftest.py file and add the following code:
@pytest.fixture(scope="session", autouse=True)
def setup_session(request):
    # TODO: workaround to set calling root path, because pytest runs from the root dir
    work_dir = RootPathHelper.current_root_path(__file__)
    os.chdir(work_dir)

It's necessary to set root dir for your test directory. It is assumed that your project structure will look like this:

src/
    __init__.py
    some_code/
tests/  # Any name
    __init__.py
    resources/
    some_code/
  1. Create instance of Browser in your test:
browser = BrowserServices.Instance.browser
  1. Use Browser's methods directly for general actions, such as navigation, window resize, scrolling and alerts handling:
browser.maximize()
browser.go_to("https://google.com")
browser.wait_for_page_to_load()
  1. Use ElementFactory class's methods to get an instance of each element:
my_text_box = BrowserServices.Instance.service_provider.element_factory().get_text_box(Locator.by_xpath("XPATH"), "Name")

Or you can inherit a class from Form class and use existing ElementFactory:

self.my_text_box = self._element_factory.get_text_box(Locator.by_xpath("XPATH"), "Name")
  1. Call element's methods to perform action with element:
my_text_box.type("example@email.com")
  1. Quit browser at the end:
browser.quit()

Configuration

This file is used to configure your browser settings, as well as other settings.By default, your solution will use the file from this project.

Copy the following file to your solution in tests/resources to configure it yourself

License

Library's source code is made available under the Apache 2.0 license.

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

py-selenium-auto-0.4.5.tar.gz (36.9 kB view hashes)

Uploaded Source

Built Distribution

py_selenium_auto-0.4.5-py3-none-any.whl (59.1 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