Skip to content

Commit a1bb37a

Browse files
fetch build from local cli
1 parent 84003f7 commit a1bb37a

File tree

3 files changed

+27
-11
lines changed

3 files changed

+27
-11
lines changed

selenium/lambdatest_selenium_driver/smartui_app_snapshot.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from lambdatest_sdk_utils.git_utils import get_git_info
99
from lambdatest_sdk_utils.models import BuildData, UploadSnapshotRequest
1010
from lambdatest_sdk_utils.app_api import create_build, upload_screenshot, stop_build
11+
from lambdatest_sdk_utils.rest import fetch_build_info
1112
from lambdatest_selenium_driver.full_page_screenshot_util import FullPageScreenshotUtil
1213

1314
# Setup logger
@@ -24,6 +25,7 @@
2425
OPTION_PAGE_COUNT = "pageCount"
2526
OPTION_NAVIGATION_BAR_HEIGHT = "navigationBarHeight"
2627
OPTION_STATUS_BAR_HEIGHT = "statusBarHeight"
28+
OPTION_IS_CLI_ENABLED = "isCliEnabled"
2729

2830
BROWSER_IOS = "safari"
2931
BROWSER_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

5053
class 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

utils/lambdatest_sdk_utils/models.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ class BuildData:
99
build_url: Optional[str] = None
1010
baseline: Optional[bool] = None
1111
name: Optional[str] = None
12+
project_token: Optional[str] = None
1213

1314
def to_dict(self):
1415
return {
@@ -24,7 +25,8 @@ def from_dict(cls, data: dict):
2425
build_id=data.get("buildId"),
2526
build_url=data.get("buildURL"),
2627
baseline=data.get("baseline"),
27-
name=data.get("buildName")
28+
name=data.get("buildName"),
29+
project_token=data.get("projectToken")
2830
)
2931

3032

utils/lambdatest_sdk_utils/rest.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,13 @@ def get_snapshot_status(snapshot_name,context_id,timeout):
5858
except Exception as e:
5959
logger.debug(f'get snapshot status failed : {e}')
6060
raise Exception(f'get snapshot status failed')
61+
62+
def fetch_build_info():
63+
try:
64+
response = requests.get(f'{get_smart_ui_server_address()}/build/info')
65+
response.raise_for_status()
66+
return response.json()
67+
except Exception as e:
68+
logger.debug(f'fetch build info failed : {e}')
69+
raise Exception(f'fetch build info failed')
6170

0 commit comments

Comments
 (0)