chippers / hello_tauri

Absolutely minimal example for a linux Tauri application.
Apache License 2.0
15 stars 5 forks source link

Windows 11 support suggestions #1

Open richardeschloss opened 1 year ago

richardeschloss commented 1 year ago

Hi,

I appreciate your efforts in putting this repo together. I tried to run the webdriverio example on Windows 11 and could not get it running out of the box, but I think I got close to getting something working.

  1. I had to create an "icons/icon.ico" file
  2. I had to supply "--native-driver", "msedgedriver.exe" as arguments to tauri-driver.
  3. When that tauri-driver runs, it defaults to port 4445 (so I had to update the port in the wdio config to that)
  4. After finally building the tauri app successfully, the webdriver launches a blank Microsoft Edge window, and while the window says "Microsoft Edge is being controlled by automation software" it never seems to load the actual Tauri app.

What might I be missing? Here's my updated config:

exports.config = {
  port: 4444, <-- needed
  specs: ["./test/specs/**/*.js"],
  maxInstances: 1,
  capabilities: [
    {
      maxInstances: 1,
      "tauri:options": {
        application: "../../target/release/hello_tauri.exe", <-- the ".exe" needed for windows
      },
    },
  ],
  reporters: ["spec"],
  framework: "mocha",
  mochaOpts: {
    ui: "bdd",
    timeout: 60000,
  },

  // ensure the rust project is built since we expect this binary to exist for the webdriver sessions
  onPrepare: () => spawnSync("cargo", ["build", "--release"]),

  // ensure we are running `tauri-driver` before the session starts so that we can proxy the webdriver requests
  beforeSession: () =>
    (tauriDriver = spawn(
      path.resolve(os.homedir(), ".cargo", "bin", "tauri-driver"),
      // ['--native-driver', './msedgedriver.exe'], // <-- Key issue: would start just a blank MSedge window, not the app. Tauri driver was only respecting the PATH env var, not the CLI option. 
      { stdio: [null, process.stdout, process.stderr] }
    )),

  // clean up the `tauri-driver` process we spawned at the start of the session
  afterSession: () => tauriDriver.kill(),
};

I know it sounds trivial, but the CLI help says I can use the "--native-driver" param but only the ENV var was working completely.

justintaylor-dev commented 1 year ago

Had similar issues, finally got it working on Windows 11 via the Selenium approach.

I also converted my setup to TypeScript. For Reference:

test/test.ts

import os from "os";
import path from "path";
import { expect } from "chai";
import { spawn, spawnSync } from "child_process";
import { Builder, By, Capabilities } from "selenium-webdriver";

import type { WebDriver } from "selenium-webdriver";
import type { ChildProcessByStdio } from "child_process";

let port = 4454;
let nativePort = port + 1;
const isRelease = false;

// create the path to the expected application binary
const application = path.resolve(
  __dirname,
  "..",
  "..",
  "..",
  "target",
  isRelease ? "release" : "debug",
  "hello_tauri.exe"
);

console.log(application);

// keep track of the webdriver instance we create
let driver: WebDriver;

// keep track of the tauri-driver process we start
let tauriDriver: ChildProcessByStdio<any, null, null>;

before(async function () {
  // set timeout to 2 minutes to allow the program to build if it needs to
  this.timeout(120000);

  // ensure the program has been built
  spawnSync("cargo", ["build", isRelease ? "--release" : "--debug"]);

  // start tauri-driver
  tauriDriver = spawn(
    path.resolve(os.homedir(), ".cargo", "bin", "tauri-driver"),
    [
      "--port",
      port.toString(),
      "--native-driver",
      "C:/path/to/msedgedriver.exe",
      "--native-port",
      nativePort.toString(),
    ],
    { stdio: [null, process.stdout, process.stderr] }
  );

  const capabilities = new Capabilities();
  capabilities.set("tauri:options", { application });
  capabilities.setBrowserName("wry");

  // start the webdriver client
  driver = await new Builder()
    .withCapabilities(capabilities)
    .usingServer(`http://localhost:${port.toString()}/`)
    .build();
});

after(async function () {
  // stop the webdriver session
  await driver!.quit();

  // kill the tauri-driver process
  tauriDriver!.kill();
});

describe("Hello Tauri", () => {
  it("should be cordial", async () => {
    const text = await driver!.findElement(By.css("body > h1")).getText();
    expect(text).to.match(/^[hH]ello/);
  });

  it("should be excited", async () => {
    const text = await driver!.findElement(By.css("body > h1")).getText();
    expect(text).to.match(/!$/);
  });
});

And ran with ts-mocha

ts-mocha -p ./tsconfig.json test/*.ts

package.json

{
  "name": "selenium",
  "version": "1.0.0",
  "license": "Apache-2.0",
  "private": true,
  "scripts": {
    "test": "mocha",
    "test-ts": "ts-mocha -p ./tsconfig.json test/*.ts",
    "format": "prettier --write \"./**/*.js\""
  },
  "dependencies": {
    "@types/chai": "^4.3.5",
    "@types/selenium-webdriver": "^4.1.15",
    "chai": "^4.3.7",
    "mocha": "^10.2.0",
    "selenium-webdriver": "^4.9.2",
    "ts-mocha": "^10.0.0",
    "ts-node": "^10.9.1",
    "typescript": "^5.1.3"
  }
}
bukowa commented 6 days ago

cannot parse capability: ms:edgeOptions

Thanks for the port, now seems like this is also required: webviewOptions because of cannot parse capability: ms:edgeOptions.

capabilities.set('tauri:options', {
    application: application,
    webviewOptions: {},
})