Skip to main content

It will download a WebDriver, and then set basic configuration automatically.

Project description

PWDriver (PyWebDriver)

E2e test Code Coverage

Release status PyPI version

MIT License FOSSA Status

Motivation

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

Support:
  • ChromeDriver

  • GeckoDriver

  • EdgeDriver (Chromium)

  • IEDriver

Usage

1. Install:

pip install pwdriver

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

config.ini 's contents look like this.

[automation]
;automation.browser: chrome, gecko, edge, safari
automation.browser=chrome
;automation.local: true, false
automation.local=true
automation.url=http://localhost:4444/wd/hub

3. Import WebDriverFactory.

Now, we can launch webdriver.

from pwdriver.core import WebDriverFactory

driver = WebDriverFactory().launch()

Different Usage(using selenium)

Use with Chrome:

from selenium import webdriver
from pwdriver import core

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

Use with FireFox:

from selenium import webdriver
from pwdriver import core

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

Use 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

pages/bing_page.py look like this.

from selenium.webdriver.common.by import By
from pwdriver.page import BasePage


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

    def __init__(self, driver):
        super().__init__(driver)

    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

page_object.py look like this.

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()
        page.type_keyword("치킨")
        page.click_search()
        self.assertIn("https://www.bing.com/search?q=%EC%B9%98%ED%82%A8", self.driver.current_url)
        self.assertEqual("치킨 - 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.

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('eventdriver')

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

License

FOSSA Status

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

pwdriver-0.26.0.tar.gz (9.2 kB view details)

Uploaded Source

Built Distribution

pwdriver-0.26.0-py3-none-any.whl (8.7 kB view details)

Uploaded Python 3

File details

Details for the file pwdriver-0.26.0.tar.gz.

File metadata

  • Download URL: pwdriver-0.26.0.tar.gz
  • Upload date:
  • Size: 9.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.13

File hashes

Hashes for pwdriver-0.26.0.tar.gz
Algorithm Hash digest
SHA256 e9e08b679541e5295bdf0860c1233411691f9eaff6d1751f34e1c1e33fee2ca0
MD5 1e1879295399edcc898d8146de6531ac
BLAKE2b-256 9a4c0d4eb0169006d2edc7274c12a261ad937964a52bf881c59f0e92e595865c

See more details on using hashes here.

File details

Details for the file pwdriver-0.26.0-py3-none-any.whl.

File metadata

  • Download URL: pwdriver-0.26.0-py3-none-any.whl
  • Upload date:
  • Size: 8.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.13

File hashes

Hashes for pwdriver-0.26.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1d38d2153cdbb5dc2e3c43ce8a9d70b84d93640f7e77da8258ca6021c1bab5f6
MD5 187aae17d0c437e43e82b002e1e42fca
BLAKE2b-256 c5495e7443c4231817829e7596622a9e9c79d086673486c475fc40fd161f8d63

See more details on using hashes here.

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