Skip to content

Instantly share code, notes, and snippets.

@bukowa
Last active July 7, 2024 02:25
Show Gist options
  • Save bukowa/e9623517b7e73f2494369af98185a13f to your computer and use it in GitHub Desktop.
Save bukowa/e9623517b7e73f2494369af98185a13f to your computer and use it in GitHub Desktop.
CLRF
<!DOCTYPE html>
<html class="default" lang="en">
<head>
<meta charset="utf-8"/>
<meta http-equiv="x-ua-compatible" content="IE=edge"/>
<title>3. Selenium API | @tauri-e2e/selenium</title>
<meta name="description" content="Documentation for @tauri-e2e/selenium"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<link rel="stylesheet" href="../assets/style.css"/>
<link rel="stylesheet" href="../assets/highlight.css"/>
<script defer src="../assets/main.js"></script>
<script async src="../assets/icons.js" id="tsd-icons-script"></script>
<script async src="../assets/search.js" id="tsd-search-script"></script>
<script async src="../assets/navigation.js" id="tsd-nav-script"></script>
</head>
<body>
<script>document.documentElement.dataset.theme = localStorage.getItem("tsd-theme") || "os";
document.body.style.display = "none";
setTimeout(() => app ? app.showPage() : document.body.style.removeProperty("display"), 500)</script>
<header class="tsd-page-toolbar">
<div class="tsd-toolbar-contents container">
<div class="table-cell" id="tsd-search" data-base="..">
<div class="field"><label for="tsd-search-field" class="tsd-widget tsd-toolbar-icon search no-caption">
<svg width="16" height="16" viewBox="0 0 16 16" fill="none">
<use href="../assets/icons.svg#icon-search"></use>
</svg>
</label><input type="text" id="tsd-search-field" aria-label="Search"/></div>
<div class="field">
<div id="tsd-toolbar-links"></div>
</div>
<ul class="results">
<li class="state loading">Preparing search index...</li>
<li class="state failure">The search index is not available</li>
</ul>
<a href="../index.html" class="title">@tauri-e2e/selenium</a></div>
<div class="table-cell" id="tsd-widgets"><a href="#" class="tsd-widget tsd-toolbar-icon menu no-caption"
data-toggle="menu" aria-label="Menu">
<svg width="16" height="16" viewBox="0 0 16 16" fill="none">
<use href="../assets/icons.svg#icon-menu"></use>
</svg>
</a></div>
</div>
</header>
<div class="container container-main">
<div class="col-content">
<div class="tsd-page-title">
<ul class="tsd-breadcrumb">
<li><a href="../index.html">@tauri-e2e/selenium</a></li>
<li><a href="3__Selenium_API.html">3. Selenium API</a></li>
</ul>
</div>
<div class="tsd-panel tsd-typography"><pre><code class="javascript"><span class="hl-4">import</span><span
class="hl-1"> {</span><span class="hl-5">Builder</span><span class="hl-1">} </span><span class="hl-4">from</span><span
class="hl-1"> </span><span class="hl-2">&quot;selenium-webdriver&quot;</span><span class="hl-1">;</span><br/><span
class="hl-4">import</span><span class="hl-1"> </span><span class="hl-3">*</span><span
class="hl-1"> </span><span class="hl-4">as</span><span class="hl-1"> </span><span
class="hl-5">e2e</span><span class="hl-1"> </span><span class="hl-4">from</span><span
class="hl-1"> </span><span class="hl-2">&quot;@tauri-e2e/selenium&quot;</span><br/><br/><span
class="hl-6">// Using native selenium-webdriver API:</span><br/><br/><span
class="hl-6">// Windows</span><br/><span class="hl-3">let</span><span class="hl-1"> </span><span
class="hl-5">opts</span><span class="hl-1"> = </span><span class="hl-3">new</span><span
class="hl-1"> </span><span class="hl-5">e2e</span><span class="hl-1">.</span><span
class="hl-5">webview2</span><span class="hl-1">.</span><span class="hl-0">Options</span><span
class="hl-1">()</span><br/><span class="hl-5">opts</span><span class="hl-1">.</span><span class="hl-0">setBinaryPath</span><span
class="hl-1">(</span><span class="hl-2">&quot;/path/to/tauri-app.exe&quot;</span><span
class="hl-1">)</span><br/><span class="hl-3">let</span><span class="hl-1"> </span><span class="hl-5">driver</span><span
class="hl-1"> = </span><span class="hl-3">new</span><span class="hl-1"> </span><span class="hl-0">Builder</span><span
class="hl-1">()</span><br/><span class="hl-1"> .</span><span
class="hl-0">withCapabilities</span><span class="hl-1">(</span><span class="hl-5">opts</span><span
class="hl-1">)</span><br/><br/><span class="hl-6">// Linux</span><br/><span class="hl-3">let</span><span
class="hl-1"> </span><span class="hl-5">opts</span><span class="hl-1"> = </span><span
class="hl-3">new</span><span class="hl-1"> </span><span class="hl-5">e2e</span><span
class="hl-1">.</span><span class="hl-5">webkitgtk2</span><span class="hl-1">.</span><span class="hl-0">Options</span><span
class="hl-1">()</span><br/><span class="hl-5">opts</span><span class="hl-1">.</span><span class="hl-0">setBinaryPath</span><span
class="hl-1">(</span><span class="hl-2">&quot;/path/to/tauri-app&quot;</span><span class="hl-1">)</span><br/><span
class="hl-3">let</span><span class="hl-1"> </span><span class="hl-5">driver</span><span
class="hl-1"> = </span><span class="hl-3">new</span><span class="hl-1"> </span><span class="hl-0">Builder</span><span
class="hl-1">()</span><br/><span class="hl-1"> .</span><span
class="hl-0">withCapabilities</span><span class="hl-1">(</span><span class="hl-5">opts</span><span
class="hl-1">)</span>
</code><button type="button">Copy</button></pre>
</div>
</div>
<div class="col-sidebar">
<div class="page-menu">
<div class="tsd-navigation settings">
<details class="tsd-accordion">
<summary class="tsd-accordion-summary">
<h3>
<svg width="20" height="20" viewBox="0 0 24 24" fill="none">
<use href="../assets/icons.svg#icon-chevronDown"></use>
</svg>
Settings
</h3>
</summary>
<div class="tsd-accordion-details">
<div class="tsd-filter-visibility"><span class="settings-label">Member Visibility</span>
<ul id="tsd-filter-options">
<li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox"
id="tsd-filter-protected"
name="protected"/>
<svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true">
<rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6"
fill="none"></rect>
<path class="tsd-checkbox-checkmark"
d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none"
stroke-width="3.5" stroke-linejoin="round" fill="none"></path>
</svg>
<span>Protected</span></label></li>
<li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox"
id="tsd-filter-inherited"
name="inherited"
checked/>
<svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true">
<rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6"
fill="none"></rect>
<path class="tsd-checkbox-checkmark"
d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none"
stroke-width="3.5" stroke-linejoin="round" fill="none"></path>
</svg>
<span>Inherited</span></label></li>
<li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox"
id="tsd-filter-external"
name="external"/>
<svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true">
<rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6"
fill="none"></rect>
<path class="tsd-checkbox-checkmark"
d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none"
stroke-width="3.5" stroke-linejoin="round" fill="none"></path>
</svg>
<span>External</span></label></li>
</ul>
</div>
<div class="tsd-theme-toggle"><label class="settings-label" for="tsd-theme">Theme</label><select
id="tsd-theme">
<option value="os">OS</option>
<option value="light">Light</option>
<option value="dark">Dark</option>
</select></div>
</div>
</details>
</div>
</div>
<div class="site-menu">
<nav class="tsd-navigation"><a href="../index.html">
<svg class="tsd-kind-icon" viewBox="0 0 24 24">
<use href="../assets/icons.svg#icon-1"></use>
</svg>
<span>@tauri-e2e/selenium</span></a>
<ul class="tsd-small-nested-navigation" id="tsd-nav-container" data-base="..">
<li>Loading...</li>
</ul>
</nav>
</div>
</div>
</div>
<footer><p class="tsd-generator">Generated using <a href="https://typedoc.org/" target="_blank">TypeDoc</a></p></footer>
<div class="overlay"></div>
</body>
</html>
<!DOCTYPE html>
<html class="default" lang="en">
<head>
<meta charset="utf-8"/>
<meta http-equiv="x-ua-compatible" content="IE=edge"/>
<title>quick-start | @tauri-e2e/selenium</title>
<meta name="description" content="Documentation for @tauri-e2e/selenium"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<link rel="stylesheet" href="../assets/style.css"/>
<link rel="stylesheet" href="../assets/highlight.css"/>
<script defer src="../assets/main.js"></script>
<script async src="../assets/icons.js" id="tsd-icons-script"></script>
<script async src="../assets/search.js" id="tsd-search-script"></script>
<script async src="../assets/navigation.js" id="tsd-nav-script"></script>
</head>
<body>
<script>document.documentElement.dataset.theme = localStorage.getItem("tsd-theme") || "os";
document.body.style.display = "none";
setTimeout(() => app ? app.showPage() : document.body.style.removeProperty("display"), 500)</script>
<header class="tsd-page-toolbar">
<div class="tsd-toolbar-contents container">
<div class="table-cell" id="tsd-search" data-base="..">
<div class="field"><label for="tsd-search-field" class="tsd-widget tsd-toolbar-icon search no-caption">
<svg width="16" height="16" viewBox="0 0 16 16" fill="none">
<use href="../assets/icons.svg#icon-search"></use>
</svg>
</label><input type="text" id="tsd-search-field" aria-label="Search"/></div>
<div class="field">
<div id="tsd-toolbar-links"></div>
</div>
<ul class="results">
<li class="state loading">Preparing search index...</li>
<li class="state failure">The search index is not available</li>
</ul>
<a href="../index.html" class="title">@tauri-e2e/selenium</a></div>
<div class="table-cell" id="tsd-widgets"><a href="#" class="tsd-widget tsd-toolbar-icon menu no-caption"
data-toggle="menu" aria-label="Menu">
<svg width="16" height="16" viewBox="0 0 16 16" fill="none">
<use href="../assets/icons.svg#icon-menu"></use>
</svg>
</a></div>
</div>
</header>
<div class="container container-main">
<div class="col-content">
<div class="tsd-page-title">
<ul class="tsd-breadcrumb">
<li><a href="../index.html">@tauri-e2e/selenium</a></li>
<li><a href="quick_start.html">quick-start</a></li>
</ul>
</div>
<div class="tsd-panel tsd-typography">
<hr>
<a id="md:title-2-quickstart-guidegroup-documentscategory-readme" class="tsd-anchor"></a>
<h2 class="tsd-anchor-link">title: 2. Quickstart Guide
group: Documents
category: README<a href="#md:title-2-quickstart-guidegroup-documentscategory-readme"
aria-label="Permalink" class="tsd-anchor-icon">
<svg viewBox="0 0 24 24">
<use href="../assets/icons.svg#icon-anchor"></use>
</svg>
</a></h2>
<pre><code class="javascript"><span class="hl-4">import</span><span class="hl-1"> {</span><span
class="hl-5">launch</span><span class="hl-1">} </span><span class="hl-4">from</span><span
class="hl-1"> </span><span class="hl-2">&quot;@tauri-e2e/selenium&quot;</span><span
class="hl-1">;</span><br/><span class="hl-4">import</span><span class="hl-1"> </span><span
class="hl-5">assert</span><span class="hl-1"> </span><span class="hl-4">from</span><span
class="hl-1"> </span><span class="hl-2">&quot;node:assert&quot;</span><span
class="hl-1">;</span><br/><span class="hl-4">import</span><span class="hl-1"> {</span><span
class="hl-5">until</span><span class="hl-1">} </span><span class="hl-4">from</span><span
class="hl-1"> </span><span class="hl-2">&quot;selenium-webdriver&quot;</span><span
class="hl-1">;</span><br/><span class="hl-4">import</span><span class="hl-1"> </span><span
class="hl-3">*</span><span class="hl-1"> </span><span class="hl-4">as</span><span
class="hl-1"> </span><span class="hl-5">e2e</span><span class="hl-1"> </span><span
class="hl-4">from</span><span class="hl-1"> </span><span class="hl-2">&quot;@tauri-e2e/selenium&quot;</span><br/><br/><span
class="hl-6">// This setup simplifies managing `WebDriver` binary locations and platform-specific details.</span><br/><span
class="hl-6">// The following `optional` environment variables can be set to quickly get started.</span><br/><span
class="hl-6">// Under the hood all modules recognize them and adjust their behavior accordingly.</span><br/><span
class="hl-6">// Note!: This is optional and opinionated, you can manage the WebDriver process yourself.</span><br/><br/><span
class="hl-6">// Path to the Tauri app binary.</span><br/><span class="hl-6">// (if .exe is detected it will be stripped on non-Windows platforms)</span><br/><span
class="hl-5">process</span><span class="hl-1">.</span><span class="hl-5">env</span><span
class="hl-1">.</span><span class="hl-7">TAURI_SELENIUM_BINARY</span><span
class="hl-1"> = </span><span
class="hl-2">&#39;../../../target/release/tauri-app.exe&#39;</span><span
class="hl-1">;</span><br/><br/><span class="hl-6">// Path to the WebDriver binary (optional as it will be looked up in the system&#39;s PATH).</span><br/><span
class="hl-6">// In this example we use `install` module to install the WebDriver binary based on the platform.</span><br/><span
class="hl-6">// On `Windows` we will automatically download the WebDriver binary while utilizing cache.</span><br/><span
class="hl-6">// On `Linux` if the WebDriver binary is not found in the PATH, we will throw an error as</span><br/><span
class="hl-6">// WebDriver has to be installed using native package manager like `apt-get` or `yum`.</span><br/><span
class="hl-6">// Note: For running Windows tests inside GitHub Actions see:</span><br/><span
class="hl-6">// https://github.com/actions/runner-images/issues/9538</span><br/><span class="hl-5">process</span><span
class="hl-1">.</span><span class="hl-5">env</span><span class="hl-1">.</span><span class="hl-7">TAURI_WEBDRIVER_BINARY</span><span
class="hl-1"> = </span><span class="hl-4">await</span><span class="hl-1"> </span><span class="hl-5">e2e</span><span
class="hl-1">.</span><span class="hl-5">install</span><span class="hl-1">.</span><span class="hl-0">PlatformDriver</span><span
class="hl-1">();</span><br/><br/><span
class="hl-6">// Define URL of the remote Selenium server.</span><br/><span class="hl-6">// That&#39;s how we connect these two modules together:</span><br/><span
class="hl-6">// - If spawning WebDriver using `launch.SpawnWebDriver` module - host and port</span><br/><span
class="hl-6">// arguments passed to the WebDriver binary will be extracted from this URL.</span><br/><span
class="hl-6">// - If using `Builder` then host and port will be passed</span><br/><span
class="hl-6">// to `usingServer` method of `selenium-webdriver`. This aligns with the</span><br/><span
class="hl-6">// `selenium-webdriver` API and allows to use custom remote servers.</span><br/><span
class="hl-5">process</span><span class="hl-1">.</span><span class="hl-5">env</span><span
class="hl-1">.</span><span class="hl-7">SELENIUM_REMOTE_URL</span><span class="hl-1"> = </span><span
class="hl-2">&#39;http://127.0.0.1:4674&#39;</span><span class="hl-1">;</span><br/><br/><span
class="hl-6">// Loge level for WebDriver process.</span><br/><span class="hl-5">process</span><span
class="hl-1">.</span><span class="hl-5">env</span><span class="hl-1">.</span><span class="hl-7">TAURI_WEBDRIVER_LOGLEVEL</span><span
class="hl-1"> = </span><span class="hl-2">&#39;debug&#39;</span><span
class="hl-1">;</span><br/><br/><span
class="hl-6">// Setup optional logging in case of failures.</span><br/><span class="hl-5">e2e</span><span
class="hl-1">.</span><span class="hl-0">setLogger</span><span class="hl-1">(</span><span
class="hl-5">console</span><span class="hl-1">);</span><br/><br/><span class="hl-6">// Launch WebDriver process.</span><br/><span
class="hl-6">// Handles cleanup on process exit under the hood (SIGINT, SIGTERM, etc).</span><br/><span
class="hl-6">// Because each WebDriver has its own way of spawning and managing the process,</span><br/><span
class="hl-6">// we abstract this complexity into a single module while trying to keep the API simple.</span><br/><span
class="hl-3">let</span><span class="hl-1"> </span><span class="hl-5">webdriver</span><span
class="hl-1"> = </span><span class="hl-4">await</span><span class="hl-1"> </span><span class="hl-5">e2e</span><span
class="hl-1">.</span><span class="hl-5">launch</span><span class="hl-1">.</span><span class="hl-0">spawnWebDriver</span><span
class="hl-1">({</span><span class="hl-5">setupExitHandlers:</span><span class="hl-1"> </span><span
class="hl-3">true</span><span class="hl-1">})</span><br/><br/><span class="hl-6">// Create a new WebDriver session.</span><br/><span
class="hl-3">let</span><span class="hl-1"> </span><span class="hl-5">driver</span><span
class="hl-1"> = </span><span class="hl-3">new</span><span class="hl-1"> </span><span class="hl-5">e2e</span><span
class="hl-1">.</span><span class="hl-5">selenium</span><span class="hl-1">.</span><span
class="hl-0">Builder</span><span class="hl-1">().</span><span class="hl-0">build</span><span
class="hl-1">();</span><br/><br/><span
class="hl-6">// Wait until the body is loaded.</span><br/><span class="hl-4">await</span><span
class="hl-1"> </span><span class="hl-5">driver</span><span class="hl-1">.</span><span class="hl-0">wait</span><span
class="hl-1">(</span><span class="hl-5">until</span><span class="hl-1">.</span><span class="hl-0">elementLocated</span><span
class="hl-1">({</span><span class="hl-5">css:</span><span class="hl-1"> </span><span class="hl-2">&#39;body&#39;</span><span
class="hl-1">}));</span><br/><br/><span class="hl-6">// Get the title.</span><br/><span
class="hl-3">let</span><span class="hl-1"> </span><span class="hl-5">title</span><span class="hl-1"> = </span><span
class="hl-4">await</span><span class="hl-1"> </span><span class="hl-5">driver</span><span
class="hl-1">.</span><span class="hl-0">getTitle</span><span class="hl-1">();</span><br/><span
class="hl-5">assert</span><span class="hl-1">.</span><span class="hl-0">equal</span><span
class="hl-1">(</span><span class="hl-5">title</span><span class="hl-1">, </span><span class="hl-2">&#39;Tauri App&#39;</span><span
class="hl-1">);</span><br/><br/><span
class="hl-6">// Properly cleanup WebDriver session.</span><br/><span class="hl-6">// This will close the Tauri window and the WebDriver session.</span><br/><span
class="hl-6">// Note: on Linux need this PR to be merged:</span><br/><span class="hl-6">// - https://github.com/tauri-apps/wry/pull/1311/files</span><br/><span
class="hl-4">await</span><span class="hl-1"> </span><span class="hl-5">e2e</span><span class="hl-1">.</span><span
class="hl-5">selenium</span><span class="hl-1">.</span><span class="hl-0">cleanupSession</span><span
class="hl-1">(</span><span class="hl-5">driver</span><span class="hl-1">);</span><br/><br/><span
class="hl-6">// Close underlying WebDriver process.</span><br/><span class="hl-6">// Otherwise, we will hang indefinitely.</span><br/><span
class="hl-6">// Note: When using node runner you can pass `--test-force-exit` flag.</span><br/><span
class="hl-5">e2e</span><span class="hl-1">.</span><span class="hl-5">launch</span><span
class="hl-1">.</span><span class="hl-0">killWebDriver</span><span class="hl-1">(</span><span
class="hl-5">webdriver</span><span class="hl-1">)</span>
</code><button type="button">Copy</button></pre>
</div>
</div>
<div class="col-sidebar">
<div class="page-menu">
<div class="tsd-navigation settings">
<details class="tsd-accordion">
<summary class="tsd-accordion-summary">
<h3>
<svg width="20" height="20" viewBox="0 0 24 24" fill="none">
<use href="../assets/icons.svg#icon-chevronDown"></use>
</svg>
Settings
</h3>
</summary>
<div class="tsd-accordion-details">
<div class="tsd-filter-visibility"><span class="settings-label">Member Visibility</span>
<ul id="tsd-filter-options">
<li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox"
id="tsd-filter-protected"
name="protected"/>
<svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true">
<rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6"
fill="none"></rect>
<path class="tsd-checkbox-checkmark"
d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none"
stroke-width="3.5" stroke-linejoin="round" fill="none"></path>
</svg>
<span>Protected</span></label></li>
<li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox"
id="tsd-filter-inherited"
name="inherited"
checked/>
<svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true">
<rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6"
fill="none"></rect>
<path class="tsd-checkbox-checkmark"
d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none"
stroke-width="3.5" stroke-linejoin="round" fill="none"></path>
</svg>
<span>Inherited</span></label></li>
<li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox"
id="tsd-filter-external"
name="external"/>
<svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true">
<rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6"
fill="none"></rect>
<path class="tsd-checkbox-checkmark"
d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none"
stroke-width="3.5" stroke-linejoin="round" fill="none"></path>
</svg>
<span>External</span></label></li>
</ul>
</div>
<div class="tsd-theme-toggle"><label class="settings-label" for="tsd-theme">Theme</label><select
id="tsd-theme">
<option value="os">OS</option>
<option value="light">Light</option>
<option value="dark">Dark</option>
</select></div>
</div>
</details>
</div>
<details open class="tsd-accordion tsd-page-navigation">
<summary class="tsd-accordion-summary">
<h3>
<svg width="20" height="20" viewBox="0 0 24 24" fill="none">
<use href="../assets/icons.svg#icon-chevronDown"></use>
</svg>
On This Page
</h3>
</summary>
<div class="tsd-accordion-details"><a href="#md:title-2-quickstart-guidegroup-documentscategory-readme"><span>title: 2. <wbr/>Quickstart <wbr/>Guidegroup: <wbr/>Documentscategory: README</span></a>
</div>
</details>
</div>
<div class="site-menu">
<nav class="tsd-navigation"><a href="../index.html">
<svg class="tsd-kind-icon" viewBox="0 0 24 24">
<use href="../assets/icons.svg#icon-1"></use>
</svg>
<span>@tauri-e2e/selenium</span></a>
<ul class="tsd-small-nested-navigation" id="tsd-nav-container" data-base="..">
<li>Loading...</li>
</ul>
</nav>
</div>
</div>
</div>
<footer><p class="tsd-generator">Generated using <a href="https://typedoc.org/" target="_blank">TypeDoc</a></p></footer>
<div class="overlay"></div>
</body>
</html>
title group category
2. Quickstart Guide
Documents
README
title group category
3. Selenium API
Documents
README
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment