Replies: 2 comments 2 replies
-
Tauri supports the webdriver interface on Windows and Linux through tauri-driver. Edit: If you're looking for rust-only tests, there is this selenium style client thirtyfour that looks interesting. |
Beta Was this translation helpful? Give feedback.
2 replies
-
Here is the configuration for testing in thirtyfour in linux/ubuntu: use crate::config::constants::WEBDRIVER_URL;
use serde_json::{json, Map, Value};
use std::collections::HashMap;
use std::process::{Command, Stdio};
use std::time::Duration;
use thirtyfour::prelude::*;
pub async fn initialize_driver() -> WebDriver {
let mut caps: Map<String, Value> = Map::new();
// Required for tauri-driver to know your app binary
// Build with:
// cargo tauri build
caps.insert(
"tauri:options".to_string(),
json!({
"application": "/home/amiya/Documents/workspace/shivarthu/working_directory/shiv/shivarthu-app/target/x86_64-unknown-linux-gnu/release/shivarthu-app"
}),
);
// Set browserName to "wry" as per tauri-driver expectations
caps.insert("browserName".to_string(), json!("wry"));
let driver = WebDriver::new(WEBDRIVER_URL, caps).await.unwrap();
driver
}
pub fn remove_port() {
let status = Command::new("fuser")
.arg("-n")
.arg("tcp")
.arg("-k")
.arg("4444")
.status();
match status {
Ok(exit_status) => {
if exit_status.success() {
println!("fuser command executed successfully");
} else {
eprintln!("fuser command failed: {:?}", exit_status);
}
}
Err(e) => {
eprintln!("Failed to execute fuser command: {}", e);
}
}
}
pub async fn run_webdriver() {
let geckodriver_path = "tauri-driver/tauri-driver";
let status = Command::new(geckodriver_path)
.arg("--port")
.arg("4444")
.stdout(Stdio::null())
.stderr(Stdio::null())
.spawn();
// Check if the command was executed successfully
match status {
Ok(_) => {
// Give some time for geckodriver to initialize
tokio::time::sleep(Duration::from_secs(2)).await;
println!("geckodriver started successfully on port 4444");
}
Err(e) => {
eprintln!("Failed to execute geckodriver: {}", e);
}
}
} pub const WEBDRIVER_URL: &str = "http://localhost:4444"; use shivarthu_client_test::polkadotjs::polkadotjs_test::PolkadotjsStruct;
use shivarthu_client_test::webdriver_run::webdriver_function::{
initialize_driver, remove_port, run_webdriver,
};
use thirtyfour::prelude::*;
#[tokio::main]
async fn main() -> WebDriverResult<()> {
remove_port();
run_webdriver().await;
let driver = initialize_driver().await;
let polkadotjs = PolkadotjsStruct::new(driver.clone()).await?;
polkadotjs.got_page().await?;
driver.quit().await.unwrap();
remove_port();
Ok(())
} use thirtyfour::prelude::*;
// Define a struct to hold the WebDriver instance.
pub struct PolkadotjsStruct {
driver: WebDriver,
}
impl PolkadotjsStruct {
// Implement methods for the WebDriver struct.
pub async fn new(driver: WebDriver) -> Result<Self, WebDriverError> {
// Initialize WebDriverSession here.
// You need to provide the appropriate WebDriver URL (e.g., "http://localhost:4444/wd/hub").
Ok(PolkadotjsStruct { driver })
}
pub async fn got_page(&self) -> WebDriverResult<()> {
// Wait for UI to load
tokio::time::sleep(std::time::Duration::from_secs(3)).await;
// Example: Check a button exists
//
let elem = self.driver.find(By::Css("button")).await?;
elem.click().await?;
Ok(())
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I've been having a blast using Tauri for my new project, Atomic-Server, but I'm having a bit of a problem: I want to run end-to-end tests, but I have no idea how. Since my app is also a web app, I use playwright to end-to-end test most GUI parts of the code, but taht still leaves at least some parts of functionality untested in the tauri sections, like:
I have no idea as to how I could automatically test things like this. In my dream scenario, I'd have a tool similar to playwright, where I could programatically trigger and access desktop GUI elements. Also ideally, I could run this as part of
cargo test
.Some projects that might be interesting:
I'm mostly wondering: what are you using? What works? Is there a different approach to end-to-end testing / desktop GUI automation?
Beta Was this translation helpful? Give feedback.
All reactions