Skip to content

Instantly share code, notes, and snippets.

@elyezer
Last active February 16, 2018 18:43
Show Gist options
  • Save elyezer/647ea45e93f386d24cf689bccf4b25d7 to your computer and use it in GitHub Desktop.
Save elyezer/647ea45e93f386d24cf689bccf4b25d7 to your computer and use it in GitHub Desktop.
widgestastic + pytest-selenium POC
$ py.test --driver Chrome camayoc/tests/qcs/ui/test_login.py
=============================================== test session starts ===============================================
platform linux -- Python 3.6.4, pytest-3.3.1, py-1.5.2, pluggy-0.6.0
driver: Chrome
sensitiveurl: .*
metadata: {'Python': '3.6.4', 'Platform': 'Linux-4.14.14-300.fc27.x86_64-x86_64-with-fedora-27-Twenty_Seven', 'Packages': {'pytest': '3.3.1', 'py': '1.5.2', 'pluggy': '0.6.0'}, 'Plugins': {'wait-for': '1.0.9', 'xdist': '1.20.1', 'variables': '1.7.1', 'selenium': '1.11.4', 'metadata': '1.5.1', 'html': '1.16.1', 'forked': '0.2', 'cov': '2.5.1', 'base-url': '1.4.1'}, 'Base URL': '', 'Driver': 'Chrome', 'Capabilities': {}}
rootdir: /home/elyezer/code/camayoc, inifile:
plugins: wait-for-1.0.9, xdist-1.20.1, variables-1.7.1, selenium-1.11.4, metadata-1.5.1, html-1.16.1, forked-0.2, cov-2.5.1, base-url-1.4.1
collected 1 item                                                                                                  

camayoc/tests/qcs/ui/test_login.py .                                                                        [100%]

============================================ 1 passed in 3.59 seconds =============================================

I think it worth using pytest-selenium to remove all the boilerplat to configure and have an isolated browser instance for each test. Also it is easy to run locally and the remote browser (such as on a docker container or sauce labs)

from widgetastic.browser import Browser
from widgetastic.widget import View, TextInput
from widgetastic_patternfly import Button
class QuipucordsBrowser(Browser):
pass
class LoginView(View):
login = Button('Log In', classes=[Button.PRIMARY])
username = TextInput(id='id_username')
password = TextInput(id='id_password')
def test_loging(selenium):
selenium.get('http://localhost:8000/')
browser = QuipucordsBrowser(selenium)
login_view = LoginView(browser)
login_view.username.fill('admin')
login_view.password.fill('pass')
login_view.login.click()
assert selenium.current_url == 'http://localhost:8000/client/index.html'
assert selenium.title == 'Red Hat Entitlements Reporting'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment