JavaScript SDK API Reference

This page provides detailed documentation for all methods available in the kogiQA JavaScript SDK.

Browser Class

Browser.start

Starts a new browser session.

const browser = await Browser.start("your_token", "firefox", "Test Login Flow");

Parameters:

  • accessToken: Your API access token.
  • browserType: One of 'chrome' | 'firefox' | 'edge' | 'safari'| 'local'. Defaults to "chrome".
  • sessionName: Optional name for the session.
  • sessionId: Optional custom session ID.
  • backendURL: Optional custom backend URL.

Navigates to a given URL.

await browser.navigate("https://www.atagon.com");

Local Development Tip: If you navigate to a server running on your local machine while using a cloud session, we automatically open a tunnel for the port specified in the URL. If you need additional ports (for example, for a backend API), you can use exposePorts() to make them accessible.

click

Clicks on an element by its description.

await browser.click("Save", "top-left");

Positions:

Supports multiple formats including:

  • "top left", "center", "bottom right"
  • "oben links", "unten mitte" (German)
  • "arriba izquierda", "abajo centro" (Spanish)
  • "haut gauche", "bas centre" (French)

type

Types text into an input field based on your description.

await browser.type("Name", "Max McMan", "topLeft");

sleep

Pauses execution for a number of seconds.

await browser.sleep(5); // Sleeps for 5 seconds

clickAtPosition

Click at a fixed coordinate on the page. (Only use this if necessary; click() is preferred as it handles page layout changes more gracefully.)

await browser.clickAtPosition({x: 100, y: 200});

drawOnCanvas

Draws a path on a canvas.

await browser.drawOnCanvas([
{x: 100, y: 100},
{x: 200, y: 200}
]);

pressKey

Triggers a keyboard shortcut.

await browser.pressKey("ctrl+s");
await browser.pressKey("alt+space", {repeat: 3});

scroll

Scrolls the page by the specified number of pixels.

await browser.scroll(100, -400);

resize

Resizes an element to a specific size.

await browser.resize("column", {x: 200, y: 200}, "center");

hover

Triggers a hover event at a position.

await browser.hover({x: 120, y: 120});

hasText

Checks if the page contains a specific text.

await browser.hasText("Welcome back!");

hasInput

Checks if the page contains an input with the specified label.

await browser.hasInput("Email");

hasButton

Checks if the page contains a button with the specified label.

await browser.hasButton("Submit");

clearSession

Clears all session data like cookies and local storage.

await browser.clearSession();

autoLogin

Automatically fills and submits a login form.

await browser.autoLogin("user@example.com", "password123");

checkStructure

Saves the current page structure and compares it later.

await browser.checkStructure("loginPage");

selectText

Selects specific text in an input.

await browser.selectText("Username", "max", "topLeft");

uploadFile

Uploads a file using a file input.

await browser.uploadFile("Upload", "/path/to/file.txt", "center");

dragStart

Starts dragging an element.

await browser.dragStart("Task 1");

dragEnd

Ends dragging element by dropping it.

await browser.dragEnd("State Done");

dragHover

Drags over a target element.

await browser.dragHover("Drop Zone");

getPageText

Returns all visible text on the page.

const text = await browser.getPageText();
console.log(text);

dragFromTo

Drags one element onto another.

await browser.dragFromTo("Drag Me", "Drop Here");

evaluate

Evaluates a function in the browser context.

const title = await browser.evaluate(() => document.title);
console.log(title);

createEmailAddress

Creates a new email address. If no inbox name is specified, a random address will be generated.

const email = await browser.createEmailAddress("Max.huber");

fetchEmails

Returns all emails received by the specified inbox.

const emails = await browser.fetchEmails("Max.huber");

clearEmails

Deletes all emails in the specified inbox.

await browser.clearEmails("Max.huber");

Email usage example

const adresse = await browser.createEmailAddress("myInbox");
// use the adresse.emailAddress to receive an email.
const result = await browser.fetchEmails(adresse.inboxName);
console.log(result.emails)
await browser.clearEmails("myInbox");

textContent

Returns all text on the current page.

let allTexts = await browser.textContent();

url

Returns the URL of the current page.

let currentURL = await browser.url()

screenshot

Returns a screenshot of the current page.

let result = await browser.screenshot();
console.log(result.data)

close

Closes the browser session.

await browser.close();

Advanced Methods

runStep

Executes a custom step defined by you.

await browser.runStep({
type: "customAction",
data: {foo: "bar"}
});

exposePorts

Exposes local ports to make them accessible during cloud test runs.

await browser.exposePorts([3000, 8080, 443]);

setTimeout

Sets a custom timeout for the session.

await browser.setTimeout(5*60); // in seconds