Browser
The Browser class provides a set of browser-level actions for enhanced, generalized automation. These methods enable seamless interaction with browser windows, navigation, alerts, cookies, and more. This module is part of Spartify.IO’s automation framework, ensuring efficient and scalable test execution.
Class : Browser
The Browser class is designed to interact with the browser
import { SpartiUI } from "@spartify.io/spartify-engine";
SpartiUI.browser().navigateToUrl('https://spartify.io');
Methods & Usage
Navigation Methods
navigateToUrl(url: string): void
Navigates to the specified URL.
@param url - the url to navigate to.
@return void
SpartiUI.browser.navigateToUrl('https://spartify.io');
refreshPage(): void
Refreshes the current page.
@return void
SpartiUI.browser.refreshPage('https://spartify.io');
goBack(): void
Navigates back to the previous page.
@return void
SpartiUI.browser.goBack();
goForward(): void
Navigates forward to the next page.
@return void
SpartiUI.browser.goForward();
getCurrentUrl(): Chainable<String>
Retrieves the current URL
@return Object<Promise>
SpartiUI.browser.getCurrentUrl().then((url) => { console.log('Current URL:', url);});
getPageTitle(): Chainable<String>
Retrieves the title of the current page.
@return Object<Promise>
SpartiUI.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 assert
@return void.
SpartiUI.browser.assertUrl('https://spartify.io');
assertPageTitle(expectedTitle: <String>): void
Asserts that the current page title matches the specified title.
@param title - the title to assert. @return void
SpartiUI.browser.assertPageTitle('Spartify - Home');
Browser Session & Storage
clearBrowserCache: void
Clears the browser cache.
@return void
SpartiUI.browser.clearBrowserCache();
clearBrowserCookies: void
Clears the browser cookies.
@return void
SpartiUI.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.
@return void
SpartiUI.browser.setBrowserCookie('sessionId', '12345');
getBrowserCookies(): Chainable<Cookie[]>
Retrieves all browser cookies..
@returns object<promise>
SpartiUI.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.
@return void
SpartiUI.browser.setWindowSize(1280, 720);
switchToWindow(windowName: string): void
Switches to the specified window.
@return void
SpartiUI.browser.switchToWindow('newWindow');
switchToFrame(frameName: any): void
Switches to the specified frame.
@param frameName - the name or index of the frame to switch to.
@return void
SpartiUI.browser.switchToFrame('iframe-id');
closeCurrentWindow(): void
Closes the current window.
@return void
SpartiUI.browser.closeCurrentWindow();
openNewTab(url: string): void
Opens a new tab with the specified URL.
@param url - the url to open in the new tab.
@return void
SpartiUI.browser.openNewTab('https://spartify.io');
assertBrowserIsOpen(): void
Asserts that the browser is open.
@return void
SpartiUI.browser.assertBrowserIsOpen();
Screenshots & Alerts
takeScreenshot(fileName: string): void
Takes a screenshot and saves it with the specified file name.
@param fileName - the name of the file to save the screenshot as
@return void
SpartiUI.browser.takeScreenshot('homepage');
takeFullPageScreenshot(fileName: string): void
Takes a full-page screenshot and saves it with the specified file name.
@param fileName - the name of the file to save the full-page screenshot as.
@return void
SpartiUI.browser.takeFullPageScreenshot('full-homepage');
handleAlert(alertText: string, action: string): void
Handles an alert with the specified text and action.
@param alertText - the text of the alert.
@param action - the action to take on the alert (e.g., accept, dismiss).
@return void
SpartiUI.browser.handleAlert('Confirm Delete?', 'accept');
Network Handling
waitForNetworkIdle(): void
Waits for the network to be idle.
@return void
SpartiUI.browser.waitForNetworkIdle();