-
Notifications
You must be signed in to change notification settings - Fork 423
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #3341 - Adding basic python playwright browser test
Fixes #3341 - Adding basic python playwright browser test
- Loading branch information
1 parent
039d3e3
commit e025672
Showing
6 changed files
with
39 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,7 +33,7 @@ bravado_core | |
pytest | ||
pytest-cache | ||
pytest-cov | ||
selenium | ||
playwright | ||
webtest | ||
# dev | ||
build | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -87,7 +87,7 @@ test = [ | |
"pytest", | ||
"pytest-cache", | ||
"pytest-cov", | ||
"selenium", | ||
"playwright", | ||
"webtest", | ||
] | ||
dev = [ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,68 +1,38 @@ | ||
import time | ||
import re | ||
import unittest | ||
from urllib.parse import urljoin | ||
|
||
import requests | ||
from selenium import webdriver | ||
from selenium.webdriver.common.by import By | ||
from playwright.sync_api import expect, sync_playwright | ||
|
||
|
||
SERVER_URL = "http://localhost:8888/v1" | ||
DEFAULT_AUTH = ("user", "p4ssw0rd") | ||
baseUrl = "http://localhost:8888/v1/" | ||
auth = {"user": "user", "password": "p4ssw0rd"} | ||
|
||
browser = sync_playwright().start().firefox.launch() | ||
context = browser.new_context(base_url=baseUrl) | ||
page = browser.new_page() | ||
|
||
|
||
class BrowserTest(unittest.TestCase): | ||
def setUp(self): | ||
options = webdriver.FirefoxOptions() | ||
options.headless = True | ||
self.driver = webdriver.Firefox(options=options) | ||
self.driver.implicitly_wait(10) # seconds | ||
|
||
@classmethod | ||
def setUpClass(cls): | ||
# Make sure our user exists. | ||
requests.post( | ||
urljoin(SERVER_URL, "/accounts"), | ||
json={"data": {"id": DEFAULT_AUTH[0], "password": DEFAULT_AUTH[1]}}, | ||
) | ||
|
||
# Create a bucket and a collection for our user. | ||
bucket_url = urljoin(SERVER_URL, "/buckets/workspace") | ||
collection_url = f"{bucket_url}/collections/articles" | ||
session = requests.Session() | ||
session.auth = DEFAULT_AUTH | ||
resp = session.put(bucket_url) | ||
resp.raise_for_status() | ||
resp = session.put(collection_url) | ||
resp.raise_for_status() | ||
request = context.request | ||
|
||
def tearDown(self): | ||
self.driver.close() | ||
request.post("accounts", data={"data": {"id": auth["user"], "password": auth["password"]}}) | ||
|
||
def test_admin_ui_renders_properly(self): | ||
base_url = urljoin(SERVER_URL, "/v1/admin/") | ||
self.driver.get(base_url) | ||
def test_login_and_view_home_page(self): | ||
page.goto(f"{baseUrl}admin/") | ||
|
||
# Load auth page. | ||
header = self.driver.find_element(By.CSS_SELECTOR, ".content div > h1") | ||
self.assertIn("Administration", header.text) | ||
self.assertTrue(header.is_displayed()) | ||
expect(page).to_have_title(re.compile("Kinto Administration")) | ||
|
||
# Select Kinto Accounts. | ||
radio = self.driver.find_element(By.XPATH, "//label[contains(.,'Kinto Account Auth')]") | ||
radio.click() | ||
page.get_by_label("Kinto Account Auth").click() | ||
txtUsername = page.get_by_label(re.compile("Username")) | ||
txtPassword = page.get_by_label(re.compile("Password")) | ||
|
||
# Fill username and password. | ||
user_field = self.driver.find_element(By.ID, "root_credentials_username") | ||
user_field.send_keys(DEFAULT_AUTH[0]) | ||
user_pass = self.driver.find_element(By.ID, "root_credentials_password") | ||
user_pass.send_keys(DEFAULT_AUTH[1]) | ||
# Login | ||
submit = self.driver.find_element(By.CSS_SELECTOR, "button[type='submit']") | ||
submit.click() | ||
txtUsername.fill(auth["user"]) | ||
txtPassword.fill(auth["password"]) | ||
page.get_by_text(re.compile("Sign in using Kinto Account Auth")).click() | ||
|
||
# Navigate to simple review page (uses React Hooks and broke a few times) | ||
review_url = base_url + "#/buckets/workspace/collections/articles/simple-review" | ||
self.driver.get(review_url) | ||
time.sleep(1) | ||
self.assertTrue(self.driver.find_element(By.CSS_SELECTOR, ".alert-warning").is_displayed()) | ||
expect(page.get_by_text("Kinto Administration")).to_be_visible() | ||
expect(page.get_by_text("project_name")).to_be_visible() | ||
expect(page.get_by_text("project_version")).to_be_visible() | ||
expect(page.get_by_text("http_api_version")).to_be_visible() | ||
expect(page.get_by_text("project_docs")).to_be_visible() |