Skip to main content

Python SDK for SmartBear VisualTest via Selenium WebDriver

Project description

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

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

import unittest
import time
from selenium import webdriver
from sbvt import VisualTest

API_KEY = 'INSERT_BITBAR_APIKEY'
PROJECT_TOKEN = 'INSERT_PROJECT_TOKEN'

class TestSmartbearHomePage(unittest.TestCase):

    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:
        unittest.main()
    except Exception as e:
        print(f'Error starting test {e}')

Running Selenium Locally

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

visualtest_python-1.0.0b6-py3-none-any.whl (20.9 kB view details)

Uploaded Python 3

File details

Details for the file visualtest_python-1.0.0b6-py3-none-any.whl.

File metadata

File hashes

Hashes for visualtest_python-1.0.0b6-py3-none-any.whl
Algorithm Hash digest
SHA256 b461b395122348cd3c4b79c380bb1ed7bb87651b6e3ff34ec48aa86886c49a62
MD5 5e255bdd05955ab09d2afafc3543e1e0
BLAKE2b-256 c367a0dee5e650a0901612606498038b66ed0c6b32909039d5e46bf0b0f24592

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