This is a demo to show how simple it is to create UI tests with SeleniumHQ based on Zalenium.
To try it out you need Python3 and virtualenv and Docker. Download/clone this repo and run run-tests.sh.
This is a demo to show how simple it is to create UI tests with SeleniumHQ based on Zalenium.
To try it out you need Python3 and virtualenv and Docker. Download/clone this repo and run run-tests.sh.
| /venv | |
| *.png | |
| *~ | |
| *.pyc | |
| /.vscode | |
| *.png |
| """ A simple Flask app """ | |
| from flask import Flask | |
| app = Flask(__name__) | |
| @app.route('/') | |
| def hello_world(): | |
| return """<!doctype html> | |
| Hello, World!<br> | |
| <a href="/demo">Demo</a> | |
| """ | |
| @app.route('/demo') | |
| def demo(): | |
| return 'Demo works' |
| pylint | |
| nose2 | |
| Flask | |
| Flask-Testing | |
| selenium==3.3.1 | |
| autopep8 |
| #!/bin/bash | |
| set -e | |
| rm -Rf venv | |
| virtualenv -p python3 --no-site-packages venv | |
| source venv/bin/activate | |
| pip install -r requirements.txt | |
| zalenium=$(curl -sSL https://raw.githubusercontent.com/dosel/t/i/p) | |
| export USE_NET_HOST=true | |
| bash -s stop <<<"$zalenium" | |
| bash -s start <<<"$zalenium" | |
| nose2 | |
| bash -s stop <<<"$zalenium" |
| from selenium import webdriver | |
| from selenium.webdriver.common.desired_capabilities import DesiredCapabilities | |
| from flask import Flask | |
| from flask_testing import LiveServerTestCase | |
| from urllib.error import URLError | |
| class IntegrationTest(LiveServerTestCase): | |
| @classmethod | |
| def setUpClass(cls): | |
| try: | |
| cls.driver = webdriver.Remote( | |
| command_executor='http://127.0.0.1:4444/wd/hub', | |
| desired_capabilities=DesiredCapabilities.CHROME) | |
| except URLError: | |
| print("ERROR: Need selenium grid at %s, please start Zalanium like this:\n" % huburl + | |
| "curl -sSL https://raw.githubusercontent.com/dosel/t/i/p | env USE_NET_HOST=true bash -s start") | |
| exit(99) | |
| @classmethod | |
| def tearDownClass(cls): | |
| cls.driver.quit() | |
| def create_app(self): | |
| from app import app | |
| app.testing = True | |
| app.config['LIVESERVER_PORT'] = 0 | |
| app.config['LIVESERVER_TIMEOUT'] = 10 | |
| return app | |
| def test_main_view(self): | |
| driver = self.driver | |
| driver.get(self.get_server_url()) | |
| driver.get_screenshot_as_file("out1.png") | |
| self.assertIn("Hello", driver.page_source) | |
| def test_follow_link(self): | |
| driver = self.driver | |
| driver.get(self.get_server_url()) | |
| driver.get_screenshot_as_file("out2.png") | |
| try: | |
| driver.find_element_by_link_text("Demo").click() | |
| except BaseException: | |
| self.fail("Could not find link 'Demo'") | |
| driver.get_screenshot_as_file("out3.png") | |
| self.assertIn("works", driver.page_source) |