tauri-apps / tauri

Build smaller, faster, and more secure desktop applications with a web frontend.
https://tauri.app
Apache License 2.0
78.1k stars 2.31k forks source link

Cannot create raw webdriver session with tauri-driver #9653

Closed charleslowell-valstro closed 1 week ago

charleslowell-valstro commented 2 weeks ago

Describe the bug

I'm trying to just use raw webdriver (not selenium, and not @wdio) using tauri-driver on Windows, using the demonstration app at https://github.com/chippers/hello_tauri

However, whenever I try to create a session, it fails with the following error:

Error: Failed to create session.
unknown error: no msedge binary at ..\..\target\release\hello_tauri.exe
    at startWebDriverSession (file:///C:/Users/charleslowell/hello_tauri/webdriver/valstro/node_modules/webdriver/build/utils.js:69:15)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async WebDriver.newSession (file:///C:/Users/charleslowell/hello_tauri/webdriver/valstro/node_modules/webdriver/build/index.js:20:45)

Reproduction

  1. Check out and build https://github.com/chippers/hello_tauri
PS > cargo build --release
  1. Manually run tauri-driver:
    
    PS > .\.cargo\bin\tauri-driver.exe --port 4445 --native-port 4444
    Starting Microsoft Edge WebDriver 124.0.2478.67 (d385ef2844e0afdd93039326e4121de317ea611b) on port 4444
    To submit feedback, report a bug, or suggest new features, please visit https://github.com/MicrosoftEdge/EdgeWebDriver

Only local connections are allowed. Please see https://aka.ms/WebDriverSecurity for suggestions on keeping Microsoft Edge WebDriver safe.

Microsoft Edge WebDriver was started successfully.


3. Run the following snippet of javascript that just tries to create a webdriver session:

```ts
import path from "node:path";
import { statSync } from "node:fs";
import WebDriver from "webdriver";

const appexe = path.join('..','..','target', 'release', 'hello_tauri.exe');

console.log(`application:`, statSync(appexe));

await WebDriver.newSession({
  port: 4445,
  hostname: 'localhost',

  capabilities: {
    //@ts-expect-error this is an non-standard extension
    'tauri:options': {
      application: appexe,
      webviewOptions: {},
    },
    browserName: 'wry',
  }
});

Expected behavior

I'd expect a webdriver session to be created.

Full tauri info output

PS C:\Users\charleslowell\hello_tauri> cargo tauri info
error: no such command: `tauri`

        Did you mean `miri`?

        View all installed commands with `cargo --list`
        Find a package to install `tauri` with `cargo search cargo-tauri`

Stack trace

Error: Failed to create session.
unknown error: no msedge binary at ..\..\target\release\hello_tauri.exe
    at startWebDriverSession (file:///C:/Users/charleslowell/hello_tauri/webdriver/valstro/node_modules/webdriver/build/utils.js:69:15)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async WebDriver.newSession (file:///C:/Users/charleslowell/hello_tauri/webdriver/valstro/node_modules/webdriver/build/index.js:20:45)

Additional context

No response

chippers commented 1 week ago

It looks like you have msedgedriver in your PATH based on your second command (and as always probably check if it's the right version).

unknown error: no msedge binary means that the binary field that msedgedriver expects to run was not able to be found. That binary field is taken from tauri:options > application, so whatever is set there is what it looks for. That example repository has the WebDriver examples 2 sub-directories deep from the root of the repo which is where target gets built. Likely, the parent directories are not aligned with wherever you have your WebDriver JavaScript snippet at when you assign const appexe.

Sidenote: if you want to run cargo tauri commands then you need to install the subcommand first with cargo install tauri-cli.

charleslowell-valstro commented 1 week ago

@chippers Thanks! It was totally the path. I was not running the tauri-driver in the same directory as I was running the node script. That got me working on the hello_tauri app, and so I'm going to close this issue.

However, one thing I noticed is that when I apply it to my own app, I'm running into trouble because it is a multi window app, and there does not appear to be away to interact with multiple windows from webdriver. Is there any trails to follow around using tauri-driver with multi-window apps?