Understand Taiko's implicit assertions
masterError and the test will fail.repository·master·Indexed 25 days ago
https://github.com/getgauge/taikoTaiko is a Node.js library for browser automation optimized for testing modern web applications. It features a human-readable API with smart selectors to minimize complex CSS/XPath, an interactive REPL for real-time browser control, and network interception capabilities for stubbing and mocking requests. It supports Chromium and experimental Firefox support, and integrates with the Gauge testing framework.
Error and the test will fail.The examples folder demonstrates several common automation tasks using Taiko against 'The Internet Express' application:
01-file_upload.js02-file_download.js03-work-with-frames.js04-windows-tabs.js05-dropdown.js06-basic-auth.js07-dynamic-loading.js08-contenteditable.jsTaiko supports various community-developed plugins to extend its functionality, including accessibility testing, Android device support, performance diagnostics, screencasting, storage interaction, and automated screenshots.
Available community plugins include:
taiko-accessibility: Test site accessibility.taiko-android: Run web tests on Android devices and emulators.taiko-diagnostics: Measure speedindex and performance metrics.taiko-screencast: Record a GIF video of a Taiko script run.taiko-storage: Interact with browser storages.taiko-screeny: Capture a screenshot on every action.taiko-video: Save screencasts as compressed MP4 videos.Taiko supports the following browsers:
Note: Safari is NOT supported. Taiko is designed for web applications using chromium/chrome based browsers. For Android Chrome testing, use the taiko-android plugin.
If you want to attempt an action without failing the test when the implicit assertion fails (e.g., when an element is not visible), wrap the action in a JavaScript try...catch block.
const { openBrowser, goto, click, closeBrowser } = require('taiko');
(async () => {
await openBrowser();
await goto("google.com");
try {
await click("Google Search");
} catch(e) {
// Ignore or log the error.
} finally {
closeBrowser();
}
})();To use Taiko within the Gauge testing framework, install the Gauge CLI and initialize a JavaScript project.
$ npm install @getgauge/cli
$ gauge init jsTo improve load times when running tests in parallel (e.g., in the cloud), use the following Chromium command line arguments with openBrowser.
await openBrowser({args: [
'--disable-gpu',
'--disable-dev-shm-usage',
'--disable-setuid-sandbox',
'--no-first-run',
'--no-sandbox',
'--no-zygote']});Taiko uses smart selectors to mimic user behavior, reducing the need for brittle CSS or XPath selectors.
click("Button Text") clicks an element containing that text.write("text") writes into the currently focused element.write("text", into(textBox({placeholder: "Username"}))) targets a specific field.click(checkBox(near("Username"))) clicks the checkbox nearest to the element with text "Username".$("#id")) and XPath ($("//xpath")).To enable debug logs for Taiko, run your script with the DEBUG environment variable set to taiko:*.
env DEBUG="taiko:*" taiko code.jsThe Taiko REPL includes built-in commands to discover available APIs and their usage:
.api: Lists all available API categories (e.g., Browser actions, Page actions)..api <api_name>: Provides detailed information for a specific API, including a description, parameters, return values, and an example usage.> .api
> .api clickYou can load plugins using the following methods:
--plugins option.taiko code.js --plugin 'android'TAIKO_PLUGINS to load plugins when using other runners.package.json dependencies by calling their init method.You can modify how the examples are executed using CLI flags passed to npm test:
--observe to run the examples in a headed browser so you can visually monitor the actions.05) to run only that specific test file.--screencast to run all examples and record the session using the taiko-screencast plugin. Recordings are saved in the captures directory.