Skip to main content

PWDriver (PyWebDriver)

E2e test Code Coverage

Release status PyPI version

MIT License FOSSA Status

Motivation

To simplify automation settings of each different platform, version, browser.

Support:
  • ChromeDriver

  • GeckoDriver

  • EdgeDriver (Chromium)

  • IEDriver

  • ...and Android, iOS (See With Appium section)

Usage

1. Install:

pip install pwdriver

2. Make 'config.ini' file and locate in your project directory.

config.ini look like this.

[automation]
;if using remote webdriver, then local be false and url required.
local=true
url=http://localhost:4444
;target: chrome, gecko, edge, safari
target=chrome

3. Import WebDriverFactory.

Now, we can launch webdriver.

from pwdriver.core import WebDriverFactory

driver = WebDriverFactory.launch()

Alternative Usage

This way doesn't make and doesn't use configuration file, but calls setup method of the driver in your test code.

with Chrome:

from selenium import webdriver
from pwdriver import core

core.setup_chromedriver()
driver = webdriver.Chrome()

with FireFox:

from selenium import webdriver
from pwdriver import core

core.setup_geckodriver()
driver = webdriver.Firefox()

with Edge:

from selenium import webdriver
from pwdriver import core

core.setup_edgedriver()
driver = webdriver.Edge()

Page object models

Page object models pattern makes our test cases more concise and readable.

The good news is, we can use Page Objects with this.

There is an example that searching for keyword on www.bing.com and verifying url, title.

For using this, we are going to create modules that page object classes and test cases.

Modules that page elements and locators already implemented, so nevermind.

Page Object Class

from selenium.webdriver.common.by import By

from pwdriver.page import BasePage


class BingPage(BasePage):
    def __init__(self, driver):
        super().__init__(driver)
        self._url = 'https://www.bing.com'
        self._locator = {
            'input': (By.CSS_SELECTOR, 'input#sb_form_q'),
            'search': (By.CSS_SELECTOR, 'label#search_icon')
        }

    def type_keyword(self, text) -> None:
        self._by('input').send_keys(text)

    def click_search(self) -> BasePage:
        self._by('search').click()
        return BingPage(BasePage)

Test case

from pwdriver.core import WebDriverFactory
from tests.pages.bing_page import BingPage

import unittest


class BrowserTest(unittest.TestCase):
    def setUp(self):
        self.driver = WebDriverFactory.launch()

    def tearDown(self):
        self.driver.quit()

    def test_something(self):
        page = BingPage(self.driver)
        page.get()
        keyword = 'chicken'
        page.type_keyword(keyword)
        page.submit_keyword()
        self.assertIn(f'https://www.bing.com/search?q={keyword}', self.driver.current_url)
        self.assertEqual(f'{keyword} - Search', self.driver.title)


if __name__ == '__main__':
    unittest.main()

Logging and Event listener

If we want to use logging or want to see what events occured in webdriver,

we can use get_logger() or EventListener().

See below example code.

Test

from selenium.webdriver.support.events import EventFiringWebDriver

from pwdriver.core import WebDriverFactory
from pwdriver.listener import EventListener
from pwdriver.util import get_logger

logger = get_logger('test')

core = WebDriverFactory.launch()
driver = EventFiringWebDriver(core, EventListener())
logger.info('WebDriver created.')
  • Log level: debug, info, warning, error, critical
  • WebDriver event: navigate, execute script
  • WebElement event: find, click, change value

With Appium

This package also includes wrapped appium's remote webdriver.

We could launch an appium driver using config.ini file that contains capabilities.

See below configuration and example code.

Configuration

[automation]
;if using appium, then local be false and url required.
local=false
url=http://localhost:4723
;target: android, ios
target=ios

[mobile]
;add capabilities for mobile testing.
platformVersion=15.5
deviceName=iPhone 13 mini
browserName=Safari

Test

from pwdriver.core import WebDriverFactory

driver = WebDriverFactory.launch()

License

FOSSA Status

Metadata

Release files for pwdriver 0.27.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pwdriver 0.27.3
File Size Uploaded Provenance Actions
pwdriver-0.27.3.tar.gz 9.7 kB Without provenance Details for pwdriver-0.27.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pwdriver 0.27.3
File Interpreter ABI Platform Actions
pwdriver-0.27.3-py3-none-any.whl Python 3 none any Details for pwdriver-0.27.3-py3-none-any.whl

Total release size: 19.3 kB

Release files / pwdriver-0.27.3.tar.gz

Download URL pwdriver-0.27.3.tar.gz
Size 9.7 kB
Tags Source
SHA-256 checksum
How to use checksums
619b19d76924ddd2c65d19676212a72fbea0ab4bab7b4f8ceda6c7302f96c5c4
BLAKE2b-256 checksum
How to use checksums
3b1ec281ce44eee0ded0d54a480e8b2466827c84b21601cf27c65ba2e7d3371a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.5.1 CPython/3.11.0 Linux/5.15.0-1041-azure

Release files / pwdriver-0.27.3-py3-none-any.whl

Download URL pwdriver-0.27.3-py3-none-any.whl
Size 9.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ff6a338bed430b26c174b131587c4083e8f85e92497e9a53b92632ab302efd22
BLAKE2b-256 checksum
How to use checksums
a21a7fe2c8ba2a61172cc05c625d64fadeabd346ff9d326dd63b6ed78bc493a9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.5.1 CPython/3.11.0 Linux/5.15.0-1041-azure

Security for pwdriver 0.27.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.27.3 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page