53
53
"""
54
54
55
55
ARTIFACTS_DIR = "/app/artifacts"
56
- PROD_BASE_URL = "https://flybase.org"
57
56
DEFAULT_POST_LOAD_WAIT_S = 1.5
58
57
CLICK_WAIT_TIMEOUT_S = 10 # Timeout for finding/waiting for elements
59
58
DEFAULT_WAIT_AFTER_CLICK_S = 1.0
@@ -337,14 +336,15 @@ def load_yaml_config(config_path):
337
336
try :
338
337
with open (config_path , 'r' , encoding = 'utf-8' ) as file :
339
338
config = yaml .safe_load (file )
339
+ comparison_url = config .get ("COMPARISON_URL" , "https://flybase.org" )
340
340
tests = config .get ("tests" )
341
341
if tests is None :
342
342
print (f"Warning: 'tests' key not found in { config_path } . Returning empty list." )
343
- return []
343
+ return [], comparison_url
344
344
if not isinstance (tests , list ):
345
345
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
348
348
except FileNotFoundError :
349
349
print (f"Error: Configuration file not found at { config_path } " )
350
350
sys .exit (1 )
@@ -398,7 +398,7 @@ def parse_api_response(response):
398
398
return {"result" : result_status , "failed_component" : failed_component , "explanation" : explanation }
399
399
400
400
401
- def run_test (driver , test_def ):
401
+ def run_test (driver , test_def , comparison_url ):
402
402
"""
403
403
Execute a test: navigate, wait, perform actions, capture, analyze.
404
404
Returns a dict with test name, prompt, result, failed_component, and explanation.
@@ -415,6 +415,20 @@ def run_test(driver, test_def):
415
415
ticket = test_def .get ("ticket" , "" )
416
416
actions_to_perform = test_def .get ("actions_before_capture" , [])
417
417
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
+
418
432
# --- Pre-checks ---
419
433
if not enabled :
420
434
print (f"Skipping disabled test: { test_name } " )
@@ -432,7 +446,7 @@ def run_test(driver, test_def):
432
446
parsed_target = urlparse (preview_url )
433
447
path = parsed_target .path if parsed_target .path else "/"
434
448
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 ('/' ))
436
450
except Exception as e :
437
451
print (f"Warning: Could not construct production URL for comparison from { preview_url } : { e } " )
438
452
compare_to_production = False
@@ -463,7 +477,7 @@ def run_test(driver, test_def):
463
477
try :
464
478
if compare_to_production : # This implies prod_url is valid
465
479
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 } " })
467
481
user_content_parts .append ({"type" : "text" , "text" : f"Preview URL: { preview_url } " })
468
482
469
483
# --- Production Data Capture ---
@@ -477,22 +491,22 @@ def run_test(driver, test_def):
477
491
478
492
if "text" in check_types and not action_failure :
479
493
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" )
481
495
try :
482
496
with open (prod_text_path , "w" , encoding = "utf-8" ) as f : f .write (prod_text )
483
497
print (f" Saved text artifact: { prod_text_path } " )
484
498
except Exception as e : print (f" Warning: Could not save prod text file: { e } " )
485
- user_content_parts .append ({"type" : "text" , "text" : f"\n Production Text :\n ```\n { prod_text } \n ```" })
499
+ user_content_parts .append ({"type" : "text" , "text" : f"\n { prod_text_label } :\n ```\n { prod_text } \n ```" })
486
500
elif "text" in check_types and action_failure :
487
- user_content_parts .append ({"type" : "text" , "text" : " \n Production Text : (Skipped due to action failure)" })
501
+ user_content_parts .append ({"type" : "text" , "text" : f" \n { prod_text_label } : (Skipped due to action failure)" })
488
502
489
503
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" )
491
505
prod_screenshot_bytes = capture_page_screenshot (driver , prod_screenshot_path )
492
506
prod_img_uri = encode_image_to_data_uri (prod_screenshot_bytes )
493
507
if prod_img_uri :
494
508
screenshots_data .append ({"type" : "image_url" , "image_url" : {"url" : prod_img_uri }})
495
- user_content_parts .append ({"type" : "text" , "text" : " \n Production Screenshot :" })
509
+ user_content_parts .append ({"type" : "text" , "text" : f" \n { prod_label } :" })
496
510
else : print (f" Warning: Failed to get Production screenshot" )
497
511
498
512
# --- Preview Data Capture ---
@@ -594,7 +608,7 @@ def main(config_path):
594
608
print (f"Artifacts will be saved to container path: { ARTIFACTS_DIR } " )
595
609
except OSError as e : print (f"Error creating artifacts directory { ARTIFACTS_DIR } : { e } " )
596
610
597
- tests = load_yaml_config (config_path )
611
+ tests , comparison_url = load_yaml_config (config_path )
598
612
if not tests : print ("No tests found/loaded." ); return
599
613
600
614
driver = None
@@ -606,7 +620,7 @@ def main(config_path):
606
620
print (f"Warning: Skipping invalid test definition: { test_def } " ); continue
607
621
result = None
608
622
try :
609
- result = run_test (driver , test_def )
623
+ result = run_test (driver , test_def , comparison_url )
610
624
except Exception as err :
611
625
test_name_fallback = test_def .get ("name" , "Unknown Test" )
612
626
prompt_fallback = test_def .get ("prompt" , "" )
0 commit comments