11import json
2- from lambdatest_sdk_utils import is_smartui_enabled ,fetch_dom_serializer ,post_snapshot
2+ import uuid
3+ from lambdatest_sdk_utils import is_smartui_enabled ,fetch_dom_serializer ,post_snapshot ,get_snapshot_status
34from lambdatest_sdk_utils import setup_logger ,get_logger
45
56
@@ -34,13 +35,30 @@ def smartui_snapshot(driver, name,options={}):
3435
3536 # Post the dom to smartui endpoint
3637 dom ['name' ] = name
37- res = post_snapshot (dom ,'lambdatest-selenium-driver' ,options = options )
38+ if 'sync' in options and options ['sync' ] is True :
39+ options ['contextId' ] = str (uuid .uuid4 ())
40+ res = post_snapshot (dom ,'lambdatest-selenium-driver' ,options = options )
3841
39- if res and res .get ('data' ) and res ['data' ].get ('warnings' ) and len (res ['data' ]['warnings' ]) != 0 :
40- for warning in res ['data' ]['warnings' ]:
41- logger .warn (warning )
42+ if res and res .get ('data' ) and res ['data' ].get ('warnings' ) and len (res ['data' ]['warnings' ]) != 0 :
43+ for warning in res ['data' ]['warnings' ]:
44+ logger .warn (warning )
4245
43- logger .info (f'Snapshot captured { name } ' )
46+ logger .info (f'Snapshot captured { name } ' )
47+ timeout = 600
48+ if 'timeout' in options and options ['timeout' ] is not None :
49+ timeout = options ['timeout' ]
50+ if timeout > 900 or timeout < 30 :
51+ timeout = 600
52+ logger .warn ("Timeout value is not valid, allowed range is 30-900 seconds. Defaulting to 600 seconds." )
53+ return get_snapshot_status (name ,options ['contextId' ],timeout )
54+ else :
55+ res = post_snapshot (dom ,'lambdatest-selenium-driver' ,options = options )
56+
57+ if res and res .get ('data' ) and res ['data' ].get ('warnings' ) and len (res ['data' ]['warnings' ]) != 0 :
58+ for warning in res ['data' ]['warnings' ]:
59+ logger .warn (warning )
60+
61+ logger .info (f'Snapshot captured { name } ' )
4462 except Exception as e :
4563 logger .error (f'SmartUI snapshot failed "${ name } "' )
4664 logger .error (e )
0 commit comments