Skip to content

Commit a79d4f5

Browse files
authored
Improve AI usage of newly open tabs (#254)
1 parent 331a584 commit a79d4f5

File tree

5 files changed

+39
-23
lines changed

5 files changed

+39
-23
lines changed

.env.example

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,8 @@ ANTHROPIC_API_KEY=
3131
# Copy from Github Settings
3232
GITHUB_TOTP_SECRET=
3333
GITHUB_USERNAME=
34-
GITHUB_PASSWORD=
34+
GITHUB_PASSWORD=
35+
36+
# Mailosaur integration
37+
MAILOSAUR_API_KEY=
38+
MAILOSAUR_SERVER_ID=

README.md

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,6 @@ You'll need to set up the following services for local development. If you're no
328328
<summary>GitHub OAuth</summary>
329329

330330
1. Create a GitHub OAuth App:
331-
332331
- Go to your GitHub account settings.
333332
- Navigate to `Developer settings` > `OAuth Apps` > `New OAuth App`.
334333
- Fill in the application details:
@@ -344,16 +343,22 @@ You'll need to set up the following services for local development. If you're no
344343
- Enter your `Client ID` and `Client Secret` from the GitHub OAuth app you just created.
345344
- Add `repo` to the `Scopes`
346345
![Clerk Custom Credentials](https://github.com/user-attachments/assets/31d414e1-4e1e-4725-8649-ec1826c6e53e)
347-
</details>
346+
</details>
348347

349348
<details>
350349
<summary>Mailosaur</summary>
351350

352-
1. Go to [mailosaur.com](https://mailosaur.com) and create an account.
353-
2. Create a new server and copy the Server ID.
354-
3. Go to your API settings and copy your API key.
355-
- You'll need both the Server ID and API key for your environment variables: - `MAILOSAUR_API_KEY`: Your API key - `MAILOSAUR_SERVER_ID`: Your server ID
356-
</details>
351+
1. [Sign up](https://mailosaur.com/app/signup) for an account with Mailosaur.
352+
2. Create a new Inbox/Server.
353+
3. Go to [API Keys](https://mailosaur.com/app/keys) and create a standard key.
354+
4. Update the environment variables:
355+
- `MAILOSAUR_API_KEY`: Your API key
356+
- `MAILOSAUR_SERVER_ID`: Your server ID
357+
358+
The email used to test the login flow will have the format `shortest@<MAILOSAUR_SERVER_ID>.mailosaur.net`, where
359+
`MAILOSAUR_SERVER_ID` is your server ID.
360+
Make sure to add the email as a new user under the Clerk app.
361+
</details>
357362

358363
### Running locally
359364

app/(dashboard)/page.test.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import { shortest } from "@antiwork/shortest";
22

33
shortest("Verify that buttons on the landing page are rounded");
4-
shortest("Login using this email: mission-health@rdt7stzf.mailosaur.net");
5-
shortest("Verify that the user can access the /dashboard page");
4+
5+
const loginEmail = `shortest@${process.env.MAILOSAUR_SERVER_ID}.mailosaur.net`;
6+
shortest("Log in", { email: loginEmail }).expect(
7+
"Check Manage Account page from user icon menu",
8+
);

packages/shortest/src/ai/prompts/index.ts

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export const SYSTEM_PROMPT = `You are a test automation expert working with a Ch
44
55
EXAMPLE TEST CASE:
66
------------------
7-
Test: "Login to the app using Github login"
7+
Test: "Log in to the app using GitHub login"
88
Context: {"username":"argo.mohrad@gmail.com","password":"password1234"}
99
Callback function: [NO_CALLBACK]
1010
Expect: 1. Test case to be generated within at least 20 seconds [HAS_CALLBACK]
@@ -25,9 +25,9 @@ IMPORTANT GLOBAL RULES:
2525
- Do not request screenshots until after a tool has completely finished its execution.
2626
- Once the tool execution result is received, you may then request a screenshot to determine subsequent actions if needed.
2727
28-
4. **Github Login Flow with 2FA**:
29-
- If you need to test a Github login flow that involves 2FA, only call the "github_login" tool after you have confirmed that the Github login page is displayed.
30-
- Calling the "github_login" tool prematurely (before the Github login page is visible) will lead to incorrect test behavior.
28+
4. **GitHub Login Flow with 2FA**:
29+
- If you need to test a GitHub login flow that involves 2FA, only call the "github_login" tool after you have confirmed that the GitHub login page is displayed.
30+
- Calling the "github_login" tool prematurely (before the GitHub login page is visible) will lead to incorrect test behavior.
3131
3232
5. **Callbacks**:
3333
- Steps may include a notation like [HAS_CALLBACK], which means after completing the browser actions for that step, you must call the "run_callback" tool.
@@ -43,12 +43,10 @@ IMPORTANT GLOBAL RULES:
4343
- If any expectation is not met, the test case must be marked as failed.
4444
4545
8. **Testing Email**:
46-
- If you need to test a condition that involves seeing the contents of an email, use the "check_email" tool.
47-
- For email validation, you MUST always use 'Click' and 'Mouse' action instead of using keyboard shortcuts.
48-
- This tool will grab the latest email from the email address given to you and will render it in a new tab for you to see.
49-
- Once you are done with validating the email, navigate back to the original tab.
50-
- You MUST pass the email address that is given to you to the tool as a parameter otherwise it will fail.
51-
- If no email address is given to you for this test, you should fail the test.
46+
- If you need to test a condition that involves checking the contents of an email, use the "check_email" tool.
47+
- If no email address is given to you for this test, you must fail the test.
48+
- You MUST pass the email address that is given to you to the tool as a parameter, otherwise it will fail.
49+
- For email validation, you MUST always use 'Click' and 'Mouse' actions instead of keyboard shortcuts.
5250
5351
9. **Bash Commands**:
5452
- You have access to a bash tool to execute bash commands.
@@ -62,7 +60,7 @@ Your task is to:
6260
3. Return test execution results in strict JSON format: { result: "pass" | "fail", reason: string }.
6361
For failures, provide a maximum 1-sentence reason.
6462
IMPORTANT:
65-
- DO NOT include anything else in your response, only the result and reason.
66-
- DO NOT include any other JSON-like object in your response except the required structure.
67-
If there's need to do that, remove braces {} to ensure it's not interpreted as JSON.
63+
- DO NOT include anything else in your response, only the result and reason.
64+
- DO NOT include any other JSON-like object in your response except the required structure.
65+
- If there's need to do that, remove braces {} to ensure it's not interpreted as JSON.
6866
4. For click actions, provide x,y coordinates of the element to click.`;

packages/shortest/src/browser/core/browser-tool.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,12 @@ export class BrowserTool extends BaseBrowserTool {
6262
this.viewport = { width: config.width, height: config.height };
6363
this.testContext = config.testContext;
6464

65+
// Update active page reference to a newly opened tab
66+
this.page.context().on("page", async (newPage) => {
67+
await newPage.waitForLoadState("domcontentloaded").catch(() => {});
68+
this.page = newPage;
69+
});
70+
6571
this.initialize();
6672
this.cleanupScreenshots();
6773
}

0 commit comments

Comments
 (0)