88from lambdatest_sdk_utils .git_utils import get_git_info
99from lambdatest_sdk_utils .models import BuildData , UploadSnapshotRequest
1010from lambdatest_sdk_utils .app_api import create_build , upload_screenshot , stop_build
11+ from lambdatest_sdk_utils .rest import fetch_build_info
1112from lambdatest_selenium_driver .full_page_screenshot_util import FullPageScreenshotUtil
1213
1314# Setup logger
2425OPTION_PAGE_COUNT = "pageCount"
2526OPTION_NAVIGATION_BAR_HEIGHT = "navigationBarHeight"
2627OPTION_STATUS_BAR_HEIGHT = "statusBarHeight"
28+ OPTION_IS_CLI_ENABLED = "isCliEnabled"
2729
2830BROWSER_IOS = "safari"
2931BROWSER_ANDROID = "chrome"
@@ -38,13 +40,14 @@ class SnapshotConfig:
3840 """Configuration object for snapshot capture."""
3941
4042 def __init__ (self , device_name : str , platform : str , test_type : str ,
41- page_count : int , full_page : bool , precise_scroll : bool ):
43+ page_count : int , full_page : bool , precise_scroll : bool , is_cli_enabled : bool ):
4244 self .device_name = device_name
4345 self .platform = platform
4446 self .test_type = test_type
4547 self .page_count = page_count
4648 self .full_page = full_page
4749 self .precise_scroll = precise_scroll
50+ self .is_cli_enabled = is_cli_enabled
4851
4952
5053class SmartUIAppSnapshot :
@@ -139,7 +142,7 @@ def smartui_app_snapshot(self, driver: WebDriver, screenshot_name: str,
139142 try :
140143 config = self ._parse_snapshot_config (options )
141144 self ._validate_mandatory_params (driver , screenshot_name , config .device_name )
142-
145+
143146 upload_request = self ._create_upload_request (driver , screenshot_name , config )
144147 self ._process_screenshot_capture (driver , screenshot_name , config , upload_request , options )
145148 except Exception as e :
@@ -158,7 +161,8 @@ def _parse_snapshot_config(self, options: Dict[str, str]) -> SnapshotConfig:
158161 test_type = test_type ,
159162 page_count = self ._parse_int_option (options , OPTION_PAGE_COUNT , 0 ),
160163 full_page = self ._parse_boolean_option (options , OPTION_FULL_PAGE , False ),
161- precise_scroll = self ._parse_boolean_option (options , OPTION_PRECISE_SCROLL , False )
164+ precise_scroll = self ._parse_boolean_option (options , OPTION_PRECISE_SCROLL , False ),
165+ is_cli_enabled = self ._parse_boolean_option (options , OPTION_IS_CLI_ENABLED , False )
162166 )
163167
164168 def _validate_mandatory_params (self , driver : WebDriver , screenshot_name : str , device_name : str ):
@@ -177,23 +181,24 @@ def _create_upload_request(self, driver: WebDriver, screenshot_name: str,
177181 rect = driver .get_window_rect ()
178182 viewport_string = f"{ rect ['width' ]} x{ rect ['height' ]} "
179183
180- request = self ._initialize_upload_request (screenshot_name , viewport_string )
184+ request = self ._initialize_upload_request (screenshot_name , viewport_string , config )
181185 self ._configure_device_and_platform (request , config .device_name , config .platform )
182186 request .screenshot_hash = str (uuid .uuid4 ())
183187
184188 return request
185189
186- def _initialize_upload_request (self , screenshot_name : str , viewport : str ) -> UploadSnapshotRequest :
190+ def _initialize_upload_request (self , screenshot_name : str , viewport : str , config : SnapshotConfig ) -> UploadSnapshotRequest :
187191 """Initialize upload request with base values."""
188192 request = UploadSnapshotRequest ()
193+ if config .is_cli_enabled :
194+ build_info = fetch_build_info ()
195+ if build_info and "data" in build_info :
196+ self .build_data = BuildData .from_dict (build_info ["data" ])
197+ self .project_token = self .build_data .project_token
198+
189199 request .screenshot_name = screenshot_name
190200 request .project_token = self .project_token
191201 request .viewport = viewport
192- logger .info (f"Viewport set to: { viewport } " )
193-
194- if self .build_data :
195- request .build_id = self .build_data .build_id
196- request .build_name = self .build_data .name
197202
198203 return request
199204
0 commit comments