Skip to content

Commit 8f8a7ca

Browse files
committed
Added flexibility for comparison URL.
1 parent 1a9a8d7 commit 8f8a7ca

File tree

2 files changed

+32
-14
lines changed

2 files changed

+32
-14
lines changed

main.py

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@
5353
"""
5454

5555
ARTIFACTS_DIR = "/app/artifacts"
56-
PROD_BASE_URL = "https://flybase.org"
5756
DEFAULT_POST_LOAD_WAIT_S = 1.5
5857
CLICK_WAIT_TIMEOUT_S = 10 # Timeout for finding/waiting for elements
5958
DEFAULT_WAIT_AFTER_CLICK_S = 1.0
@@ -337,14 +336,15 @@ def load_yaml_config(config_path):
337336
try:
338337
with open(config_path, 'r', encoding='utf-8') as file:
339338
config = yaml.safe_load(file)
339+
comparison_url = config.get("COMPARISON_URL", "https://flybase.org")
340340
tests = config.get("tests")
341341
if tests is None:
342342
print(f"Warning: 'tests' key not found in {config_path}. Returning empty list.")
343-
return []
343+
return [], comparison_url
344344
if not isinstance(tests, list):
345345
print(f"Warning: 'tests' key in {config_path} is not a list. Returning empty list.")
346-
return []
347-
return tests
346+
return [], comparison_url
347+
return tests, comparison_url
348348
except FileNotFoundError:
349349
print(f"Error: Configuration file not found at {config_path}")
350350
sys.exit(1)
@@ -398,7 +398,7 @@ def parse_api_response(response):
398398
return {"result": result_status, "failed_component": failed_component, "explanation": explanation}
399399

400400

401-
def run_test(driver, test_def):
401+
def run_test(driver, test_def, comparison_url):
402402
"""
403403
Execute a test: navigate, wait, perform actions, capture, analyze.
404404
Returns a dict with test name, prompt, result, failed_component, and explanation.
@@ -415,6 +415,20 @@ def run_test(driver, test_def):
415415
ticket = test_def.get("ticket", "")
416416
actions_to_perform = test_def.get("actions_before_capture", [])
417417

418+
# --- Label and Suffix Logic ---
419+
if comparison_url == "https://flybase.org":
420+
prod_label = "Production Screenshot"
421+
prod_text_label = "Production Text"
422+
prod_suffix = "_prod"
423+
elif comparison_url == "https://stage.flybase.org":
424+
prod_label = "Staging Screenshot"
425+
prod_text_label = "Staging Text"
426+
prod_suffix = "_stage"
427+
else:
428+
prod_label = "Production Screenshot"
429+
prod_text_label = "Production Text"
430+
prod_suffix = "_prod"
431+
418432
# --- Pre-checks ---
419433
if not enabled:
420434
print(f"Skipping disabled test: {test_name}")
@@ -432,7 +446,7 @@ def run_test(driver, test_def):
432446
parsed_target = urlparse(preview_url)
433447
path = parsed_target.path if parsed_target.path else "/"
434448
prod_path_query_fragment = urlunparse(('', '', path, parsed_target.params, parsed_target.query, parsed_target.fragment))
435-
prod_url = urljoin(PROD_BASE_URL.rstrip('/') + '/', prod_path_query_fragment.lstrip('/'))
449+
prod_url = urljoin(comparison_url.rstrip('/') + '/', prod_path_query_fragment.lstrip('/'))
436450
except Exception as e:
437451
print(f"Warning: Could not construct production URL for comparison from {preview_url}: {e}")
438452
compare_to_production = False
@@ -463,7 +477,7 @@ def run_test(driver, test_def):
463477
try:
464478
if compare_to_production: # This implies prod_url is valid
465479
user_content_parts.append({"type": "text", "text": f"\n--- Comparing Production vs Preview ---"})
466-
user_content_parts.append({"type": "text", "text": f"Production URL: {prod_url}"})
480+
user_content_parts.append({"type": "text", "text": f"{prod_label}: {prod_url}"})
467481
user_content_parts.append({"type": "text", "text": f"Preview URL: {preview_url}"})
468482

469483
# --- Production Data Capture ---
@@ -477,22 +491,22 @@ def run_test(driver, test_def):
477491

478492
if "text" in check_types and not action_failure:
479493
prod_text = capture_page_text(driver)
480-
prod_text_path = os.path.join(ARTIFACTS_DIR, f"{safe_test_name}_prod.txt")
494+
prod_text_path = os.path.join(ARTIFACTS_DIR, f"{safe_test_name}{prod_suffix}.txt")
481495
try:
482496
with open(prod_text_path, "w", encoding="utf-8") as f: f.write(prod_text)
483497
print(f" Saved text artifact: {prod_text_path}")
484498
except Exception as e: print(f" Warning: Could not save prod text file: {e}")
485-
user_content_parts.append({"type": "text", "text": f"\nProduction Text:\n```\n{prod_text}\n```"})
499+
user_content_parts.append({"type": "text", "text": f"\n{prod_text_label}:\n```\n{prod_text}\n```"})
486500
elif "text" in check_types and action_failure:
487-
user_content_parts.append({"type": "text", "text": "\nProduction Text: (Skipped due to action failure)"})
501+
user_content_parts.append({"type": "text", "text": f"\n{prod_text_label}: (Skipped due to action failure)"})
488502

489503
if "picture" in check_types:
490-
prod_screenshot_path = os.path.join(ARTIFACTS_DIR, f"{safe_test_name}_prod.png")
504+
prod_screenshot_path = os.path.join(ARTIFACTS_DIR, f"{safe_test_name}{prod_suffix}.png")
491505
prod_screenshot_bytes = capture_page_screenshot(driver, prod_screenshot_path)
492506
prod_img_uri = encode_image_to_data_uri(prod_screenshot_bytes)
493507
if prod_img_uri:
494508
screenshots_data.append({"type": "image_url", "image_url": {"url": prod_img_uri}})
495-
user_content_parts.append({"type": "text", "text": "\nProduction Screenshot:"})
509+
user_content_parts.append({"type": "text", "text": f"\n{prod_label}:"})
496510
else: print(f" Warning: Failed to get Production screenshot")
497511

498512
# --- Preview Data Capture ---
@@ -594,7 +608,7 @@ def main(config_path):
594608
print(f"Artifacts will be saved to container path: {ARTIFACTS_DIR}")
595609
except OSError as e: print(f"Error creating artifacts directory {ARTIFACTS_DIR}: {e}")
596610

597-
tests = load_yaml_config(config_path)
611+
tests, comparison_url = load_yaml_config(config_path)
598612
if not tests: print("No tests found/loaded."); return
599613

600614
driver = None
@@ -606,7 +620,7 @@ def main(config_path):
606620
print(f"Warning: Skipping invalid test definition: {test_def}"); continue
607621
result = None
608622
try:
609-
result = run_test(driver, test_def)
623+
result = run_test(driver, test_def, comparison_url)
610624
except Exception as err:
611625
test_name_fallback = test_def.get("name", "Unknown Test")
612626
prompt_fallback = test_def.get("prompt", "")

test_config.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# Please set the comparison URL to either production or staging.
2+
COMPARISON_URL: "https://flybase.org"
3+
# COMPARISON_URL: "https://staging.flybase.org"
4+
15
tests:
26
- name: "GAL4 Drivers Table Broken Page"
37
enabled: true

0 commit comments

Comments
 (0)