complete milestone 1
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
#include <filesystem>
|
||||
#include <thread>
|
||||
#include <chrono>
|
||||
#include <optional>
|
||||
|
||||
using namespace mosis::test;
|
||||
|
||||
@@ -104,26 +105,88 @@ bool ClickByClassIndex(TestContext& ctx, const std::string& className, int index
|
||||
return false;
|
||||
}
|
||||
|
||||
// Helper: Wait for hierarchy to update to expected screen
|
||||
bool WaitForScreen(TestContext& ctx, const std::string& expectedScreen, int timeoutMs = 3000) {
|
||||
auto startTime = std::chrono::steady_clock::now();
|
||||
while (true) {
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
ctx.hierarchy.Reload();
|
||||
std::string currentScreen = ctx.hierarchy.GetScreenName();
|
||||
if (currentScreen.find(expectedScreen) != std::string::npos) {
|
||||
return true;
|
||||
}
|
||||
auto elapsed = std::chrono::steady_clock::now() - startTime;
|
||||
if (std::chrono::duration_cast<std::chrono::milliseconds>(elapsed).count() >= timeoutMs) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Helper: Find a back button in the hierarchy
|
||||
std::optional<ElementInfo> FindBackButton(TestContext& ctx) {
|
||||
// Try to find back button by class (app-bar-nav is used in most screens)
|
||||
auto elements = ctx.hierarchy.FindByClass("app-bar-nav");
|
||||
for (const auto& elem : elements) {
|
||||
if (elem.visible && elem.bounds.width > 0 && elem.bounds.height > 0) {
|
||||
return elem;
|
||||
}
|
||||
}
|
||||
|
||||
// Try browser-specific back button
|
||||
elements = ctx.hierarchy.FindByClass("browser-nav-btn");
|
||||
for (const auto& elem : elements) {
|
||||
if (elem.visible && elem.bounds.width > 0 && elem.bounds.height > 0) {
|
||||
return elem;
|
||||
}
|
||||
}
|
||||
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
// Helper: Go back to home screen by clicking back button multiple times
|
||||
void GoHome(TestContext& ctx) {
|
||||
// Click back button (app-bar-nav) up to 5 times to ensure we're at home
|
||||
// Wait longer for hierarchy file to be updated from any previous navigation
|
||||
// The designer writes hierarchy every frame, but there can be a race condition
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1500));
|
||||
|
||||
for (int i = 0; i < 5; ++i) {
|
||||
// Wait then reload to get fresh hierarchy data
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(300));
|
||||
ctx.hierarchy.Reload();
|
||||
// Look for the back button by class
|
||||
auto elements = ctx.hierarchy.FindByClass("app-bar-nav");
|
||||
if (!elements.empty()) {
|
||||
auto& btn = elements[0];
|
||||
if (btn.visible && btn.bounds.width > 0) {
|
||||
int x = btn.bounds.centerX();
|
||||
int y = btn.bounds.centerY();
|
||||
ScaleToPhysical(ctx, x, y);
|
||||
ctx.window.SendClick(x, y);
|
||||
}
|
||||
|
||||
// Check hierarchy to see if dock-phone exists (indicating home screen)
|
||||
auto dockPhone = ctx.hierarchy.FindById("dock-phone");
|
||||
if (dockPhone && dockPhone->visible) {
|
||||
std::cout << " GoHome: At home screen (dock-phone found)" << std::endl;
|
||||
break;
|
||||
}
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(400));
|
||||
|
||||
// Find back button from hierarchy
|
||||
auto backBtn = FindBackButton(ctx);
|
||||
int x, y;
|
||||
if (backBtn) {
|
||||
x = backBtn->bounds.centerX();
|
||||
y = backBtn->bounds.centerY();
|
||||
std::cout << " GoHome: Found back button at (" << x << "," << y << ")" << std::endl;
|
||||
} else {
|
||||
// Fallback to default position if no back button found
|
||||
x = 48;
|
||||
y = 36;
|
||||
std::cout << " GoHome: No back button found, using default position" << std::endl;
|
||||
}
|
||||
|
||||
ScaleToPhysical(ctx, x, y);
|
||||
std::cout << " GoHome: Clicking back at (" << x << "," << y << ")" << std::endl;
|
||||
ctx.window.SendClick(x, y);
|
||||
|
||||
// Wait for navigation animation to complete
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
|
||||
}
|
||||
// Extra wait for animations to fully complete and hierarchy to update
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(800));
|
||||
|
||||
// Final verification - wait and reload hierarchy
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(500));
|
||||
ctx.hierarchy.Reload();
|
||||
std::cout << " GoHome: Final screen = " << ctx.hierarchy.GetScreenName() << std::endl;
|
||||
}
|
||||
|
||||
// Test: Navigate to dialer by clicking Phone dock icon
|
||||
|
||||
Reference in New Issue
Block a user