11package org .testar .action .priorization .llm ;
22
3+ import static org .junit .Assert .assertEquals ;
4+
35import java .util .HashSet ;
46import java .util .Set ;
57
1214import org .testar .monkey .alayer .actions .CompoundAction ;
1315import org .testar .monkey .alayer .actions .StdActionCompiler ;
1416import org .testar .monkey .alayer .actions .Type ;
17+ import org .testar .monkey .alayer .actions .WdCloseTabAction ;
18+ import org .testar .monkey .alayer .actions .WdHistoryBackAction ;
1519import org .testar .monkey .alayer .actions .WdRemoteScrollTypeAction ;
1620import org .testar .monkey .alayer .actions .WdRemoteTypeAction ;
1721import org .testar .monkey .alayer .actions .WdSelectListAction ;
@@ -222,6 +226,42 @@ public void test_llm_selects_android_type_action() {
222226 Assert .isTrue (innerText .equals ("testar" ));
223227 }
224228
229+ @ Test
230+ public void test_parsing_hit_escape_action () {
231+ String llmResponse = "```json{\" actionId\" :\" AID_HitEsc\" ,\" input\" :\" \" }```" ;
232+ Set <Action > derivedActions = createDefaultDerivedActions (createState ());
233+
234+ LlmParseActionResponse llmParseResponse = new LlmParseActionResponse ();
235+ LlmParseActionResult llmParseResult = llmParseResponse .parseLlmResponse (derivedActions , llmResponse );
236+
237+ assertEquals (LlmParseActionResult .ParseResult .SUCCESS , llmParseResult .getParseResult ());
238+ assertEquals ("AID_HitEsc" , llmParseResult .getActionToExecute ().get (Tags .AbstractID ));
239+ }
240+
241+ @ Test
242+ public void test_parsing_wd_navigate_back_action () {
243+ String llmResponse = "```json{\" actionId\" :\" AID_NavBack\" ,\" input\" :\" \" }```" ;
244+ Set <Action > derivedActions = createDefaultDerivedActions (createState ());
245+
246+ LlmParseActionResponse llmParseResponse = new LlmParseActionResponse ();
247+ LlmParseActionResult llmParseResult = llmParseResponse .parseLlmResponse (derivedActions , llmResponse );
248+
249+ assertEquals (LlmParseActionResult .ParseResult .SUCCESS , llmParseResult .getParseResult ());
250+ assertEquals ("AID_NavBack" , llmParseResult .getActionToExecute ().get (Tags .AbstractID ));
251+ }
252+
253+ @ Test
254+ public void test_parsing_wd_close_tab_action () {
255+ String llmResponse = "```json{\" actionId\" :\" AID_CloseTab\" ,\" input\" :\" \" }```" ;
256+ Set <Action > derivedActions = createDefaultDerivedActions (createState ());
257+
258+ LlmParseActionResponse llmParseResponse = new LlmParseActionResponse ();
259+ LlmParseActionResult llmParseResult = llmParseResponse .parseLlmResponse (derivedActions , llmResponse );
260+
261+ assertEquals (LlmParseActionResult .ParseResult .SUCCESS , llmParseResult .getParseResult ());
262+ assertEquals ("AID_CloseTab" , llmParseResult .getActionToExecute ().get (Tags .AbstractID ));
263+ }
264+
225265 private static StateStub createState () {
226266 StateStub createdState = new StateStub ();
227267 createdState .set (WdTags .WebTitle , "Page Title | State" );
@@ -241,6 +281,9 @@ private static Set<Action> createDefaultDerivedActions(StateStub state) {
241281 derivedActions .add (createSelectAction (state , "combobox_widget_desc" , "combobox_widget_web_id" ,
242282 "CID_combobox_widget" , "AID_combobox_widget" , "CID_select" , "AID_select" , "Saab" ));
243283 derivedActions .add (createAndroidTypeAction (state ));
284+ derivedActions .add (createHitEscAction (state , "CID_HitEsc" , "AID_HitEsc" ));
285+ derivedActions .add (createWdHistoryBackAction (state , "CID_NavBack" , "AID_NavBack" ));
286+ derivedActions .add (createWdCloseTabAction (state , "CID_CloseTab" , "AID_CloseTab" ));
244287 return derivedActions ;
245288 }
246289
@@ -321,4 +364,25 @@ private static Action createAndroidTypeAction(StateStub parentState) {
321364 return action ;
322365 }
323366
367+ private static Action createHitEscAction (StateStub parentState , String actionConcreteId , String actionAbstractId ) {
368+ Action action = ac .hitESC (parentState );
369+ action .set (Tags .ConcreteID , actionConcreteId );
370+ action .set (Tags .AbstractID , actionAbstractId );
371+ return action ;
372+ }
373+
374+ private static Action createWdHistoryBackAction (StateStub parentState , String actionConcreteId , String actionAbstractId ) {
375+ Action action = new WdHistoryBackAction (parentState );
376+ action .set (Tags .ConcreteID , actionConcreteId );
377+ action .set (Tags .AbstractID , actionAbstractId );
378+ return action ;
379+ }
380+
381+ private static Action createWdCloseTabAction (StateStub parentState , String actionConcreteId , String actionAbstractId ) {
382+ Action action = new WdCloseTabAction (parentState );
383+ action .set (Tags .ConcreteID , actionConcreteId );
384+ action .set (Tags .AbstractID , actionAbstractId );
385+ return action ;
386+ }
387+
324388}
0 commit comments