Initial set up for Ghost Inspector integration tests.

Adds a CircleCI integration for Ghost Inspector
(https://ghostinspector.com), a headless browser testing SaaS. The
README is updated with details about how to run GI locally.

Removes the bootstrap setup for Selenium testing with BrowserStack.
This commit is contained in:
dandds
2019-10-10 09:22:10 -04:00
parent 73a459ea28
commit 7949c64b9b
8 changed files with 101 additions and 172 deletions

View File

@@ -1,18 +0,0 @@
BROWSERSTACK_CONFIG = {
"win7_ie10": {
"browser": "IE",
"browser_version": "10.0",
"os": "Windows",
"os_version": "7",
"resolution": "1024x768",
"browserstack.local": True,
},
"win10_chrome62": {
"browser": "Chrome",
"browser_version": "62.0",
"os": "Windows",
"os_version": "10",
"resolution": "1024x768",
"browserstack.local": True,
},
}

View File

@@ -1,65 +0,0 @@
import os
import pytest
import logging
from collections import Mapping
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from .browsers import BROWSERSTACK_CONFIG
@pytest.fixture(scope="function", autouse=True)
def session(db, request):
"""
Override base test session
"""
pass
class DriverCollection(Mapping):
"""
Allows access to drivers with dictionary syntax. Keeps track of which ones
have already been initialized. Allows teardown of all existing drivers.
"""
def __init__(self):
self._drivers = {}
def __iter__(self):
return iter(self._drivers)
def __len__(self):
return len(self._drivers)
def __getitem__(self, name):
if name in self._drivers:
return self._drivers[name]
elif name in BROWSERSTACK_CONFIG:
self._drivers[name] = self._build_driver(name)
return self._drivers[name]
else:
raise AttributeError("Driver {} not found".format(name))
def _build_driver(self, config_key):
return webdriver.Remote(
command_executor="http://{}:{}@hub.browserstack.com:80/wd/hub".format(
os.getenv("BROWSERSTACK_EMAIL"), os.getenv("BROWSERSTACK_TOKEN")
),
desired_capabilities=BROWSERSTACK_CONFIG.get(config_key),
)
def teardown(self):
for driver in self._drivers.values():
driver.quit()
@pytest.fixture(scope="session")
def drivers():
driver_collection = DriverCollection()
yield driver_collection
driver_collection.teardown()

View File

@@ -1,50 +0,0 @@
import pytest
import requests
from flask import url_for
from urllib.parse import urljoin
from .browsers import BROWSERSTACK_CONFIG
from atst.domain.users import Users
import atst.domain.exceptions as exceptions
from atst.routes.dev import _DEV_USERS as DEV_USERS
from tests.test_auth import _login
import cryptography.x509 as x509
from cryptography.hazmat.backends import default_backend
USER_CERT = "ssl/client-certs/atat.mil.crt"
@pytest.mark.parametrize("browser_type", BROWSERSTACK_CONFIG.keys())
@pytest.mark.usefixtures("live_server")
def test_can_get_title(browser_type, app, drivers):
driver = drivers[browser_type]
driver.get(url_for("atst.root", _external=True))
assert "JEDI" in driver.title
def _get_common_name(cert_path):
with open(USER_CERT, "rb") as cert_file:
cert = x509.load_pem_x509_certificate(cert_file.read(), default_backend())
common_names = cert.subject.get_attributes_for_oid(x509.NameOID.COMMON_NAME)
return common_names[0].value
@pytest.fixture(scope="module")
def valid_user_from_cert():
cn = _get_common_name(USER_CERT)
cn_parts = cn.split(".")
user_info = {
"last_name": cn_parts[0],
"first_name": cn_parts[1],
"dod_id": cn_parts[-1],
"atat_role_name": "developer",
}
return Users.get_or_create_by_dod_id(**user_info)
@pytest.mark.usefixtures("live_server")
def test_login(drivers, client, app, valid_user_from_cert):
driver = drivers["win7_ie10"]
driver.get(url_for("dev.login_dev", _external=True))
assert "Sign in" not in driver.title