11 const std::vector<ai::AIAction>& actions) {
13 auto json_result = GenerateTestJSON(actions);
14 if (!json_result.ok()) {
15 return json_result.status();
17 return json_result->dump(2);
19 return absl::UnimplementedError(
"JSON support required for test script generation");
24absl::StatusOr<nlohmann::json> GuiActionGenerator::GenerateTestJSON(
25 const std::vector<ai::AIAction>& actions) {
26 nlohmann::json test_script;
27 test_script[
"test_name"] =
"ai_generated_test";
28 test_script[
"description"] =
"Automatically generated from AI actions";
29 test_script[
"steps"] = nlohmann::json::array();
31 for (
size_t i = 0; i < actions.size(); ++i) {
32 nlohmann::json step = ActionToJSON(actions[i]);
33 step[
"step_number"] = i + 1;
34 test_script[
"steps"].push_back(step);
40nlohmann::json GuiActionGenerator::ActionToJSON(
const ai::AIAction& action) {
43 switch (action.type) {
45 step[
"action"] =
"click";
46 auto it = action.parameters.find(
"editor");
47 if (it != action.parameters.end()) {
48 step[
"target"] = absl::StrCat(
"button:", it->second,
" Editor");
49 step[
"wait_after"] = 500;
55 step[
"action"] =
"click";
56 auto it = action.parameters.find(
"tile_id");
57 if (it != action.parameters.end()) {
58 int tile_id = std::stoi(it->second);
60 int tile_x = (tile_id % 8) * 16 + 8;
61 int tile_y = (tile_id / 8) * 16 + 8;
63 step[
"target"] =
"canvas:tile16_selector";
64 step[
"position"] = {{
"x", tile_x}, {
"y", tile_y}};
65 step[
"wait_after"] = 200;
71 step[
"action"] =
"click";
72 auto x_it = action.parameters.find(
"x");
73 auto y_it = action.parameters.find(
"y");
75 if (x_it != action.parameters.end() && y_it != action.parameters.end()) {
78 int screen_x = std::stoi(x_it->second) * 16 + 8;
79 int screen_y = std::stoi(y_it->second) * 16 + 8;
81 step[
"target"] =
"canvas:overworld_map";
82 step[
"position"] = {{
"x", screen_x}, {
"y", screen_y}};
83 step[
"wait_after"] = 200;
89 step[
"action"] =
"click";
90 step[
"target"] =
"button:Save to ROM";
91 step[
"wait_after"] = 300;
96 step[
"action"] =
"click";
97 auto it = action.parameters.find(
"button");
98 if (it != action.parameters.end()) {
99 step[
"target"] = absl::StrCat(
"button:", it->second);
100 step[
"wait_after"] = 200;
106 step[
"action"] =
"wait";
107 auto it = action.parameters.find(
"duration_ms");
108 int duration = it != action.parameters.end() ? std::stoi(it->second) : 500;
109 step[
"duration_ms"] = duration;
114 step[
"action"] =
"screenshot";
115 auto it = action.parameters.find(
"filename");
116 if (it != action.parameters.end()) {
117 step[
"filename"] = it->second;
119 step[
"filename"] =
"verification.png";
125 step[
"action"] =
"verify";
126 step[
"target"] =
"tile_placement";
128 for (
const auto& [key, value] : action.parameters) {
135 step[
"action"] =
"error";
136 step[
"message"] =
"Invalid action type";
146 switch (action.
type) {
162 return absl::StrFormat(
"# Step %d: Unknown action", step_number);
169 return absl::StrFormat(
"Click button:'%s Editor'\nWait 500ms", it->second);
171 return "Click button:'Editor'\nWait 500ms";
177 int tile_id = std::stoi(it->second);
178 int tile_x = (tile_id % 8) * 16 + 8;
179 int tile_y = (tile_id / 8) * 16 + 8;
180 return absl::StrFormat(
"Click canvas:'tile16_selector' at (%d, %d)\nWait 200ms",
183 return "Click canvas:'tile16_selector'\nWait 200ms";
191 int screen_x = std::stoi(x_it->second) * 16 + 8;
192 int screen_y = std::stoi(y_it->second) * 16 + 8;
193 return absl::StrFormat(
"Click canvas:'overworld_map' at (%d, %d)\nWait 200ms",
196 return "Click canvas:'overworld_map'\nWait 200ms";
200 return "Click button:'Save to ROM'\nWait 300ms";
206 return absl::StrFormat(
"Click button:'%s'\nWait 200ms", it->second);
208 return "Click button\nWait 200ms";
212 auto it = action.
parameters.find(
"duration_ms");
213 int duration = it != action.
parameters.end() ? std::stoi(it->second) : 500;
214 return absl::StrFormat(
"Wait %dms", duration);
220 return absl::StrFormat(
"Screenshot '%s'", it->second);
222 return "Screenshot 'verification.png'";