-
Notifications
You must be signed in to change notification settings - Fork 45
Expand file tree
/
Copy pathinstructions.ts
More file actions
146 lines (125 loc) · 5.31 KB
/
instructions.ts
File metadata and controls
146 lines (125 loc) · 5.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
import { SUPPORTED_CONFIGURATIONS } from "./constants.js";
import { SDKSupportedLanguage } from "./types.js";
import { SDKSupportedBrowserAutomationFramework } from "./types.js";
import { SDKSupportedTestingFramework } from "./types.js";
const errorMessageSuffix =
"Please open an issue at our Github repo: https://github.com/browserstack/browserstack-mcp-server/issues to request support for your project configuration";
export const getInstructionsForProjectConfiguration = (
detectedBrowserAutomationFramework: SDKSupportedBrowserAutomationFramework,
detectedTestingFramework: SDKSupportedTestingFramework,
detectedLanguage: SDKSupportedLanguage,
username: string,
accessKey: string,
) => {
const configuration = SUPPORTED_CONFIGURATIONS[detectedLanguage];
if (!configuration) {
throw new Error(
`BrowserStack MCP Server currently does not support ${detectedLanguage}, ${errorMessageSuffix}`,
);
}
if (!configuration[detectedBrowserAutomationFramework]) {
throw new Error(
`BrowserStack MCP Server currently does not support ${detectedBrowserAutomationFramework} for ${detectedLanguage}, ${errorMessageSuffix}`,
);
}
if (
!configuration[detectedBrowserAutomationFramework][detectedTestingFramework]
) {
throw new Error(
`BrowserStack MCP Server currently does not support ${detectedTestingFramework} for ${detectedBrowserAutomationFramework} on ${detectedLanguage}, ${errorMessageSuffix}`,
);
}
const instructionFunction =
configuration[detectedBrowserAutomationFramework][detectedTestingFramework]
.instructions;
return instructionFunction(username, accessKey);
};
export function generateBrowserStackYMLInstructions(
desiredPlatforms: string[],
enablePercy: boolean = false,
) {
let ymlContent = `
# ======================
# BrowserStack Reporting
# ======================
# Project and build names help organize your test runs in BrowserStack dashboard and Percy.
# TODO: Replace these sample values with your actual project details
projectName: Sample Project
buildName: Sample Build
# =======================================
# Platforms (Browsers / Devices to test)
# =======================================
# Platforms object contains all the browser / device combinations you want to test on.
# Generate this on the basis of the following platforms requested by the user:
# Requested platforms: ${desiredPlatforms}
platforms:
- os: Windows
osVersion: 11
browserName: chrome
browserVersion: latest
# =======================
# Parallels per Platform
# =======================
# The number of parallel threads to be used for each platform set.
# BrowserStack's SDK runner will select the best strategy based on the configured value
#
# Example 1 - If you have configured 3 platforms and set \`parallelsPerPlatform\` as 2, a total of 6 (2 * 3) parallel threads will be used on BrowserStack
#
# Example 2 - If you have configured 1 platform and set \`parallelsPerPlatform\` as 5, a total of 5 (1 * 5) parallel threads will be used on BrowserStack
parallelsPerPlatform: 1
# =================
# Local Testing
# =================
# Set to true to test local
browserstackLocal: true
# ===================
# Debugging features
# ===================
debug: true # Visual logs, text logs, etc.
testObservability: true # For Test Observability
# Optional settings (uncomment only if explicitly required)
# geoLocation: "US" # Simulate tests from a specific country (Default: null)
# timezone: "New_York" # Run tests in custom timezone
# retryOnFailure: 2 # Retries failed tests (Default: 0)
# idleTimeout: 30 # Max idle time in seconds (Default: 30, Range: 0-300)
# commandTimeout: 180 # Max time to wait for a command (Default: 180)
# deviceOrientation: portrait # For mobile, choose portrait or landscape (Default: portrait)`;
if (enablePercy) {
ymlContent += `
# =====================
# Percy Visual Testing
# =====================
# Set percy to true to enable visual testing.
# Set percyCaptureMode to 'manual' to control when screenshots are taken.
percy: true
percyCaptureMode: manual`;
}
return `
Create a browserstack.yml file in the project root. The file should be in the following format:
\`\`\`yaml${ymlContent}
\`\`\`
\n`;
}
export function formatInstructionsWithNumbers(
instructionText: string,
separator: string = "---STEP---",
): string {
// Split the instructions by the separator
const steps = instructionText
.split(separator)
.map((step) => step.trim())
.filter((step) => step.length > 0);
// If no separators found, treat the entire text as one step
if (steps.length === 1 && !instructionText.includes(separator)) {
return `**Step 1:**\n${instructionText.trim()}\n\n**✅ Verification:**\nPlease verify that you have completed all the steps above to ensure proper setup.`;
}
// Format each step with numbering
const formattedSteps = steps
.map((step, index) => {
return `**Step ${index + 1}:**\n${step.trim()}`;
})
.join("\n\n");
// Add verification statement at the end
const verificationText = `\n\n**✅ Verification:**\nPlease verify that you have completed all ${steps.length} steps above to ensure proper setup. If you encounter any issues, double-check each step and ensure all commands executed successfully.`;
return formattedSteps + verificationText;
}