16
16
from pyvirtualdisplay import Display
17
17
from seleniumbase .config import settings
18
18
from seleniumbase .core .application_manager import ApplicationManager
19
+ from seleniumbase .core .s3_manager import S3LoggingBucket
19
20
from seleniumbase .core .testcase_manager import ExecutionQueryPayload
20
21
from seleniumbase .core .testcase_manager import TestcaseDataPayload
21
22
from seleniumbase .core .testcase_manager import TestcaseManager
@@ -340,6 +341,11 @@ def setUp(self):
340
341
self .headless_active = False
341
342
self .with_testing_base = pytest .config .option .with_testing_base
342
343
self .with_db_reporting = pytest .config .option .with_db_reporting
344
+ self .with_s3_logging = pytest .config .option .with_s3_logging
345
+ self .with_screen_shots = pytest .config .option .with_screen_shots
346
+ self .with_basic_test_info = (
347
+ pytest .config .option .with_basic_test_info )
348
+ self .with_page_source = pytest .config .option .with_page_source
343
349
self .database_env = pytest .config .option .database_env
344
350
self .log_path = pytest .config .option .log_path
345
351
self .browser = pytest .config .option .browser
@@ -416,13 +422,24 @@ def tearDown(self):
416
422
test_logpath = self .log_path + "/" + test_id
417
423
if not os .path .exists (test_logpath ):
418
424
os .makedirs (test_logpath )
419
- # Handle screenshot logging
420
- log_helper .log_screenshot (test_logpath , self .driver )
421
- # Handle basic test info logging
422
- log_helper .log_test_failure_data (
423
- test_logpath , self .driver , self .browser )
424
- # Handle page source logging
425
- log_helper .log_page_source (test_logpath , self .driver )
425
+ if ((not self .with_screen_shots ) and
426
+ (not self .with_basic_test_info ) and
427
+ (not self .with_page_source )):
428
+ # Log everything if nothing specified (if testing_base)
429
+ log_helper .log_screenshot (test_logpath , self .driver )
430
+ log_helper .log_test_failure_data (
431
+ test_logpath , self .driver , self .browser )
432
+ log_helper .log_page_source (test_logpath , self .driver )
433
+ else :
434
+ if self .with_screen_shots :
435
+ log_helper .log_screenshot (
436
+ test_logpath , self .driver )
437
+ if self .with_basic_test_info :
438
+ log_helper .log_test_failure_data (
439
+ test_logpath , self .driver , self .browser )
440
+ if self .with_page_source :
441
+ log_helper .log_page_source (
442
+ test_logpath , self .driver )
426
443
# Finally close the browser
427
444
self .driver .quit ()
428
445
if self .headless :
@@ -436,3 +453,27 @@ def tearDown(self):
436
453
runtime = int (time .time () * 1000 ) - self .execution_start_time
437
454
self .testcase_manager .update_execution_data (
438
455
self .execution_guid , runtime )
456
+ if self .with_s3_logging and (sys .exc_info ()[1 ] is not None ):
457
+ """ After each testcase, upload logs to the S3 bucket. """
458
+ s3_bucket = S3LoggingBucket ()
459
+ guid = str (uuid .uuid4 ().hex )
460
+ path = "%s/%s" % (self .log_path , test_id )
461
+ uploaded_files = []
462
+ for logfile in os .listdir (path ):
463
+ logfile_name = "%s/%s/%s" % (guid ,
464
+ test_id ,
465
+ logfile .split (path )[- 1 ])
466
+ s3_bucket .upload_file (logfile_name ,
467
+ "%s/%s" % (path , logfile ))
468
+ uploaded_files .append (logfile_name )
469
+ s3_bucket .save_uploaded_file_names (uploaded_files )
470
+ index_file = s3_bucket .upload_index_file (test_id , guid )
471
+ print "\n \n *** Log files uploaded: ***\n %s\n " % index_file
472
+ logging .error (
473
+ "\n \n *** Log files uploaded: ***\n %s\n " % index_file )
474
+ if self .with_db_reporting :
475
+ self .testcase_manager = TestcaseManager (self .database_env )
476
+ data_payload = TestcaseDataPayload ()
477
+ data_payload .guid = guid
478
+ data_payload .logURL = index_file
479
+ self .testcase_manager .update_testcase_log_url (data_payload )
0 commit comments