shu/removeSettingsManager.get_settings (#1305)
This commit is contained in:
@@ -12,6 +12,7 @@ import structlog
|
||||
from playwright.async_api import FileChooser, Frame, Locator, Page, TimeoutError
|
||||
from pydantic import BaseModel
|
||||
|
||||
from skyvern.config import settings
|
||||
from skyvern.constants import REPO_ROOT_DIR, SKYVERN_ID_ATTR
|
||||
from skyvern.exceptions import (
|
||||
EmptySelect,
|
||||
@@ -52,7 +53,6 @@ from skyvern.forge.sdk.db.enums import OrganizationAuthTokenType
|
||||
from skyvern.forge.sdk.models import Step
|
||||
from skyvern.forge.sdk.schemas.tasks import Task
|
||||
from skyvern.forge.sdk.services.bitwarden import BitwardenConstants
|
||||
from skyvern.forge.sdk.settings_manager import SettingsManager
|
||||
from skyvern.webeye.actions import actions
|
||||
from skyvern.webeye.actions.actions import (
|
||||
Action,
|
||||
@@ -371,7 +371,7 @@ async def handle_click_action(
|
||||
page,
|
||||
action,
|
||||
skyvern_element,
|
||||
timeout=SettingsManager.get_settings().BROWSER_ACTION_TIMEOUT_MS,
|
||||
timeout=settings.BROWSER_ACTION_TIMEOUT_MS,
|
||||
)
|
||||
|
||||
if results and task.workflow_run_id and download_dir:
|
||||
@@ -400,8 +400,8 @@ async def handle_click_to_download_file_action(
|
||||
locator = skyvern_element.locator
|
||||
|
||||
try:
|
||||
await locator.click(timeout=SettingsManager.get_settings().BROWSER_ACTION_TIMEOUT_MS)
|
||||
await page.wait_for_load_state(timeout=SettingsManager.get_settings().BROWSER_LOADING_TIMEOUT_MS)
|
||||
await locator.click(timeout=settings.BROWSER_ACTION_TIMEOUT_MS)
|
||||
await page.wait_for_load_state(timeout=settings.BROWSER_LOADING_TIMEOUT_MS)
|
||||
except Exception as e:
|
||||
LOG.exception("ClickAction with download failed", action=action, exc_info=True)
|
||||
return [ActionFailure(e, download_triggered=False)]
|
||||
@@ -420,7 +420,7 @@ async def handle_input_text_action(
|
||||
skyvern_element = await dom.get_skyvern_element_by_id(action.element_id)
|
||||
skyvern_frame = await SkyvernFrame.create_instance(skyvern_element.get_frame())
|
||||
incremental_scraped = IncrementalScrapePage(skyvern_frame=skyvern_frame)
|
||||
timeout = SettingsManager.get_settings().BROWSER_ACTION_TIMEOUT_MS
|
||||
timeout = settings.BROWSER_ACTION_TIMEOUT_MS
|
||||
|
||||
current_text = await get_input_value(skyvern_element.get_tag_name(), skyvern_element.get_locator())
|
||||
if current_text == action.text:
|
||||
@@ -656,7 +656,7 @@ async def handle_upload_file_action(
|
||||
if file_path:
|
||||
await locator.set_input_files(
|
||||
file_path,
|
||||
timeout=SettingsManager.get_settings().BROWSER_ACTION_TIMEOUT_MS,
|
||||
timeout=settings.BROWSER_ACTION_TIMEOUT_MS,
|
||||
)
|
||||
|
||||
# Sleep for 10 seconds after uploading a file to let the page process it
|
||||
@@ -675,7 +675,7 @@ async def handle_upload_file_action(
|
||||
page,
|
||||
action,
|
||||
skyvern_element,
|
||||
timeout=SettingsManager.get_settings().BROWSER_ACTION_TIMEOUT_MS,
|
||||
timeout=settings.BROWSER_ACTION_TIMEOUT_MS,
|
||||
)
|
||||
|
||||
|
||||
@@ -699,7 +699,7 @@ async def handle_download_file_action(
|
||||
|
||||
locator = skyvern_element.locator
|
||||
await locator.click(
|
||||
timeout=SettingsManager.get_settings().BROWSER_ACTION_TIMEOUT_MS,
|
||||
timeout=settings.BROWSER_ACTION_TIMEOUT_MS,
|
||||
modifiers=["Alt"],
|
||||
)
|
||||
|
||||
@@ -847,7 +847,7 @@ async def handle_select_option_action(
|
||||
action=action,
|
||||
)
|
||||
|
||||
timeout = SettingsManager.get_settings().BROWSER_ACTION_TIMEOUT_MS
|
||||
timeout = settings.BROWSER_ACTION_TIMEOUT_MS
|
||||
skyvern_frame = await SkyvernFrame.create_instance(skyvern_element.get_frame())
|
||||
incremental_scraped = IncrementalScrapePage(skyvern_frame=skyvern_frame)
|
||||
is_open = False
|
||||
@@ -935,7 +935,7 @@ async def handle_select_option_action(
|
||||
)
|
||||
try:
|
||||
await incremental_scraped.start_listen_dom_increment()
|
||||
timeout = SettingsManager.get_settings().BROWSER_ACTION_TIMEOUT_MS
|
||||
timeout = settings.BROWSER_ACTION_TIMEOUT_MS
|
||||
await skyvern_element.scroll_into_view()
|
||||
|
||||
try:
|
||||
@@ -999,9 +999,9 @@ async def handle_checkbox_action(
|
||||
locator = skyvern_element.locator
|
||||
|
||||
if action.is_checked:
|
||||
await locator.check(timeout=SettingsManager.get_settings().BROWSER_ACTION_TIMEOUT_MS)
|
||||
await locator.check(timeout=settings.BROWSER_ACTION_TIMEOUT_MS)
|
||||
else:
|
||||
await locator.uncheck(timeout=SettingsManager.get_settings().BROWSER_ACTION_TIMEOUT_MS)
|
||||
await locator.uncheck(timeout=settings.BROWSER_ACTION_TIMEOUT_MS)
|
||||
|
||||
# TODO (suchintan): Why does checking the label work, but not the actual input element?
|
||||
return [ActionSuccess()]
|
||||
@@ -1136,7 +1136,7 @@ async def chain_click(
|
||||
page: Page,
|
||||
action: ClickAction | UploadFileAction,
|
||||
skyvern_element: SkyvernElement,
|
||||
timeout: int = SettingsManager.get_settings().BROWSER_ACTION_TIMEOUT_MS,
|
||||
timeout: int = settings.BROWSER_ACTION_TIMEOUT_MS,
|
||||
) -> List[ActionResult]:
|
||||
# Add a defensive page handler here in case a click action opens a file chooser.
|
||||
# This automatically dismisses the dialog
|
||||
@@ -1374,9 +1374,7 @@ async def choose_auto_completion_dropdown(
|
||||
if cnt == 0:
|
||||
continue
|
||||
|
||||
element_handler = await locator.element_handle(
|
||||
timeout=SettingsManager.get_settings().BROWSER_ACTION_TIMEOUT_MS
|
||||
)
|
||||
element_handler = await locator.element_handle(timeout=settings.BROWSER_ACTION_TIMEOUT_MS)
|
||||
if not element_handler:
|
||||
continue
|
||||
|
||||
@@ -1444,7 +1442,7 @@ async def choose_auto_completion_dropdown(
|
||||
if await locator.count() == 0:
|
||||
raise MissingElement(element_id=element_id)
|
||||
|
||||
await locator.click(timeout=SettingsManager.get_settings().BROWSER_ACTION_TIMEOUT_MS)
|
||||
await locator.click(timeout=settings.BROWSER_ACTION_TIMEOUT_MS)
|
||||
clear_input = False
|
||||
return result
|
||||
except Exception as e:
|
||||
@@ -1776,7 +1774,7 @@ async def select_from_dropdown(
|
||||
select_history = [] if select_history is None else select_history
|
||||
single_select_result = CustomSingleSelectResult(skyvern_frame=skyvern_frame)
|
||||
|
||||
timeout = SettingsManager.get_settings().BROWSER_ACTION_TIMEOUT_MS
|
||||
timeout = settings.BROWSER_ACTION_TIMEOUT_MS
|
||||
|
||||
if dropdown_menu_element is None:
|
||||
dropdown_menu_element = await locate_dropdown_menu(
|
||||
@@ -1927,7 +1925,7 @@ async def select_from_dropdown_by_value(
|
||||
step: Step,
|
||||
dropdown_menu_element: SkyvernElement | None = None,
|
||||
) -> ActionResult:
|
||||
timeout = SettingsManager.get_settings().BROWSER_ACTION_TIMEOUT_MS
|
||||
timeout = settings.BROWSER_ACTION_TIMEOUT_MS
|
||||
await incremental_scraped.get_incremental_element_tree(
|
||||
clean_and_remove_element_tree_factory(task=task, step=step, check_exist_funcs=[dom.check_id_in_dom]),
|
||||
)
|
||||
@@ -2061,9 +2059,7 @@ async def locate_dropdown_menu(
|
||||
|
||||
# sometimes taking screenshot might scroll away, need to scroll back after the screenshot
|
||||
x, y = await skyvern_frame.get_scroll_x_y()
|
||||
screenshot = await head_element.get_locator().screenshot(
|
||||
timeout=SettingsManager.get_settings().BROWSER_SCREENSHOT_TIMEOUT_MS
|
||||
)
|
||||
screenshot = await head_element.get_locator().screenshot(timeout=settings.BROWSER_SCREENSHOT_TIMEOUT_MS)
|
||||
await skyvern_frame.scroll_to_x_y(x, y)
|
||||
|
||||
# TODO: better to send untrimmed HTML without skyvern attributes in the future
|
||||
@@ -2139,7 +2135,7 @@ async def scroll_down_to_load_all_options(
|
||||
step_id=step.step_id if step else "none",
|
||||
task_id=task.task_id if task else "none",
|
||||
)
|
||||
timeout = SettingsManager.get_settings().BROWSER_ACTION_TIMEOUT_MS
|
||||
timeout = settings.BROWSER_ACTION_TIMEOUT_MS
|
||||
|
||||
dropdown_menu_element_handle = await scrollable_element.get_locator().element_handle(timeout=timeout)
|
||||
if dropdown_menu_element_handle is None:
|
||||
@@ -2153,12 +2149,10 @@ async def scroll_down_to_load_all_options(
|
||||
scroll_pace = 0
|
||||
previous_num = await incremental_scraped.get_incremental_elements_num()
|
||||
|
||||
deadline = datetime.now(timezone.utc) + timedelta(
|
||||
milliseconds=SettingsManager.get_settings().OPTION_LOADING_TIMEOUT_MS
|
||||
)
|
||||
deadline = datetime.now(timezone.utc) + timedelta(milliseconds=settings.OPTION_LOADING_TIMEOUT_MS)
|
||||
while datetime.now(timezone.utc) < deadline:
|
||||
# make sure we can scroll to the bottom
|
||||
scroll_interval = SettingsManager.get_settings().BROWSER_HEIGHT * 5
|
||||
scroll_interval = settings.BROWSER_HEIGHT * 5
|
||||
if dropdown_menu_element_handle is None:
|
||||
LOG.info("element handle is None, using mouse to scroll down", element_id=scrollable_element.get_id())
|
||||
await page.mouse.wheel(0, scroll_interval)
|
||||
@@ -2250,7 +2244,7 @@ async def normal_select(
|
||||
|
||||
try:
|
||||
await locator.click(
|
||||
timeout=SettingsManager.get_settings().BROWSER_ACTION_TIMEOUT_MS,
|
||||
timeout=settings.BROWSER_ACTION_TIMEOUT_MS,
|
||||
)
|
||||
except Exception as e:
|
||||
LOG.info(
|
||||
@@ -2267,7 +2261,7 @@ async def normal_select(
|
||||
# click by value (if it matches)
|
||||
await locator.select_option(
|
||||
value=value,
|
||||
timeout=SettingsManager.get_settings().BROWSER_ACTION_TIMEOUT_MS,
|
||||
timeout=settings.BROWSER_ACTION_TIMEOUT_MS,
|
||||
)
|
||||
is_success = True
|
||||
action_result.append(ActionSuccess())
|
||||
@@ -2293,7 +2287,7 @@ async def normal_select(
|
||||
# This means the supplied index was for the select element, not a reference to the css dict
|
||||
await locator.select_option(
|
||||
index=index,
|
||||
timeout=SettingsManager.get_settings().BROWSER_ACTION_TIMEOUT_MS,
|
||||
timeout=settings.BROWSER_ACTION_TIMEOUT_MS,
|
||||
)
|
||||
is_success = True
|
||||
action_result.append(ActionSuccess())
|
||||
@@ -2308,7 +2302,7 @@ async def normal_select(
|
||||
|
||||
try:
|
||||
await locator.click(
|
||||
timeout=SettingsManager.get_settings().BROWSER_ACTION_TIMEOUT_MS,
|
||||
timeout=settings.BROWSER_ACTION_TIMEOUT_MS,
|
||||
)
|
||||
except Exception as e:
|
||||
LOG.info(
|
||||
@@ -2464,7 +2458,7 @@ async def poll_verification_code(
|
||||
totp_verification_url: str | None = None,
|
||||
totp_identifier: str | None = None,
|
||||
) -> str | None:
|
||||
timeout = timedelta(minutes=SettingsManager.get_settings().VERIFICATION_CODE_POLLING_TIMEOUT_MINS)
|
||||
timeout = timedelta(minutes=settings.VERIFICATION_CODE_POLLING_TIMEOUT_MINS)
|
||||
start_datetime = datetime.utcnow()
|
||||
timeout_datetime = start_datetime + timeout
|
||||
org_token = await app.DATABASE.get_valid_org_auth_token(organization_id, OrganizationAuthTokenType.api)
|
||||
@@ -2472,7 +2466,7 @@ async def poll_verification_code(
|
||||
LOG.error("Failed to get organization token when trying to get verification code")
|
||||
return None
|
||||
# wait for 40 seconds to let the verification code comes in before polling
|
||||
await asyncio.sleep(SettingsManager.get_settings().VERIFICATION_CODE_INITIAL_WAIT_TIME_SECS)
|
||||
await asyncio.sleep(settings.VERIFICATION_CODE_INITIAL_WAIT_TIME_SECS)
|
||||
while True:
|
||||
# check timeout
|
||||
if datetime.utcnow() > timeout_datetime:
|
||||
|
||||
@@ -4,7 +4,7 @@ from typing import Any
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
from skyvern.forge.sdk.settings_manager import SettingsManager
|
||||
from skyvern.config import settings
|
||||
from skyvern.webeye.actions.actions import Action, DecisiveAction, UserDefinedError
|
||||
from skyvern.webeye.actions.responses import ActionResult
|
||||
from skyvern.webeye.scraper.scraper import ScrapedPage
|
||||
@@ -45,7 +45,7 @@ class DetailedAgentStepOutput(BaseModel):
|
||||
exclude = ["scraped_page", "extract_action_prompt"]
|
||||
|
||||
def __repr__(self) -> str:
|
||||
if SettingsManager.get_settings().DEBUG_MODE:
|
||||
if settings.DEBUG_MODE:
|
||||
return f"DetailedAgentStepOutput({self.model_dump()})"
|
||||
else:
|
||||
return f"AgentStepOutput({self.to_agent_step_output().model_dump()})"
|
||||
|
||||
@@ -26,7 +26,6 @@ from skyvern.exceptions import (
|
||||
from skyvern.forge.sdk.api.files import make_temp_directory
|
||||
from skyvern.forge.sdk.core.skyvern_context import current
|
||||
from skyvern.forge.sdk.schemas.tasks import ProxyLocation
|
||||
from skyvern.forge.sdk.settings_manager import SettingsManager
|
||||
from skyvern.webeye.utils.page import SkyvernFrame
|
||||
|
||||
LOG = structlog.get_logger()
|
||||
@@ -143,12 +142,14 @@ class BrowserContextFactory:
|
||||
|
||||
@staticmethod
|
||||
def build_browser_args() -> dict[str, Any]:
|
||||
video_dir = f"{SettingsManager.get_settings().VIDEO_PATH}/{datetime.utcnow().strftime('%Y-%m-%d')}"
|
||||
har_dir = f"{SettingsManager.get_settings().HAR_PATH}/{datetime.utcnow().strftime('%Y-%m-%d')}/{BrowserContextFactory.get_subdir()}.har"
|
||||
video_dir = f"{settings.VIDEO_PATH}/{datetime.utcnow().strftime('%Y-%m-%d')}"
|
||||
har_dir = (
|
||||
f"{settings.HAR_PATH}/{datetime.utcnow().strftime('%Y-%m-%d')}/{BrowserContextFactory.get_subdir()}.har"
|
||||
)
|
||||
return {
|
||||
"user_data_dir": make_temp_directory(prefix="skyvern_browser_"),
|
||||
"locale": SettingsManager.get_settings().BROWSER_LOCALE,
|
||||
"timezone_id": SettingsManager.get_settings().BROWSER_TIMEZONE,
|
||||
"locale": settings.BROWSER_LOCALE,
|
||||
"timezone_id": settings.BROWSER_TIMEZONE,
|
||||
"color_scheme": "no-preference",
|
||||
"args": [
|
||||
"--disable-blink-features=AutomationControlled",
|
||||
@@ -191,7 +192,7 @@ class BrowserContextFactory:
|
||||
async def create_browser_context(
|
||||
cls, playwright: Playwright, **kwargs: Any
|
||||
) -> tuple[BrowserContext, BrowserArtifacts, BrowserCleanupFunc]:
|
||||
browser_type = SettingsManager.get_settings().BROWSER_TYPE
|
||||
browser_type = settings.BROWSER_TYPE
|
||||
browser_context: BrowserContext | None = None
|
||||
try:
|
||||
creator = cls._creators.get(browser_type)
|
||||
|
||||
@@ -9,10 +9,10 @@ import structlog
|
||||
from playwright.async_api import Frame, Locator, Page
|
||||
from pydantic import BaseModel, PrivateAttr
|
||||
|
||||
from skyvern.config import settings
|
||||
from skyvern.constants import BUILDING_ELEMENT_TREE_TIMEOUT_MS, SKYVERN_DIR, SKYVERN_ID_ATTR
|
||||
from skyvern.exceptions import FailedToTakeScreenshot, UnknownElementTreeFormat
|
||||
from skyvern.forge.sdk.api.crypto import calculate_sha256
|
||||
from skyvern.forge.sdk.settings_manager import SettingsManager
|
||||
from skyvern.webeye.browser_factory import BrowserState
|
||||
from skyvern.webeye.utils.page import SkyvernFrame
|
||||
|
||||
@@ -301,10 +301,10 @@ async def scrape_website(
|
||||
)
|
||||
except Exception as e:
|
||||
# NOTE: MAX_SCRAPING_RETRIES is set to 0 in both staging and production
|
||||
if num_retry > SettingsManager.get_settings().MAX_SCRAPING_RETRIES:
|
||||
if num_retry > settings.MAX_SCRAPING_RETRIES:
|
||||
LOG.error(
|
||||
"Scraping failed after max retries, aborting.",
|
||||
max_retries=SettingsManager.get_settings().MAX_SCRAPING_RETRIES,
|
||||
max_retries=settings.MAX_SCRAPING_RETRIES,
|
||||
url=url,
|
||||
exc_info=True,
|
||||
)
|
||||
|
||||
@@ -9,6 +9,7 @@ from random import uniform
|
||||
import structlog
|
||||
from playwright.async_api import ElementHandle, Frame, FrameLocator, Locator, Page, TimeoutError
|
||||
|
||||
from skyvern.config import settings
|
||||
from skyvern.constants import SKYVERN_ID_ATTR
|
||||
from skyvern.exceptions import (
|
||||
ElementIsNotLabel,
|
||||
@@ -21,7 +22,6 @@ from skyvern.exceptions import (
|
||||
NoneFrameError,
|
||||
SkyvernException,
|
||||
)
|
||||
from skyvern.forge.sdk.settings_manager import SettingsManager
|
||||
from skyvern.webeye.scraper.scraper import IncrementalScrapePage, ScrapedPage, json_to_html, trim_element
|
||||
from skyvern.webeye.utils.page import SkyvernFrame
|
||||
|
||||
@@ -313,9 +313,7 @@ class SkyvernElement:
|
||||
def get_locator(self) -> Locator:
|
||||
return self.locator
|
||||
|
||||
async def get_element_handler(
|
||||
self, timeout: float = SettingsManager.get_settings().BROWSER_ACTION_TIMEOUT_MS
|
||||
) -> ElementHandle:
|
||||
async def get_element_handler(self, timeout: float = settings.BROWSER_ACTION_TIMEOUT_MS) -> ElementHandle:
|
||||
handler = await self.locator.element_handle(timeout=timeout)
|
||||
assert handler is not None
|
||||
return handler
|
||||
@@ -368,7 +366,7 @@ class SkyvernElement:
|
||||
return None
|
||||
|
||||
async def find_label_for(
|
||||
self, dom: DomUtil, timeout: float = SettingsManager.get_settings().BROWSER_ACTION_TIMEOUT_MS
|
||||
self, dom: DomUtil, timeout: float = settings.BROWSER_ACTION_TIMEOUT_MS
|
||||
) -> SkyvernElement | None:
|
||||
if self.get_tag_name() != "label":
|
||||
return None
|
||||
@@ -388,9 +386,7 @@ class SkyvernElement:
|
||||
|
||||
return await dom.get_skyvern_element_by_id(unique_id)
|
||||
|
||||
async def find_bound_label_by_attr_id(
|
||||
self, timeout: float = SettingsManager.get_settings().BROWSER_ACTION_TIMEOUT_MS
|
||||
) -> Locator | None:
|
||||
async def find_bound_label_by_attr_id(self, timeout: float = settings.BROWSER_ACTION_TIMEOUT_MS) -> Locator | None:
|
||||
if self.get_tag_name() == "label":
|
||||
return None
|
||||
|
||||
@@ -406,7 +402,7 @@ class SkyvernElement:
|
||||
return None
|
||||
|
||||
async def find_bound_label_by_direct_parent(
|
||||
self, timeout: float = SettingsManager.get_settings().BROWSER_ACTION_TIMEOUT_MS
|
||||
self, timeout: float = settings.BROWSER_ACTION_TIMEOUT_MS
|
||||
) -> Locator | None:
|
||||
if self.get_tag_name() == "label":
|
||||
return None
|
||||
@@ -490,7 +486,7 @@ class SkyvernElement:
|
||||
self,
|
||||
attr_name: str,
|
||||
dynamic: bool = False,
|
||||
timeout: float = SettingsManager.get_settings().BROWSER_ACTION_TIMEOUT_MS,
|
||||
timeout: float = settings.BROWSER_ACTION_TIMEOUT_MS,
|
||||
) -> typing.Any:
|
||||
if not dynamic:
|
||||
attr = self.get_attributes().get(attr_name)
|
||||
@@ -499,12 +495,10 @@ class SkyvernElement:
|
||||
|
||||
return await self.locator.get_attribute(attr_name, timeout=timeout)
|
||||
|
||||
async def focus(self, timeout: float = SettingsManager.get_settings().BROWSER_ACTION_TIMEOUT_MS) -> None:
|
||||
async def focus(self, timeout: float = settings.BROWSER_ACTION_TIMEOUT_MS) -> None:
|
||||
await self.get_locator().focus(timeout=timeout)
|
||||
|
||||
async def input_sequentially(
|
||||
self, text: str, default_timeout: float = SettingsManager.get_settings().BROWSER_ACTION_TIMEOUT_MS
|
||||
) -> None:
|
||||
async def input_sequentially(self, text: str, default_timeout: float = settings.BROWSER_ACTION_TIMEOUT_MS) -> None:
|
||||
length = len(text)
|
||||
if length > TEXT_PRESS_MAX_LENGTH:
|
||||
# if the text is longer than TEXT_PRESS_MAX_LENGTH characters, we will locator.fill in initial texts until the last TEXT_PRESS_MAX_LENGTH characters
|
||||
@@ -514,22 +508,16 @@ class SkyvernElement:
|
||||
|
||||
await self.press_fill(text, timeout=default_timeout)
|
||||
|
||||
async def press_key(
|
||||
self, key: str, timeout: float = SettingsManager.get_settings().BROWSER_ACTION_TIMEOUT_MS
|
||||
) -> None:
|
||||
async def press_key(self, key: str, timeout: float = settings.BROWSER_ACTION_TIMEOUT_MS) -> None:
|
||||
await self.get_locator().press(key=key, timeout=timeout)
|
||||
|
||||
async def press_fill(
|
||||
self, text: str, timeout: float = SettingsManager.get_settings().BROWSER_ACTION_TIMEOUT_MS
|
||||
) -> None:
|
||||
async def press_fill(self, text: str, timeout: float = settings.BROWSER_ACTION_TIMEOUT_MS) -> None:
|
||||
await self.get_locator().press_sequentially(text, delay=TEXT_INPUT_DELAY, timeout=timeout)
|
||||
|
||||
async def input_fill(
|
||||
self, text: str, timeout: float = SettingsManager.get_settings().BROWSER_ACTION_TIMEOUT_MS
|
||||
) -> None:
|
||||
async def input_fill(self, text: str, timeout: float = settings.BROWSER_ACTION_TIMEOUT_MS) -> None:
|
||||
await self.get_locator().fill(text, timeout=timeout)
|
||||
|
||||
async def input_clear(self, timeout: float = SettingsManager.get_settings().BROWSER_ACTION_TIMEOUT_MS) -> None:
|
||||
async def input_clear(self, timeout: float = settings.BROWSER_ACTION_TIMEOUT_MS) -> None:
|
||||
await self.get_locator().clear(timeout=timeout)
|
||||
|
||||
async def move_mouse_to_safe(
|
||||
@@ -537,7 +525,7 @@ class SkyvernElement:
|
||||
page: Page,
|
||||
task_id: str | None = None,
|
||||
step_id: str | None = None,
|
||||
timeout: float = SettingsManager.get_settings().BROWSER_ACTION_TIMEOUT_MS,
|
||||
timeout: float = settings.BROWSER_ACTION_TIMEOUT_MS,
|
||||
) -> tuple[float, float] | tuple[None, None]:
|
||||
element_id = self.get_id()
|
||||
try:
|
||||
@@ -561,7 +549,7 @@ class SkyvernElement:
|
||||
return None, None
|
||||
|
||||
async def move_mouse_to(
|
||||
self, page: Page, timeout: float = SettingsManager.get_settings().BROWSER_ACTION_TIMEOUT_MS
|
||||
self, page: Page, timeout: float = settings.BROWSER_ACTION_TIMEOUT_MS
|
||||
) -> tuple[float, float]:
|
||||
bounding_box = await self.get_locator().bounding_box(timeout=timeout)
|
||||
if not bounding_box:
|
||||
@@ -580,9 +568,7 @@ class SkyvernElement:
|
||||
skyvern_frame = await SkyvernFrame.create_instance(self.get_frame())
|
||||
await skyvern_frame.click_element_in_javascript(await self.get_element_handler())
|
||||
|
||||
async def coordinate_click(
|
||||
self, page: Page, timeout: float = SettingsManager.get_settings().BROWSER_ACTION_TIMEOUT_MS
|
||||
) -> None:
|
||||
async def coordinate_click(self, page: Page, timeout: float = settings.BROWSER_ACTION_TIMEOUT_MS) -> None:
|
||||
click_x, click_y = await self.move_mouse_to(page=page, timeout=timeout)
|
||||
await page.mouse.click(click_x, click_y)
|
||||
|
||||
@@ -591,7 +577,7 @@ class SkyvernElement:
|
||||
frame=self.get_frame(), expression="(element) => element.blur()", arg=await self.get_element_handler()
|
||||
)
|
||||
|
||||
async def scroll_into_view(self, timeout: float = SettingsManager.get_settings().BROWSER_ACTION_TIMEOUT_MS) -> None:
|
||||
async def scroll_into_view(self, timeout: float = settings.BROWSER_ACTION_TIMEOUT_MS) -> None:
|
||||
element_handler = await self.get_element_handler(timeout=timeout)
|
||||
try:
|
||||
await element_handler.scroll_into_view_if_needed(timeout=timeout)
|
||||
@@ -608,7 +594,7 @@ class SkyvernElement:
|
||||
self,
|
||||
target_locator: Locator,
|
||||
mode: typing.Literal["inner", "outer"],
|
||||
timeout: float = SettingsManager.get_settings().BROWSER_ACTION_TIMEOUT_MS,
|
||||
timeout: float = settings.BROWSER_ACTION_TIMEOUT_MS,
|
||||
) -> float:
|
||||
self_rect = await self.get_locator().bounding_box(timeout=timeout)
|
||||
if self_rect is None:
|
||||
|
||||
@@ -8,9 +8,9 @@ import structlog
|
||||
from playwright._impl._errors import TimeoutError
|
||||
from playwright.async_api import ElementHandle, Frame, Page
|
||||
|
||||
from skyvern.config import settings
|
||||
from skyvern.constants import BUILDING_ELEMENT_TREE_TIMEOUT_MS, PAGE_CONTENT_TIMEOUT, SKYVERN_DIR
|
||||
from skyvern.exceptions import FailedToTakeScreenshot
|
||||
from skyvern.forge.sdk.settings_manager import SettingsManager
|
||||
|
||||
LOG = structlog.get_logger()
|
||||
|
||||
@@ -37,7 +37,7 @@ class SkyvernFrame:
|
||||
frame: Page | Frame,
|
||||
expression: str,
|
||||
arg: Any | None = None,
|
||||
timeout_ms: float = SettingsManager.get_settings().BROWSER_ACTION_TIMEOUT_MS,
|
||||
timeout_ms: float = settings.BROWSER_ACTION_TIMEOUT_MS,
|
||||
) -> Any:
|
||||
try:
|
||||
async with asyncio.timeout(timeout_ms / 1000):
|
||||
@@ -51,12 +51,12 @@ class SkyvernFrame:
|
||||
page: Page,
|
||||
full_page: bool = False,
|
||||
file_path: str | None = None,
|
||||
timeout: float = SettingsManager.get_settings().BROWSER_LOADING_TIMEOUT_MS,
|
||||
timeout: float = settings.BROWSER_LOADING_TIMEOUT_MS,
|
||||
) -> bytes:
|
||||
if page.is_closed():
|
||||
raise FailedToTakeScreenshot(error_message="Page is closed")
|
||||
try:
|
||||
await page.wait_for_load_state(timeout=SettingsManager.get_settings().BROWSER_LOADING_TIMEOUT_MS)
|
||||
await page.wait_for_load_state(timeout=settings.BROWSER_LOADING_TIMEOUT_MS)
|
||||
LOG.debug("Page is fully loaded, agent is about to take screenshots")
|
||||
start_time = time.time()
|
||||
screenshot: bytes = bytes()
|
||||
@@ -92,7 +92,7 @@ class SkyvernFrame:
|
||||
page: Page,
|
||||
url: str,
|
||||
draw_boxes: bool = False,
|
||||
max_number: int = SettingsManager.get_settings().MAX_NUM_SCREENSHOTS,
|
||||
max_number: int = settings.MAX_NUM_SCREENSHOTS,
|
||||
) -> List[bytes]:
|
||||
skyvern_page = await SkyvernFrame.create_instance(frame=page)
|
||||
assert isinstance(skyvern_page.frame, Page)
|
||||
|
||||
Reference in New Issue
Block a user