Browser

The Browser class in Ordino AI provides a suite of browser-level automation capabilities. It allows seamless interaction with browser windows, navigation, alerts, cookies, and more.

Usage : browser

🧩 Code

The Browser class is designed to interact with the browser

To insert a code block with syntax highlighting:

import { oi } from "@ordino.ai/spartify-engine";

oi.ui.browser().navigateToUrl('https://ordino.ai');

navigateToUrl(url: string): void

Navigates to the specified URL.

  • @param url – The URL to navigate to.

  • @returns void

oi.ui.browser().navigateToUrl('https://ordino.ai');

refreshPage(): void

Refreshes the current page.

  • @returns void

oi.ui.browser().refreshPage('https://ordino.ai');

goBack(): void

Navigates back to the previous page.

  • @returns void

oi.ui.browser().goBack();

goForward(): void

Navigates forward to the next page.

  • @returns void

oi.ui.browser().goForward();

getCurrentUrl(): Chainable<String>

Retrieves the current URL

  • @returns object<promise>

oi.ui.browser().getCurrentUrl().then((url) => {
  console.log('Current URL:', url);
});

getPageTitle(): Chainable<String>

Retrieves the title of the current page.

  • @returns object<promise>

oi.ui.browser().getPageTitle().then((title) => {
  console.log('Page Title:', title);
});

assertUrl(expectedUrl: <String>): void

Asserts that the current URL matches the specified URL.

  • @param url – The URL to navigate to.

  • @returns void

oi.ui.browser().assertUrl('https://ordino.ai');

assertPageTitle(expectedTitle: <String>): void

Asserts that the current page title matches the specified title.

  • @param title – The title to assert

  • @returns void

oi.ui.browser().assertPageTitle('Ordino - Home');

Browser Session & Storage

clearBrowserCache: void

Clears the browser cache.

  • @returns void

oi.ui.browser().clearBrowserCache();

clearBrowserCookies: void

Clears the browser cookies.

  • @returns void

oi.ui.browser().clearBrowserCookies();

setBrowserCookie(name: string, value: string): void

Sets a browser cookie with the specified name and value.

  • @param name – The name of the cookie.

  • @param value – The value of the cookie.

  • @returns void

oi.ui.browser().setBrowserCookie('sessionId', '12345');

getBrowserCookies(): Chainable<Cookie[]>

Retrieves all browser cookies.

  • @returns object<promise>

oi.ui.browser().getBrowserCookies().then((cookies) => {
  console.log('Cookies:', cookies);
});

Window & Frame Actions

setWindowSize(width: number, height: number): void

Sets the size of the browser window.

  • @param width – The width of the window.

  • @param height – The height of the window.

  • @returns void

oi.ui.browser().setWindowSize(1280, 720);

switchToWindow(windowName: string): void

Switches to the specified window.

  • @returns void

oi.ui.browser().switchToWindow('newWindow');

switchToFrame(frameName: any): void

Retrieves all browser cookies.

  • @param frame-name - The name or index of the frame to switch to.

  • @returns void

ui.browser().switchToFrame('iframe-id');

closeCurrentWindow(): void

Closes the current window.

  • @returns void

ui.browser().closeCurrentWindow();

openNewTab(url: string): void

Opens a new tab with the specified URL.

  • @param url - The url to open in the new tab.

  • @returns void

ui.browser().openNewTab('https://ordino.ai');

assertBrowserIsOpen(): void

Asserts that the browser is open.

  • @returns void

ui.browser().oi.ui.browser.assertBrowserIsOpen();

Screenshots & Alerts

takeScreenshot(fileName: string): void

Takes a screenshot and saves it with the specified file name.

  • @param file-name - The name of the file to save the screenshot as

  • @returns void

ui.browser().takeScreenshot('homepage');

takeFullPageScreenshot(fileName: string): void

Takes a full-page screenshot and saves it with the specified file name.

  • @param frame-name - The name of the file to save the full-page screenshot as.

  • @returns void

ui.browser().takeFullPageScreenshot('full-homepage');

handleAlert(alertText: string, action: string): void

Handles an alert with the specified text and action.

  • @param alert-text - the text of the alert.

  • @param action - The action to take on the alert (e.g., accept, dismiss).

  • @returns void

ui.browser().handleAlert('Confirm Delete?', 'accept');

Network Handling

waitForNetworkIdle(): void

Waits for the network to be idle.

  • @param frame-name - The name or index of the frame to switch to.

  • @returns void

ui.browser().waitForNetworkIdle();

Last updated