screenright-client 0.9.14 → 0.9.20
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +55 -3
- package/package.json +1 -1
- package/src/index.ts +18 -9
package/README.md
CHANGED
@@ -1,15 +1,67 @@
|
|
1
1
|
# ScreenRight nodejs client library.
|
2
2
|
|
3
|
-
##
|
3
|
+
## Installation
|
4
|
+
```
|
5
|
+
npm i screenright-client
|
6
|
+
```
|
7
|
+
|
8
|
+
## Setup environments
|
4
9
|
|
5
10
|
### Diagram Id
|
6
11
|
|
7
12
|
```
|
8
|
-
SCREENRIGHT_DIAGRAM_ID
|
13
|
+
export SCREENRIGHT_DIAGRAM_ID=xxxxxxx
|
9
14
|
```
|
10
15
|
|
11
16
|
### Deployment Token
|
12
17
|
```
|
13
|
-
SCREENRIGHT_DEPLOYMENT_TOKEN
|
18
|
+
export SCREENRIGHT_DEPLOYMENT_TOKEN=xxxxxxx
|
19
|
+
```
|
20
|
+
|
21
|
+
## Implementation
|
22
|
+
|
23
|
+
### with "Playwright"
|
24
|
+
|
25
|
+
```
|
26
|
+
import { capture, initializeScreenwright, finalize } from "screenright-client"
|
27
|
+
|
28
|
+
test("basic test", async ({ page }) => {
|
29
|
+
|
30
|
+
await initializeScreenwright() // The diagram ID specified in the environment variable is used.
|
31
|
+
// await initializeScreenwright(diagramId) <- The diagram ID specified in the argument is used.
|
32
|
+
|
33
|
+
|
34
|
+
// With the key home, capture with the title "Home Screen".
|
35
|
+
await capture(page, "home", "Home Screen")
|
36
|
+
|
37
|
+
|
38
|
+
// Created with "setting" as the parent screen.
|
39
|
+
await capture(
|
40
|
+
page,
|
41
|
+
"setting|projects",
|
42
|
+
"Project list",
|
43
|
+
"setting"
|
44
|
+
)
|
45
|
+
|
46
|
+
|
47
|
+
// Specify options.
|
48
|
+
await capture(
|
49
|
+
page,
|
50
|
+
"home",
|
51
|
+
"Home Screen",
|
52
|
+
undefined,
|
53
|
+
{
|
54
|
+
waitMilliseconds: 200, // wait before capturing.
|
55
|
+
clickLocatorSelector: `button:text("delete)`, // specify the element you want to click.
|
56
|
+
annotationText: "Click here!", // specify the annotation.
|
57
|
+
annotationDirection: "bottom", // Specifies the position of the annotation from the element.
|
58
|
+
paddingPixel: 4, // Specifies the padding for the border surrounding the element.
|
59
|
+
annotationTextColor: "red" | "blue" | "black" | "white" | "yellow" | "green"
|
60
|
+
description: "write a description"
|
61
|
+
}
|
62
|
+
)
|
63
|
+
|
64
|
+
await finalize()
|
65
|
+
})
|
14
66
|
```
|
15
67
|
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
import * as fs from 'fs'
|
2
1
|
import { Page } from '@playwright/test'
|
3
2
|
import fetch from 'node-fetch'
|
4
3
|
import process from 'node:process'
|
@@ -35,9 +34,7 @@ const result: Result = { diagramId: "", screenshotItemAttributes: [], annotation
|
|
35
34
|
let deploymentId: string | null = null
|
36
35
|
const deploymentToken: string = process.env.SCREENRIGHT_DEPLOYMENT_TOKEN || ''
|
37
36
|
|
38
|
-
const baseUrl =
|
39
|
-
return `${process.env.SCREENRIGHT_ENDPOINT}/client_api`
|
40
|
-
}
|
37
|
+
const baseUrl = `${process.env.SCREENRIGHT_ENDPOINT || 'https://screenright.app'}/client_api`
|
41
38
|
|
42
39
|
const errorOccurred = (message: string) => {
|
43
40
|
console.error('[ScreenRight] Error occurred', message)
|
@@ -55,7 +52,7 @@ export const initializeScreenwright = async (diagramId?: string) => {
|
|
55
52
|
result.diagramId = _diagramId
|
56
53
|
|
57
54
|
try {
|
58
|
-
const response = await fetch(`${baseUrl
|
55
|
+
const response = await fetch(`${baseUrl}/diagrams/${result.diagramId}/deployments`, {
|
59
56
|
method: 'POST',
|
60
57
|
body: JSON.stringify({ deployment_token: deploymentToken }),
|
61
58
|
headers: { 'Content-Type': 'application/json' }
|
@@ -78,9 +75,15 @@ export const finalize = async () => {
|
|
78
75
|
return
|
79
76
|
}
|
80
77
|
|
81
|
-
await fetch(`${baseUrl
|
78
|
+
await fetch(`${baseUrl}/diagrams/${result.diagramId}/deployments/${deploymentId}/done_upload`, {
|
82
79
|
method: 'PUT',
|
83
|
-
body: JSON.stringify({
|
80
|
+
body: JSON.stringify({
|
81
|
+
deployment_token: deploymentToken,
|
82
|
+
blueprint: JSON.stringify({
|
83
|
+
screenshotItemAttributes: result.screenshotItemAttributes,
|
84
|
+
annotations: result.annotations
|
85
|
+
})
|
86
|
+
}),
|
84
87
|
headers: { 'Content-Type': 'application/json' }
|
85
88
|
})
|
86
89
|
|
@@ -106,7 +109,13 @@ type CaptureOptions = {
|
|
106
109
|
* @param {string} key - Unique key. cannot contain slashes.
|
107
110
|
* @param {string} title - Page title.
|
108
111
|
* @param {string|null} [parentKey] - Parent page key. Creates a hierarchical structure.
|
109
|
-
* @param {{
|
112
|
+
* @param {{}} [options] -
|
113
|
+
* waitMilliseconds: number = 0, Wait milliseconds before capture.
|
114
|
+
* clickLocatorSelector: string,
|
115
|
+
* annotationText: string = "",
|
116
|
+
* paddingPixel: number = 4,
|
117
|
+
* annotationDirection: AnnotationDirection = "bottom",
|
118
|
+
* AnnotationTextColor = "red"
|
110
119
|
*/
|
111
120
|
export const capture = async (
|
112
121
|
page: Page,
|
@@ -156,7 +165,7 @@ export const capture = async (
|
|
156
165
|
|
157
166
|
formData.append('file', buffer, fileName)
|
158
167
|
|
159
|
-
const response = await fetch(`${baseUrl
|
168
|
+
const response = await fetch(`${baseUrl}/diagrams/${result.diagramId}/deployments/${deploymentId}/screenshot`, {
|
160
169
|
method: 'POST',
|
161
170
|
headers: {
|
162
171
|
'X-File-Key': key,
|