|
| 1 | +import { test, expect, waitForAIResponse, retryOnAIFailure } from "../../test-isolation-helper"; |
| 2 | +import { HumanInLoopPage } from "../../pages/awsStrandsPages/HumanInLoopPage"; |
| 3 | + |
| 4 | +test.describe("Human in the Loop Feature", () => { |
| 5 | + test("[Strands] should interact with the chat and perform steps", async ({ |
| 6 | + page, |
| 7 | + }) => { |
| 8 | + await retryOnAIFailure(async () => { |
| 9 | + const humanInLoop = new HumanInLoopPage(page); |
| 10 | + |
| 11 | + await page.goto( |
| 12 | + "/aws-strands/feature/human_in_the_loop" |
| 13 | + ); |
| 14 | + |
| 15 | + await humanInLoop.openChat(); |
| 16 | + |
| 17 | + await humanInLoop.sendMessage("Hi"); |
| 18 | + await humanInLoop.agentGreeting.isVisible(); |
| 19 | + |
| 20 | + await humanInLoop.sendMessage( |
| 21 | + "Give me a plan to make brownies, there should be only one step with eggs and one step with oven, this is a strict requirement so adhere" |
| 22 | + ); |
| 23 | + await waitForAIResponse(page); |
| 24 | + await expect(humanInLoop.plan).toBeVisible({ timeout: 10000 }); |
| 25 | + |
| 26 | + const itemText = "eggs"; |
| 27 | + await page.waitForTimeout(5000); |
| 28 | + await humanInLoop.uncheckItem(itemText); |
| 29 | + await humanInLoop.performSteps(); |
| 30 | + |
| 31 | + await page.waitForFunction( |
| 32 | + () => { |
| 33 | + const messages = Array.from(document.querySelectorAll('.copilotKitAssistantMessage')); |
| 34 | + const lastMessage = messages[messages.length - 1]; |
| 35 | + const content = lastMessage?.textContent?.trim() || ''; |
| 36 | + return messages.length >= 3 && content.length > 0; |
| 37 | + }, |
| 38 | + { timeout: 30000 } |
| 39 | + ); |
| 40 | + |
| 41 | + await humanInLoop.sendMessage( |
| 42 | + `Does the planner include ${itemText}? ⚠️ Reply with only words 'Yes' or 'No' (no explanation, no punctuation).` |
| 43 | + ); |
| 44 | + await waitForAIResponse(page); |
| 45 | + }); |
| 46 | + }); |
| 47 | + |
| 48 | + test("[Strands] should interact with the chat using predefined prompts and perform steps", async ({ |
| 49 | + page, |
| 50 | + }) => { |
| 51 | + await retryOnAIFailure(async () => { |
| 52 | + const humanInLoop = new HumanInLoopPage(page); |
| 53 | + |
| 54 | + await page.goto( |
| 55 | + "/aws-strands/feature/human_in_the_loop" |
| 56 | + ); |
| 57 | + |
| 58 | + await humanInLoop.openChat(); |
| 59 | + |
| 60 | + await humanInLoop.sendMessage("Hi"); |
| 61 | + await humanInLoop.agentGreeting.isVisible(); |
| 62 | + await humanInLoop.sendMessage( |
| 63 | + "Plan a mission to Mars with the first step being Start The Planning" |
| 64 | + ); |
| 65 | + await waitForAIResponse(page); |
| 66 | + await expect(humanInLoop.plan).toBeVisible({ timeout: 10000 }); |
| 67 | + |
| 68 | + const uncheckedItem = "Start The Planning"; |
| 69 | + |
| 70 | + await page.waitForTimeout(5000); |
| 71 | + await humanInLoop.uncheckItem(uncheckedItem); |
| 72 | + await humanInLoop.performSteps(); |
| 73 | + |
| 74 | + await page.waitForFunction( |
| 75 | + () => { |
| 76 | + const messages = Array.from(document.querySelectorAll('.copilotKitAssistantMessage')); |
| 77 | + const lastMessage = messages[messages.length - 1]; |
| 78 | + const content = lastMessage?.textContent?.trim() || ''; |
| 79 | + |
| 80 | + return messages.length >= 3 && content.length > 0; |
| 81 | + }, |
| 82 | + { timeout: 30000 } |
| 83 | + ); |
| 84 | + |
| 85 | + await humanInLoop.sendMessage( |
| 86 | + `Does the planner include ${uncheckedItem}? ⚠️ Reply with only words 'Yes' or 'No' (no explanation, no punctuation).` |
| 87 | + ); |
| 88 | + await waitForAIResponse(page); |
| 89 | + }); |
| 90 | + }); |
| 91 | +}); |
0 commit comments