more on testing framework
This commit is contained in:
@@ -1,60 +1,67 @@
|
||||
// Action player for replaying recorded UI interactions
|
||||
// D:\Dev\Mosis\MosisService\designer\src\testing\action_player.h
|
||||
#pragma once
|
||||
|
||||
#include "action_recorder.h"
|
||||
#include "action_types.h"
|
||||
#include <RmlUi/Core.h>
|
||||
#include <functional>
|
||||
|
||||
namespace mosis {
|
||||
class IKernel;
|
||||
}
|
||||
#include <chrono>
|
||||
|
||||
namespace mosis::testing {
|
||||
|
||||
// Callback for when an action is executed
|
||||
using ActionCallback = std::function<void(const Action&, size_t index)>;
|
||||
|
||||
// Plays back recorded actions
|
||||
class ActionPlayer {
|
||||
public:
|
||||
ActionPlayer() = default;
|
||||
using ScreenshotCallback = std::function<void(const std::string& filename)>;
|
||||
using NavigateCallback = std::function<void(const std::string& screen)>;
|
||||
|
||||
// Set the kernel for executing actions
|
||||
void SetKernel(IKernel* kernel) { m_kernel = kernel; }
|
||||
|
||||
// Load actions to play
|
||||
void LoadActions(const std::vector<Action>& actions);
|
||||
void LoadFromFile(const std::string& path);
|
||||
ActionPlayer(Rml::Context* context);
|
||||
~ActionPlayer() = default;
|
||||
|
||||
// Load and play
|
||||
bool LoadSequence(const ActionSequence& sequence);
|
||||
bool LoadFromFile(const std::string& path);
|
||||
|
||||
// Playback control
|
||||
void Play();
|
||||
void Pause();
|
||||
void Start();
|
||||
void Stop();
|
||||
void Reset();
|
||||
void Pause();
|
||||
void Resume();
|
||||
bool IsPlaying() const { return m_playing && !m_paused; }
|
||||
bool IsPaused() const { return m_paused; }
|
||||
bool IsFinished() const { return m_finished; }
|
||||
|
||||
// Step through one action at a time
|
||||
void StepForward();
|
||||
|
||||
// Update (call each frame)
|
||||
void Update(double delta_time_ms);
|
||||
|
||||
// State
|
||||
bool IsPlaying() const { return m_playing; }
|
||||
bool IsFinished() const { return m_current_index >= m_actions.size(); }
|
||||
size_t GetCurrentIndex() const { return m_current_index; }
|
||||
size_t GetActionCount() const { return m_actions.size(); }
|
||||
// Call this every frame to advance playback
|
||||
void Update();
|
||||
|
||||
// Callbacks
|
||||
void SetActionCallback(ActionCallback callback) { m_action_callback = callback; }
|
||||
void SetScreenshotCallback(ScreenshotCallback cb) { m_screenshot_cb = std::move(cb); }
|
||||
void SetNavigateCallback(NavigateCallback cb) { m_navigate_cb = std::move(cb); }
|
||||
|
||||
// Get progress
|
||||
size_t GetCurrentActionIndex() const { return m_current_index; }
|
||||
size_t GetTotalActions() const { return m_sequence.actions.size(); }
|
||||
float GetProgress() const;
|
||||
|
||||
private:
|
||||
void ExecuteAction(const Action& action);
|
||||
void SimulateTap(int x, int y);
|
||||
void SimulateSwipe(int x1, int y1, int x2, int y2, int duration_ms);
|
||||
void SimulateLongPress(int x, int y, int duration_ms);
|
||||
void SimulateButton(const std::string& button);
|
||||
|
||||
IKernel* m_kernel = nullptr;
|
||||
std::vector<Action> m_actions;
|
||||
size_t m_current_index = 0;
|
||||
double m_elapsed_time_ms = 0;
|
||||
Rml::Context* m_context;
|
||||
ActionSequence m_sequence;
|
||||
|
||||
bool m_playing = false;
|
||||
ActionCallback m_action_callback;
|
||||
bool m_paused = false;
|
||||
bool m_finished = false;
|
||||
size_t m_current_index = 0;
|
||||
|
||||
std::chrono::steady_clock::time_point m_start_time;
|
||||
std::chrono::steady_clock::time_point m_pause_time;
|
||||
int64_t m_paused_duration_ms = 0;
|
||||
|
||||
ScreenshotCallback m_screenshot_cb;
|
||||
NavigateCallback m_navigate_cb;
|
||||
};
|
||||
|
||||
} // namespace mosis::testing
|
||||
|
||||
Reference in New Issue
Block a user