# velenium
Interact with an app using visual definitions of elements
## sample usage
```python
import unittest
from appium import webdriver
import velenium as ve
class VisualTestCase(unittest.TestCase):
def setUp(self):
# given a driver
self.driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_capabilities={...})
# or for local desktop automation
self.driver = ve.VisualDriver()
def tearDown(self):
self.driver.quit()
def test_visual(self):
# create a visual definition
element = ve.VisualElement(self.driver, 'path/to/pattern.png')
# create a visual definition using multiple images using glob path
element = ve.VisualElement(self.driver, 'path/to/patterns/**/pattern_*.png')
# assert element is visible
self.assertTrue(element.is_visible())
# wait until element is visible, raises TimeoutException from selenium if timeout
element.wait_until_visible()
# wait until element is not visible, raises TimeoutException from selenium if timeout
element.wait_until_not_visible()
# find only in de middle region
ve.VisualElement(self.driver, 'path/to/pattern.png', region=ve.LEFT_SIDE).click()
# custom region, upper right in the example
ve.VisualElement(self.driver, 'path/to/pattern.png', region=((0.5, 0), (1, 0.5))).click()
# click on element on de right border
ve.VisualElement(self.driver, 'path/to/pattern.png', target=ve.RIGHT).click()
# custom region, center right in the example
ve.VisualElement(self.driver, 'path/to/pattern.png', target=(0.5, 0)).click()
# refresh position of element and click
element.reset_object().click()
# click and wait no visibility of the element
element.click().wait_until_not_visible()
# find with different similarity threshold, by default is 80%
ve.VisualElement(self.driver, 'path/to/pattern.png', similarity=0.7).click()
# click the 2nd best match of element
ve.VisualElement(self.driver, 'path/to/pattern.png', order=1).click()
# click element at 2nd position in vertical order
ve.VisualElement(self.driver, 'path/to/pattern.png', order=1, disposal=ve.VERTICAL).click()
# or
item = ve.VisualElement(self.driver, 'path/to/pattern.png', disposal=ve.VERTICAL)
item.matches[1].click()
# click element at 3er position in horizontal order
ve.VisualElement(self.driver, 'path/to/pattern.png', order=2, disposal=ve.HORIZONTAL).click()
# or
item = ve.VisualElement(self.driver, 'path/to/pattern.png', disposal=ve.HORIZONTAL)
item.matches[2].click()
# use another cv2 method to get the match, by default uses CV_CCOEFF
ve.VisualElement(self.driver, 'path/to/pattern.png', method=ve.CV_SQDIFF).wait_until_visible()
# count matches
print(len(element.matches))
# or
print(element.count)
# iterate over matches
for e in element.matches:
e.click()
# enable debug images in "temp/" folder
element.debug()
# disable debug images
element.debug(False)
if __name__ == '__main__':
unittest.main()
```
Raw data
{
"_id": null,
"home_page": "https://github.com/manzanero/velenium",
"name": "velenium",
"maintainer": null,
"docs_url": null,
"requires_python": null,
"maintainer_email": null,
"keywords": "visual, testing, selenium, appium, desktop",
"author": "Alejandro Manzanero Sobrado",
"author_email": "alejmans@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/94/e4/10afbb92e658e9e9aa9901234c08a2df91d83c71b3e05690f2fd060c3a89/velenium-0.7.0.tar.gz",
"platform": null,
"description": "# velenium\r\nInteract with an app using visual definitions of elements\r\n\r\n## sample usage\r\n\r\n```python\r\nimport unittest\r\nfrom appium import webdriver\r\nimport velenium as ve\r\n\r\n\r\nclass VisualTestCase(unittest.TestCase):\r\n \r\n def setUp(self):\r\n # given a driver\r\n self.driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_capabilities={...})\r\n # or for local desktop automation\r\n self.driver = ve.VisualDriver()\r\n\r\n def tearDown(self):\r\n self.driver.quit()\r\n\r\n def test_visual(self):\r\n # create a visual definition\r\n element = ve.VisualElement(self.driver, 'path/to/pattern.png')\r\n\r\n # create a visual definition using multiple images using glob path\r\n element = ve.VisualElement(self.driver, 'path/to/patterns/**/pattern_*.png')\r\n\r\n # assert element is visible\r\n self.assertTrue(element.is_visible())\r\n\r\n # wait until element is visible, raises TimeoutException from selenium if timeout\r\n element.wait_until_visible()\r\n\r\n # wait until element is not visible, raises TimeoutException from selenium if timeout\r\n element.wait_until_not_visible()\r\n\r\n # find only in de middle region\r\n ve.VisualElement(self.driver, 'path/to/pattern.png', region=ve.LEFT_SIDE).click()\r\n\r\n # custom region, upper right in the example\r\n ve.VisualElement(self.driver, 'path/to/pattern.png', region=((0.5, 0), (1, 0.5))).click()\r\n\r\n # click on element on de right border\r\n ve.VisualElement(self.driver, 'path/to/pattern.png', target=ve.RIGHT).click()\r\n\r\n # custom region, center right in the example\r\n ve.VisualElement(self.driver, 'path/to/pattern.png', target=(0.5, 0)).click()\r\n\r\n # refresh position of element and click\r\n element.reset_object().click()\r\n\r\n # click and wait no visibility of the element\r\n element.click().wait_until_not_visible()\r\n\r\n # find with different similarity threshold, by default is 80%\r\n ve.VisualElement(self.driver, 'path/to/pattern.png', similarity=0.7).click()\r\n\r\n # click the 2nd best match of element\r\n ve.VisualElement(self.driver, 'path/to/pattern.png', order=1).click()\r\n\r\n # click element at 2nd position in vertical order\r\n ve.VisualElement(self.driver, 'path/to/pattern.png', order=1, disposal=ve.VERTICAL).click()\r\n # or\r\n item = ve.VisualElement(self.driver, 'path/to/pattern.png', disposal=ve.VERTICAL)\r\n item.matches[1].click()\r\n\r\n # click element at 3er position in horizontal order\r\n ve.VisualElement(self.driver, 'path/to/pattern.png', order=2, disposal=ve.HORIZONTAL).click()\r\n # or\r\n item = ve.VisualElement(self.driver, 'path/to/pattern.png', disposal=ve.HORIZONTAL)\r\n item.matches[2].click()\r\n\r\n # use another cv2 method to get the match, by default uses CV_CCOEFF\r\n ve.VisualElement(self.driver, 'path/to/pattern.png', method=ve.CV_SQDIFF).wait_until_visible()\r\n\r\n # count matches\r\n print(len(element.matches))\r\n # or\r\n print(element.count)\r\n\r\n # iterate over matches\r\n for e in element.matches:\r\n e.click()\r\n\r\n # enable debug images in \"temp/\" folder\r\n element.debug()\r\n\r\n # disable debug images\r\n element.debug(False)\r\n\r\n\r\nif __name__ == '__main__':\r\n unittest.main()\r\n```\r\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Interact with an app using visual definitions of elements",
"version": "0.7.0",
"project_urls": {
"Download": "https://github.com/manzanero/velenium/archive/refs/tags/v0.7.0.tar.gz",
"Homepage": "https://github.com/manzanero/velenium"
},
"split_keywords": [
"visual",
" testing",
" selenium",
" appium",
" desktop"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "94e410afbb92e658e9e9aa9901234c08a2df91d83c71b3e05690f2fd060c3a89",
"md5": "0d8fee570694de21b107b508a6aee16f",
"sha256": "6f4a4a1710ed3bbd6902da46f36dd8d131104a0d6bef0f565c91750db985dc0c"
},
"downloads": -1,
"filename": "velenium-0.7.0.tar.gz",
"has_sig": false,
"md5_digest": "0d8fee570694de21b107b508a6aee16f",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 7210,
"upload_time": "2024-11-07T10:29:09",
"upload_time_iso_8601": "2024-11-07T10:29:09.421565Z",
"url": "https://files.pythonhosted.org/packages/94/e4/10afbb92e658e9e9aa9901234c08a2df91d83c71b3e05690f2fd060c3a89/velenium-0.7.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-11-07 10:29:09",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "manzanero",
"github_project": "velenium",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"requirements": [
{
"name": "opencv-python",
"specs": []
},
{
"name": "imutils",
"specs": []
},
{
"name": "numpy",
"specs": []
},
{
"name": "Appium-Python-Client",
"specs": [
[
">=",
"3.*"
]
]
},
{
"name": "selenium",
"specs": [
[
">=",
"4.*"
]
]
},
{
"name": "Pillow",
"specs": []
},
{
"name": "PyAutoGUI",
"specs": []
}
],
"lcname": "velenium"
}