# VisualTest
This Python SDK extends the functionality of Selenium WebDriver enabling the script to capture screenshots of the device under test, including fullpage, viewport, and element screenshots for regression testing or manual review of the UI.
```pip install visualtest-python```
### Quick Setup
```shell
from selenium import webdriver
from sbvt import VisualTest
driver = webdriver.Safari()
settings = {'projectToken': "INSERT_PROJECT_TOKEN"}
visualTest = VisualTest(driver, settings)
try:
driver.get("https://www.google.com/search?q=smartbear")
visualTest.capture("Google results")
visualTest.capture("Google results viewport", {'viewport': True})
finally:
driver.quit()
```
***
### Running Selenium against BitBar
Copy the file from below
Enter BitBar API_KEY and VisualTest PROJECT_TOKEN in the file
```shell
import time
from selenium import webdriver
from sbvt import VisualTest
API_KEY = 'INSERT_BITBAR_APIKEY'
PROJECT_TOKEN = 'INSERT_PROJECT_TOKEN'
def testSmartBearHomePage():
import warnings
warnings.simplefilter("ignore") # turn off tracemalloc socket warnings
caps = {
'platform': 'Linux',
'osVersion': '18.04',
'browserName': 'firefox',
'version': 'latest',
'resolution': '2560x1920',
'bitbar_apiKey': API_KEY,
}
hubUrl = 'https://us-west-desktop-hub.bitbar.com/wd/hub'
driver = webdriver.Remote(command_executor=hubUrl, desired_capabilities=caps)
print(
f'Launching webdriver for {caps["platform"]} {caps["osVersion"]} {caps["browserName"]} {caps["version"]} ')
# load the url
url = 'https://www.smartbear.com'
print(f'Opening URL: {url}')
driver.get(url)
time.sleep(5)
settings = {
'projectToken': PROJECT_TOKEN,
}
visualTest = VisualTest(driver, settings)
# full page screenshot
fullPageScreenshot = visualTest.capture('Home Page')
# viewport screenshot
viewportScreenshot = visualTest.capture('viewport', {'viewport': True})
if __name__ == '__main__':
try:
testSmartBearHomePage()
except Exception as e:
print(f'Error starting test {e}')
```
### Running Selenium Locally
```shell
from sbvt import VisualTest
# pip install selenium==3.141
from selenium import webdriver
from selenium.webdriver.common.by import By
PROJECT_TOKEN = 'INSERT_PROJECT_TOKEN'
driver = webdriver.Chrome('./chromedriver')
driver.get("https://www.smartbear.com")
print(driver.title)
settings = {
'projectToken': PROJECT_TOKEN
}
visualTest = VisualTest(driver, settings)
# full page screenshot
fullPageScreenshot = visualTest.capture('Home Page')
# viewport screenshot
viewportScreenshot = visualTest.capture('viewport', {'viewport': True})
# element screenshot
heroEl = driver.find_element(By.CLASS_NAME, "sb-hp-hero-content")
visualTest.capture('Hero Content', {'element': heroEl})
print(driver.current_url)
driver.close()
```
Raw data
{
"_id": null,
"home_page": "https://github.com/SmartBear/visualtest-python",
"name": "visualtest-python",
"maintainer": null,
"docs_url": null,
"requires_python": null,
"maintainer_email": null,
"keywords": "visual testing, UI testing, GUI testing, UX testing, screenshots, full page screenshots, image comparisons, regression testing",
"author": "Luke Kende",
"author_email": "luke.kende@smartbear.com",
"download_url": null,
"platform": null,
"description": "# VisualTest\n\nThis Python SDK extends the functionality of Selenium WebDriver enabling the script to capture screenshots of the device under test, including fullpage, viewport, and element screenshots for regression testing or manual review of the UI.\n\n```pip install visualtest-python```\n\n ### Quick Setup\n\n```shell\nfrom selenium import webdriver\nfrom sbvt import VisualTest\n\ndriver = webdriver.Safari()\nsettings = {'projectToken': \"INSERT_PROJECT_TOKEN\"}\nvisualTest = VisualTest(driver, settings)\ntry:\n driver.get(\"https://www.google.com/search?q=smartbear\")\n visualTest.capture(\"Google results\")\n visualTest.capture(\"Google results viewport\", {'viewport': True})\nfinally:\n driver.quit()\n```\n\n***\n### Running Selenium against BitBar\nCopy the file from below\n\nEnter BitBar API_KEY and VisualTest PROJECT_TOKEN in the file\n\n```shell\nimport time\nfrom selenium import webdriver\nfrom sbvt import VisualTest\n\nAPI_KEY = 'INSERT_BITBAR_APIKEY'\nPROJECT_TOKEN = 'INSERT_PROJECT_TOKEN'\n\ndef testSmartBearHomePage():\n import warnings\n warnings.simplefilter(\"ignore\") # turn off tracemalloc socket warnings\n\n caps = {\n 'platform': 'Linux',\n 'osVersion': '18.04',\n 'browserName': 'firefox',\n 'version': 'latest',\n 'resolution': '2560x1920',\n 'bitbar_apiKey': API_KEY,\n }\n\n hubUrl = 'https://us-west-desktop-hub.bitbar.com/wd/hub'\n driver = webdriver.Remote(command_executor=hubUrl, desired_capabilities=caps)\n print(\n f'Launching webdriver for {caps[\"platform\"]} {caps[\"osVersion\"]} {caps[\"browserName\"]} {caps[\"version\"]} ')\n\n # load the url\n url = 'https://www.smartbear.com'\n print(f'Opening URL: {url}')\n driver.get(url)\n time.sleep(5)\n\n\n settings = {\n 'projectToken': PROJECT_TOKEN,\n }\n visualTest = VisualTest(driver, settings)\n \n # full page screenshot\n fullPageScreenshot = visualTest.capture('Home Page')\n \n # viewport screenshot\n viewportScreenshot = visualTest.capture('viewport', {'viewport': True})\n \n\nif __name__ == '__main__':\n try:\n testSmartBearHomePage()\n except Exception as e:\n print(f'Error starting test {e}')\n```\n\n### Running Selenium Locally\n\n```shell\nfrom sbvt import VisualTest\n\n# pip install selenium==3.141\nfrom selenium import webdriver\nfrom selenium.webdriver.common.by import By\n\nPROJECT_TOKEN = 'INSERT_PROJECT_TOKEN'\n\ndriver = webdriver.Chrome('./chromedriver')\ndriver.get(\"https://www.smartbear.com\")\nprint(driver.title)\nsettings = {\n 'projectToken': PROJECT_TOKEN\n}\nvisualTest = VisualTest(driver, settings)\n# full page screenshot\nfullPageScreenshot = visualTest.capture('Home Page')\n\n# viewport screenshot\nviewportScreenshot = visualTest.capture('viewport', {'viewport': True})\n\n# element screenshot\nheroEl = driver.find_element(By.CLASS_NAME, \"sb-hp-hero-content\")\nvisualTest.capture('Hero Content', {'element': heroEl})\nprint(driver.current_url)\ndriver.close()\n```\n",
"bugtrack_url": null,
"license": null,
"summary": "Python SDK for SmartBear VisualTest via Selenium WebDriver",
"version": "1.9.2",
"project_urls": {
"Homepage": "https://github.com/SmartBear/visualtest-python"
},
"split_keywords": [
"visual testing",
" ui testing",
" gui testing",
" ux testing",
" screenshots",
" full page screenshots",
" image comparisons",
" regression testing"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "10ac332bb2bb65672e6b411e2e18883d0a0dacec456a9f82edf3256c591863da",
"md5": "6abdfaf15272bf678f9a63c6478dfdf0",
"sha256": "36b18de17b5b86f79551f58f3b403d520d1c5150f428f41dd5a46995fb36dd1b"
},
"downloads": -1,
"filename": "visualtest_python-1.9.2-py3-none-any.whl",
"has_sig": false,
"md5_digest": "6abdfaf15272bf678f9a63c6478dfdf0",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 29118,
"upload_time": "2024-05-14T16:26:52",
"upload_time_iso_8601": "2024-05-14T16:26:52.900746Z",
"url": "https://files.pythonhosted.org/packages/10/ac/332bb2bb65672e6b411e2e18883d0a0dacec456a9f82edf3256c591863da/visualtest_python-1.9.2-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-05-14 16:26:52",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "SmartBear",
"github_project": "visualtest-python",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "visualtest-python"
}