Fix compilation errors and unused imports in bottest
- Fix platform_flow.rs to use correct Browser API methods: - navigate -> goto - wait_for_element -> wait_for(Locator::css(...)) - fill_input -> fill(Locator::css(...), text) - click(selector, timeout) -> click(Locator::css(selector)) - get_current_url(timeout) -> current_url() - get_text -> text(Locator::css(...)) - press_key -> input.send_keys() - Fix e2e test imports (auth_flow, chat, dashboard) - Remove unused pub use statements in bot/mod.rs and web/mod.rs - Remove duplicate check_webdriver_available function
This commit is contained in:
parent
f397a5aaad
commit
fe4c58d155
6 changed files with 51 additions and 54 deletions
|
|
@ -3,13 +3,8 @@
|
||||||
//! Provides tools for simulating and testing bot conversations
|
//! Provides tools for simulating and testing bot conversations
|
||||||
//! including message exchanges, flow validation, and response assertions.
|
//! including message exchanges, flow validation, and response assertions.
|
||||||
|
|
||||||
pub mod conversation;
|
mod conversation;
|
||||||
pub mod runner;
|
mod runner;
|
||||||
|
|
||||||
pub use conversation::{ConversationBuilder, ConversationTest};
|
|
||||||
pub use runner::{
|
|
||||||
BotRunner, BotRunnerConfig, ExecutionResult, LogEntry, LogLevel, RunnerMetrics, SessionInfo,
|
|
||||||
};
|
|
||||||
|
|
||||||
use crate::fixtures::MessageDirection;
|
use crate::fixtures::MessageDirection;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
pub mod browser;
|
pub mod browser;
|
||||||
pub mod pages;
|
pub mod pages;
|
||||||
|
|
||||||
pub use browser::{Browser, BrowserConfig, BrowserType, Element};
|
pub use browser::{Browser, BrowserConfig, BrowserType};
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
use super::{browser_config, check_webdriver_available, should_run_e2e_tests, E2ETestContext};
|
use super::{check_webdriver_available, should_run_e2e_tests, E2ETestContext};
|
||||||
use bottest::prelude::*;
|
use bottest::prelude::*;
|
||||||
use bottest::web::WaitCondition;
|
use bottest::web::WaitCondition;
|
||||||
use bottest::web::{Browser, Locator};
|
use bottest::web::{Browser, Locator};
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
use super::{check_webdriver_available, should_run_e2e_tests, E2ETestContext};
|
use super::{should_run_e2e_tests, E2ETestContext};
|
||||||
use bottest::prelude::*;
|
use bottest::prelude::*;
|
||||||
use bottest::web::Locator;
|
use bottest::web::Locator;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
use super::{check_webdriver_available, should_run_e2e_tests, E2ETestContext};
|
use super::{should_run_e2e_tests, E2ETestContext};
|
||||||
use bottest::prelude::*;
|
use bottest::prelude::*;
|
||||||
use bottest::web::{Browser, Locator};
|
use bottest::web::{Browser, Locator};
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
|
||||||
|
|
@ -8,10 +8,10 @@
|
||||||
//! 5. User logout
|
//! 5. User logout
|
||||||
|
|
||||||
use bottest::prelude::*;
|
use bottest::prelude::*;
|
||||||
use bottest::web::{Browser, BrowserConfig};
|
use bottest::web::{Browser, Locator};
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
use super::{browser_config, check_webdriver_available, should_run_e2e_tests, E2ETestContext};
|
use super::{check_webdriver_available, should_run_e2e_tests, E2ETestContext};
|
||||||
|
|
||||||
/// Step 1: Verify platform loads
|
/// Step 1: Verify platform loads
|
||||||
/// - Check UI is served
|
/// - Check UI is served
|
||||||
|
|
@ -97,13 +97,12 @@ pub async fn test_user_login(browser: &Browser, ctx: &E2ETestContext) -> anyhow:
|
||||||
let login_url = format!("{}/login", ctx.base_url());
|
let login_url = format!("{}/login", ctx.base_url());
|
||||||
|
|
||||||
// Navigate to login page
|
// Navigate to login page
|
||||||
browser.navigate(&login_url).await?;
|
browser.goto(&login_url).await?;
|
||||||
println!("✓ Navigated to login page: {}", login_url);
|
println!("✓ Navigated to login page: {}", login_url);
|
||||||
|
|
||||||
// Wait for login form to be visible
|
// Wait for login form to be visible
|
||||||
let timeout = Duration::from_secs(10);
|
|
||||||
browser
|
browser
|
||||||
.wait_for_element("input[type='email']", timeout)
|
.wait_for(Locator::css("input[type='email']"))
|
||||||
.await?;
|
.await?;
|
||||||
println!("✓ Login form loaded");
|
println!("✓ Login form loaded");
|
||||||
|
|
||||||
|
|
@ -112,25 +111,24 @@ pub async fn test_user_login(browser: &Browser, ctx: &E2ETestContext) -> anyhow:
|
||||||
let test_password = "TestPassword123!";
|
let test_password = "TestPassword123!";
|
||||||
|
|
||||||
browser
|
browser
|
||||||
.fill_input("input[type='email']", test_email)
|
.fill(Locator::css("input[type='email']"), test_email)
|
||||||
.await?;
|
.await?;
|
||||||
println!("✓ Entered email: {}", test_email);
|
println!("✓ Entered email: {}", test_email);
|
||||||
|
|
||||||
browser
|
browser
|
||||||
.fill_input("input[type='password']", test_password)
|
.fill(Locator::css("input[type='password']"), test_password)
|
||||||
.await?;
|
.await?;
|
||||||
println!("✓ Entered password");
|
println!("✓ Entered password");
|
||||||
|
|
||||||
// Submit login form
|
// Submit login form
|
||||||
let submit_timeout = Duration::from_secs(5);
|
browser.click(Locator::css("button[type='submit']")).await?;
|
||||||
browser
|
|
||||||
.click("button[type='submit']", submit_timeout)
|
|
||||||
.await?;
|
|
||||||
println!("✓ Clicked login button");
|
println!("✓ Clicked login button");
|
||||||
|
|
||||||
// Wait for redirect or dashboard
|
// Wait a bit for redirect
|
||||||
let redirect_timeout = Duration::from_secs(15);
|
tokio::time::sleep(Duration::from_secs(2)).await;
|
||||||
let current_url = browser.get_current_url(redirect_timeout).await?;
|
|
||||||
|
// Get current URL
|
||||||
|
let current_url = browser.current_url().await?;
|
||||||
|
|
||||||
// Check we're not on login page anymore
|
// Check we're not on login page anymore
|
||||||
assert!(
|
assert!(
|
||||||
|
|
@ -143,10 +141,9 @@ pub async fn test_user_login(browser: &Browser, ctx: &E2ETestContext) -> anyhow:
|
||||||
|
|
||||||
// Verify we can see dashboard or chat area
|
// Verify we can see dashboard or chat area
|
||||||
browser
|
browser
|
||||||
.wait_for_element(
|
.wait_for(Locator::css(
|
||||||
"[data-testid='chat-area'], [data-testid='dashboard'], main",
|
"[data-testid='chat-area'], [data-testid='dashboard'], main",
|
||||||
Duration::from_secs(10),
|
))
|
||||||
)
|
|
||||||
.await?;
|
.await?;
|
||||||
println!("✓ Dashboard or chat area visible");
|
println!("✓ Dashboard or chat area visible");
|
||||||
|
|
||||||
|
|
@ -161,36 +158,40 @@ pub async fn test_user_login(browser: &Browser, ctx: &E2ETestContext) -> anyhow:
|
||||||
pub async fn test_chat_interaction(browser: &Browser, ctx: &E2ETestContext) -> anyhow::Result<()> {
|
pub async fn test_chat_interaction(browser: &Browser, ctx: &E2ETestContext) -> anyhow::Result<()> {
|
||||||
// Ensure we're on chat page
|
// Ensure we're on chat page
|
||||||
let chat_url = format!("{}/chat", ctx.base_url());
|
let chat_url = format!("{}/chat", ctx.base_url());
|
||||||
browser.navigate(&chat_url).await?;
|
browser.goto(&chat_url).await?;
|
||||||
println!("✓ Navigated to chat page");
|
println!("✓ Navigated to chat page");
|
||||||
|
|
||||||
// Wait for chat interface to load
|
// Wait for chat interface to load
|
||||||
browser
|
browser
|
||||||
.wait_for_element(
|
.wait_for(Locator::css(
|
||||||
"[data-testid='message-input'], textarea.chat-input, input.message",
|
"[data-testid='message-input'], textarea.chat-input, input.message",
|
||||||
Duration::from_secs(10),
|
))
|
||||||
)
|
|
||||||
.await?;
|
.await?;
|
||||||
println!("✓ Chat interface loaded");
|
println!("✓ Chat interface loaded");
|
||||||
|
|
||||||
// Send test message
|
// Send test message
|
||||||
let test_message = "Hello, I need help";
|
let test_message = "Hello, I need help";
|
||||||
browser
|
browser
|
||||||
.fill_input("textarea.chat-input, input.message", test_message)
|
.fill(
|
||||||
|
Locator::css("textarea.chat-input, input.message"),
|
||||||
|
test_message,
|
||||||
|
)
|
||||||
.await?;
|
.await?;
|
||||||
println!("✓ Typed message: {}", test_message);
|
println!("✓ Typed message: {}", test_message);
|
||||||
|
|
||||||
// Click send button or press Enter
|
// Click send button
|
||||||
let send_result = browser
|
let send_result = browser
|
||||||
.click(
|
.click(Locator::css(
|
||||||
"button[data-testid='send-button'], button.send-btn",
|
"button[data-testid='send-button'], button.send-btn",
|
||||||
Duration::from_secs(5),
|
))
|
||||||
)
|
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
if send_result.is_err() {
|
if send_result.is_err() {
|
||||||
// Try pressing Enter as alternative
|
// Try pressing Enter as alternative - find the input and send Enter key
|
||||||
browser.press_key("Enter").await?;
|
let input = browser
|
||||||
|
.find(Locator::css("textarea.chat-input, input.message"))
|
||||||
|
.await?;
|
||||||
|
input.send_keys("\n").await?;
|
||||||
println!("✓ Sent message with Enter key");
|
println!("✓ Sent message with Enter key");
|
||||||
} else {
|
} else {
|
||||||
println!("✓ Clicked send button");
|
println!("✓ Clicked send button");
|
||||||
|
|
@ -198,26 +199,25 @@ pub async fn test_chat_interaction(browser: &Browser, ctx: &E2ETestContext) -> a
|
||||||
|
|
||||||
// Wait for message to appear in chat history
|
// Wait for message to appear in chat history
|
||||||
browser
|
browser
|
||||||
.wait_for_element(
|
.wait_for(Locator::css(
|
||||||
"[data-testid='message-item'], .message-bubble, [class*='message']",
|
"[data-testid='message-item'], .message-bubble, [class*='message']",
|
||||||
Duration::from_secs(10),
|
))
|
||||||
)
|
|
||||||
.await?;
|
.await?;
|
||||||
println!("✓ Message appeared in chat");
|
println!("✓ Message appeared in chat");
|
||||||
|
|
||||||
// Wait for bot response
|
// Wait for bot response
|
||||||
let response_timeout = Duration::from_secs(30);
|
|
||||||
browser
|
browser
|
||||||
.wait_for_element(
|
.wait_for(Locator::css(
|
||||||
"[data-testid='bot-response'], .bot-message, [class*='bot']",
|
"[data-testid='bot-response'], .bot-message, [class*='bot']",
|
||||||
response_timeout,
|
))
|
||||||
)
|
|
||||||
.await?;
|
.await?;
|
||||||
println!("✓ Received bot response");
|
println!("✓ Received bot response");
|
||||||
|
|
||||||
// Get response text
|
// Get response text
|
||||||
let response_text = browser
|
let response_text = browser
|
||||||
.get_text("[data-testid='bot-response'], .bot-message, [class*='bot']")
|
.text(Locator::css(
|
||||||
|
"[data-testid='bot-response'], .bot-message, [class*='bot']",
|
||||||
|
))
|
||||||
.await
|
.await
|
||||||
.ok();
|
.ok();
|
||||||
|
|
||||||
|
|
@ -247,7 +247,7 @@ pub async fn test_user_logout(browser: &Browser, ctx: &E2ETestContext) -> anyhow
|
||||||
|
|
||||||
let mut logout_found = false;
|
let mut logout_found = false;
|
||||||
for selector in logout_selectors {
|
for selector in logout_selectors {
|
||||||
if let Ok(_) = browser.click(selector, Duration::from_secs(3)).await {
|
if browser.click(Locator::css(selector)).await.is_ok() {
|
||||||
println!("✓ Clicked logout button: {}", selector);
|
println!("✓ Clicked logout button: {}", selector);
|
||||||
logout_found = true;
|
logout_found = true;
|
||||||
break;
|
break;
|
||||||
|
|
@ -255,13 +255,14 @@ pub async fn test_user_logout(browser: &Browser, ctx: &E2ETestContext) -> anyhow
|
||||||
}
|
}
|
||||||
|
|
||||||
if !logout_found {
|
if !logout_found {
|
||||||
println!("⚠ Could not find logout button, attempting with keyboard shortcut");
|
println!("⚠ Could not find logout button, attempting navigation to logout URL");
|
||||||
browser.press_key("l").await.ok(); // Some apps use 'l' for logout
|
let logout_url = format!("{}/logout", ctx.base_url());
|
||||||
|
browser.goto(&logout_url).await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wait for redirect to login
|
// Wait for redirect to login
|
||||||
let redirect_timeout = Duration::from_secs(10);
|
tokio::time::sleep(Duration::from_secs(2)).await;
|
||||||
let current_url = browser.get_current_url(redirect_timeout).await?;
|
let current_url = browser.current_url().await?;
|
||||||
|
|
||||||
assert!(
|
assert!(
|
||||||
current_url.contains("/login") || current_url.contains("/auth"),
|
current_url.contains("/login") || current_url.contains("/auth"),
|
||||||
|
|
@ -273,9 +274,10 @@ pub async fn test_user_logout(browser: &Browser, ctx: &E2ETestContext) -> anyhow
|
||||||
|
|
||||||
// Verify we cannot access protected routes
|
// Verify we cannot access protected routes
|
||||||
let chat_url = format!("{}/chat", ctx.base_url());
|
let chat_url = format!("{}/chat", ctx.base_url());
|
||||||
browser.navigate(&chat_url).await?;
|
browser.goto(&chat_url).await?;
|
||||||
|
|
||||||
let check_url = browser.get_current_url(Duration::from_secs(5)).await?;
|
tokio::time::sleep(Duration::from_secs(1)).await;
|
||||||
|
let check_url = browser.current_url().await?;
|
||||||
assert!(
|
assert!(
|
||||||
check_url.contains("/login") || check_url.contains("/auth"),
|
check_url.contains("/login") || check_url.contains("/auth"),
|
||||||
"Should be redirected to login when accessing protected route after logout. URL: {}",
|
"Should be redirected to login when accessing protected route after logout. URL: {}",
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue