# PWDriver (PyWebDriver)
[![E2e test](https://github.com/jinmoo21/pwdriver/actions/workflows/python_test.yml/badge.svg)](https://github.com/jinmoo21/pwdriver/actions/workflows/python_test.yml)
[![Code Coverage](https://codecov.io/gh/jinmoo21/pwdriver/branch/master/graph/badge.svg?branch=master&kill_cache=1)](https://codecov.io/gh/jinmoo21/pwdriver)
[![Release status](https://github.com/jinmoo21/pwdriver/actions/workflows/python_release.yml/badge.svg)](https://github.com/jinmoo21/pwdriver/actions/workflows/python_release.yml)
[![PyPI version](https://badge.fury.io/py/pwdriver.svg)](https://badge.fury.io/py/pwdriver)
[![MIT License](https://img.shields.io/badge/License-MIT-yellow.svg)](https://github.com/jinmoo21/PWDriver/blob/master/LICENSE)
[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fjinmoo21%2FPWDriver.svg?type=shield)](https://app.fossa.com/projects/git%2Bgithub.com%2Fjinmoo21%2FPWDriver?ref=badge_shield)
## Motivation
To simplify automation settings of each different platform, version, browser.
##### Support:
- ChromeDriver
- GeckoDriver
- EdgeDriver (Chromium)
- ~~IEDriver~~
- ...and Android, iOS (See [With Appium](https://github.com/jinmoo21/PWDriver#with-appium) section)
## Usage
### 1. Install:
```bash
pip install pwdriver
```
### 2. Make 'config.ini' file and locate in your project directory.
`config.ini` look like this.
```ini
[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.
```python
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:
```python
from selenium import webdriver
from pwdriver import core
core.setup_chromedriver()
driver = webdriver.Chrome()
```
### with FireFox:
```python
from selenium import webdriver
from pwdriver import core
core.setup_geckodriver()
driver = webdriver.Firefox()
```
### with Edge:
```python
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
```python
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
```python
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
```python
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
```ini
[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
```python
from pwdriver.core import WebDriverFactory
driver = WebDriverFactory.launch()
```
## License
[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fjinmoo21%2FPWDriver.svg?type=large)](https://app.fossa.com/projects/git%2Bgithub.com%2Fjinmoo21%2FPWDriver?ref=badge_large)
Raw data
{
"_id": null,
"home_page": "https://github.com/jinmoo21/pwdriver",
"name": "pwdriver",
"maintainer": "Jinmoo Han",
"docs_url": null,
"requires_python": ">=3.7,<4.0",
"maintainer_email": "jinmoo21@naver.com",
"keywords": "python,testing,automation,webdriver,selenium,test-automation,selenium-webdriver,appium,appium-webdriver",
"author": "Jinmoo Han",
"author_email": "jinmoo21@naver.com",
"download_url": "https://files.pythonhosted.org/packages/3b/1e/c281ce44eee0ded0d54a480e8b2466827c84b21601cf27c65ba2e7d3371a/pwdriver-0.27.3.tar.gz",
"platform": null,
"description": "# PWDriver (PyWebDriver)\n\n[![E2e test](https://github.com/jinmoo21/pwdriver/actions/workflows/python_test.yml/badge.svg)](https://github.com/jinmoo21/pwdriver/actions/workflows/python_test.yml)\n[![Code Coverage](https://codecov.io/gh/jinmoo21/pwdriver/branch/master/graph/badge.svg?branch=master&kill_cache=1)](https://codecov.io/gh/jinmoo21/pwdriver)\n\n[![Release status](https://github.com/jinmoo21/pwdriver/actions/workflows/python_release.yml/badge.svg)](https://github.com/jinmoo21/pwdriver/actions/workflows/python_release.yml)\n[![PyPI version](https://badge.fury.io/py/pwdriver.svg)](https://badge.fury.io/py/pwdriver)\n\n[![MIT License](https://img.shields.io/badge/License-MIT-yellow.svg)](https://github.com/jinmoo21/PWDriver/blob/master/LICENSE)\n[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fjinmoo21%2FPWDriver.svg?type=shield)](https://app.fossa.com/projects/git%2Bgithub.com%2Fjinmoo21%2FPWDriver?ref=badge_shield)\n\n## Motivation\n\nTo simplify automation settings of each different platform, version, browser. \n\n##### Support:\n\n- ChromeDriver\n\n- GeckoDriver\n\n- EdgeDriver (Chromium)\n\n- ~~IEDriver~~\n\n- ...and Android, iOS (See [With Appium](https://github.com/jinmoo21/PWDriver#with-appium) section)\n\n## Usage\n\n### 1. Install:\n\n```bash\npip install pwdriver\n```\n\n### 2. Make 'config.ini' file and locate in your project directory.\n\n`config.ini` look like this.\n\n```ini\n[automation]\n;if using remote webdriver, then local be false and url required.\nlocal=true\nurl=http://localhost:4444\n;target: chrome, gecko, edge, safari\ntarget=chrome\n```\n\n### 3. Import WebDriverFactory.\n\nNow, we can launch webdriver. \n\n```python\nfrom pwdriver.core import WebDriverFactory\n\ndriver = WebDriverFactory.launch()\n```\n\n## Alternative Usage\n\nThis way doesn't make and doesn't use configuration file, but calls setup method of the driver in your test code.\n\n### with Chrome:\n\n```python\nfrom selenium import webdriver\nfrom pwdriver import core\n\ncore.setup_chromedriver()\ndriver = webdriver.Chrome()\n```\n\n### with FireFox:\n\n```python\nfrom selenium import webdriver\nfrom pwdriver import core\n\ncore.setup_geckodriver()\ndriver = webdriver.Firefox()\n```\n\n### with Edge:\n\n```python\nfrom selenium import webdriver\nfrom pwdriver import core\n\ncore.setup_edgedriver()\ndriver = webdriver.Edge()\n```\n\n## Page object models\n\nPage object models pattern makes our test cases more concise and readable.\n\nThe good news is, we can use Page Objects with this.\n\nThere is an example that searching for keyword on `www.bing.com` and verifying url, title.\n\nFor using this, we are going to create modules that page object classes and test cases.\n\nModules that page elements and locators already implemented, so nevermind.\n\n\n### Page Object Class\n\n```python\nfrom selenium.webdriver.common.by import By\n\nfrom pwdriver.page import BasePage\n\n\nclass BingPage(BasePage):\n def __init__(self, driver):\n super().__init__(driver)\n self._url = 'https://www.bing.com'\n self._locator = {\n 'input': (By.CSS_SELECTOR, 'input#sb_form_q'),\n 'search': (By.CSS_SELECTOR, 'label#search_icon')\n }\n\n def type_keyword(self, text) -> None:\n self._by('input').send_keys(text)\n\n def click_search(self) -> BasePage:\n self._by('search').click()\n return BingPage(BasePage)\n```\n\n### Test case\n\n```python\nfrom pwdriver.core import WebDriverFactory\nfrom tests.pages.bing_page import BingPage\n\nimport unittest\n\n\nclass BrowserTest(unittest.TestCase):\n def setUp(self):\n self.driver = WebDriverFactory.launch()\n\n def tearDown(self):\n self.driver.quit()\n\n def test_something(self):\n page = BingPage(self.driver)\n page.get()\n keyword = 'chicken'\n page.type_keyword(keyword)\n page.submit_keyword()\n self.assertIn(f'https://www.bing.com/search?q={keyword}', self.driver.current_url)\n self.assertEqual(f'{keyword} - Search', self.driver.title)\n\n\nif __name__ == '__main__':\n unittest.main()\n```\n\n## Logging and Event listener\n\nIf we want to use logging or want to see what events occured in webdriver,\n\nwe can use `get_logger()` or `EventListener()`.\n\nSee below example code.\n\n### Test\n\n```python\nfrom selenium.webdriver.support.events import EventFiringWebDriver\n\nfrom pwdriver.core import WebDriverFactory\nfrom pwdriver.listener import EventListener\nfrom pwdriver.util import get_logger\n\nlogger = get_logger('test')\n\ncore = WebDriverFactory.launch()\ndriver = EventFiringWebDriver(core, EventListener())\nlogger.info('WebDriver created.')\n```\n\n* Log level: `debug`, `info`, `warning`, `error`, `critical`\n* WebDriver event: `navigate`, `execute script`\n* WebElement event: `find`, `click`, `change value` \n\n## With Appium\n\nThis package also includes wrapped appium's remote webdriver.\n\nWe could launch an appium driver using `config.ini` file that contains capabilities.\n\nSee below configuration and example code.\n\n### Configuration\n\n```ini\n[automation]\n;if using appium, then local be false and url required.\nlocal=false\nurl=http://localhost:4723\n;target: android, ios\ntarget=ios\n\n[mobile]\n;add capabilities for mobile testing.\nplatformVersion=15.5\ndeviceName=iPhone 13 mini\nbrowserName=Safari\n```\n\n### Test\n\n```python\nfrom pwdriver.core import WebDriverFactory\n\ndriver = WebDriverFactory.launch()\n```\n\n\n## License\n[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fjinmoo21%2FPWDriver.svg?type=large)](https://app.fossa.com/projects/git%2Bgithub.com%2Fjinmoo21%2FPWDriver?ref=badge_large)",
"bugtrack_url": null,
"license": "MIT",
"summary": "It will download a WebDriver, and then set basic configuration automatically.",
"version": "0.27.3",
"project_urls": {
"Bug Reports": "https://github.com/jinmoo21/pwdriver/issues",
"Homepage": "https://github.com/jinmoo21/pwdriver",
"Repository": "https://github.com/jinmoo21/pwdriver"
},
"split_keywords": [
"python",
"testing",
"automation",
"webdriver",
"selenium",
"test-automation",
"selenium-webdriver",
"appium",
"appium-webdriver"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "a21a7fe2c8ba2a61172cc05c625d64fadeabd346ff9d326dd63b6ed78bc493a9",
"md5": "b7b3eecde6a0c39d7df84c37583becc2",
"sha256": "ff6a338bed430b26c174b131587c4083e8f85e92497e9a53b92632ab302efd22"
},
"downloads": -1,
"filename": "pwdriver-0.27.3-py3-none-any.whl",
"has_sig": false,
"md5_digest": "b7b3eecde6a0c39d7df84c37583becc2",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7,<4.0",
"size": 9534,
"upload_time": "2023-07-25T11:29:33",
"upload_time_iso_8601": "2023-07-25T11:29:33.079834Z",
"url": "https://files.pythonhosted.org/packages/a2/1a/7fe2c8ba2a61172cc05c625d64fadeabd346ff9d326dd63b6ed78bc493a9/pwdriver-0.27.3-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "3b1ec281ce44eee0ded0d54a480e8b2466827c84b21601cf27c65ba2e7d3371a",
"md5": "14b6484b43c61ef0eb8183eba2a44b17",
"sha256": "619b19d76924ddd2c65d19676212a72fbea0ab4bab7b4f8ceda6c7302f96c5c4"
},
"downloads": -1,
"filename": "pwdriver-0.27.3.tar.gz",
"has_sig": false,
"md5_digest": "14b6484b43c61ef0eb8183eba2a44b17",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7,<4.0",
"size": 9744,
"upload_time": "2023-07-25T11:29:34",
"upload_time_iso_8601": "2023-07-25T11:29:34.606557Z",
"url": "https://files.pythonhosted.org/packages/3b/1e/c281ce44eee0ded0d54a480e8b2466827c84b21601cf27c65ba2e7d3371a/pwdriver-0.27.3.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-07-25 11:29:34",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "jinmoo21",
"github_project": "pwdriver",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "pwdriver"
}