-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #513 from NASA-IMPACT/512-add-functional-test-to-o…
…pen-a-collection-on-each-environment Add functional test for investigating a collection using Selenium
- Loading branch information
Showing
1 changed file
with
69 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import json | ||
import time | ||
import urllib.parse | ||
|
||
from selenium import webdriver | ||
from selenium.webdriver.chrome.service import Service | ||
from webdriver_manager.chrome import ChromeDriverManager | ||
|
||
COLLECTION_CONFIG_FOLDER = "mast" | ||
|
||
|
||
def server_url(config_folder, server="test", secret=True) -> str: | ||
URLS = { | ||
"test": "https://sciencediscoveryengine.test.nasa.gov", | ||
"prod": "https://sciencediscoveryengine.nasa.gov", | ||
} | ||
if secret: | ||
query = "query-sde-primary" | ||
app = "nasa-sba-sde" | ||
folder = "SDE" | ||
else: | ||
query = "query-smd-primary" | ||
app = "nasa-sba-smd" | ||
folder = "SMD" | ||
|
||
base_url = URLS[server] | ||
payload = { | ||
"name": query, | ||
"scope": "All", | ||
"text": "", | ||
"advanced": { | ||
"collection": f"/{folder}/{config_folder}/", | ||
}, | ||
} | ||
encoded_payload = urllib.parse.quote(json.dumps(payload)) | ||
return f"{base_url}/app/{app}/#/search?query={encoded_payload}" | ||
|
||
|
||
# Set up the Chrome WebDriver | ||
service = Service(ChromeDriverManager().install()) | ||
options = webdriver.ChromeOptions() | ||
|
||
# Initialize the browser | ||
driver = webdriver.Chrome(service=service, options=options) | ||
|
||
first = True | ||
n = 0 | ||
for server in ["test", "prod"]: | ||
for secret in [True, False]: | ||
if not first: | ||
n += 1 | ||
driver.execute_script("window.open('');") | ||
driver.switch_to.window(driver.window_handles[n]) | ||
driver.get(server_url(COLLECTION_CONFIG_FOLDER, server=server, secret=secret)) | ||
time.sleep(1) | ||
new_title = f"{'Secret' if secret else 'Regular'}{server.title()}" | ||
driver.execute_script("document.title = arguments[0]", new_title) | ||
first = False | ||
driver.switch_to.window(driver.window_handles[0]) | ||
|
||
# Keep the browser open indefinitely | ||
try: | ||
while True: | ||
time.sleep(1) | ||
except KeyboardInterrupt: | ||
print("Exiting the script...") | ||
|
||
# Close the browser after some time or interaction | ||
driver.quit() |