@applitools/eyes-images 4.21.0 → 4.22.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,34 +0,0 @@
1
- 'use strict'
2
-
3
- const axios = require('axios') // eslint-disable-line node/no-unpublished-require
4
- const {Eyes, Target, ConsoleLogHandler, RectangleSize} = require('../index') // should be replaced to '@applitools/eyes-images'
5
-
6
- ;(async () => {
7
- // Initialize the eyes SDK and set your private API key.
8
- const eyes = new Eyes()
9
- // eyes.setApiKey('Your API Key');
10
- eyes.setLogHandler(new ConsoleLogHandler(false))
11
- // Define the OS.
12
- eyes.setHostOS('Windows 10')
13
-
14
- try {
15
- // Start the test and set the browser's viewport size to 800x600.
16
- await eyes.open('Image test', 'Javascript screenshot test!', new RectangleSize(800, 600))
17
-
18
- // Load page image and validate.
19
- const response = await axios(
20
- 'https://www.google.com/logos/doodles/2018/tyrus-wongs-108th-birthday-6464919774953472.2-s.png',
21
- {responseType: 'arraybuffer'},
22
- )
23
- const img = Buffer.from(response.data, 'binary')
24
-
25
- // Visual validation.
26
- await eyes.check('Google logo', Target.image(img))
27
-
28
- // End the test.
29
- await eyes.close()
30
- } finally {
31
- // If the test was aborted before eyes.close was called ends the test as aborted.
32
- await eyes.abort()
33
- }
34
- })()
package/index.js DELETED
@@ -1,80 +0,0 @@
1
- 'use strict'
2
-
3
- const core = require('@applitools/eyes-sdk-core')
4
-
5
- exports.ImagesCheckSettings = require('./lib/fluent/ImagesCheckSettings').ImagesCheckSettings
6
- exports.Target = require('./lib/fluent/Target').Target
7
-
8
- exports.Eyes = require('./lib/Eyes').Eyes
9
-
10
- // eyes-common
11
- exports.AccessibilityLevel = core.AccessibilityLevel
12
- exports.AccessibilityMatchSettings = core.AccessibilityMatchSettings
13
- exports.AccessibilityRegionType = core.AccessibilityRegionType
14
- exports.AccessibilityGuidelinesVersion = core.AccessibilityGuidelinesVersion
15
- exports.BatchInfo = core.BatchInfo
16
- exports.BrowserType = core.BrowserType
17
- exports.Configuration = core.Configuration
18
- exports.DeviceName = core.DeviceName
19
- exports.ExactMatchSettings = core.ExactMatchSettings
20
- exports.FloatingMatchSettings = core.FloatingMatchSettings
21
- exports.ImageMatchSettings = core.ImageMatchSettings
22
- exports.MatchLevel = core.MatchLevel
23
- exports.PropertyData = core.PropertyData
24
- exports.ProxySettings = core.ProxySettings
25
- exports.ScreenOrientation = core.ScreenOrientation
26
- exports.StitchMode = core.StitchMode
27
- exports.DebugScreenshotsProvider = core.DebugScreenshotsProvider
28
- exports.FileDebugScreenshotsProvider = core.FileDebugScreenshotsProvider
29
- exports.NullDebugScreenshotProvider = core.NullDebugScreenshotProvider
30
- exports.EyesError = core.EyesError
31
- exports.CoordinatesType = core.CoordinatesType
32
- exports.Location = core.Location
33
- exports.RectangleSize = core.RectangleSize
34
- exports.Region = core.Region
35
- exports.PropertyHandler = core.PropertyHandler
36
- exports.ReadOnlyPropertyHandler = core.ReadOnlyPropertyHandler
37
- exports.SimplePropertyHandler = core.SimplePropertyHandler
38
- exports.ImageDeltaCompressor = core.ImageDeltaCompressor
39
- exports.MutableImage = core.MutableImage
40
- exports.ConsoleLogHandler = core.ConsoleLogHandler
41
- exports.DebugLogHandler = core.DebugLogHandler
42
- exports.FileLogHandler = core.FileLogHandler
43
- exports.Logger = core.Logger
44
- exports.LogHandler = core.LogHandler
45
- exports.NullLogHandler = core.NullLogHandler
46
- exports.GeneralUtils = core.GeneralUtils
47
-
48
- // eyes-sdk-core
49
- exports.ImageProvider = core.ImageProvider
50
- exports.FullPageCaptureAlgorithm = core.FullPageCaptureAlgorithm
51
- exports.EyesSimpleScreenshotFactory = core.EyesSimpleScreenshotFactory
52
- exports.CorsIframeHandle = core.CorsIframeHandle
53
- exports.CutProvider = core.CutProvider
54
- exports.FixedCutProvider = core.FixedCutProvider
55
- exports.NullCutProvider = core.NullCutProvider
56
- exports.UnscaledFixedCutProvider = core.UnscaledFixedCutProvider
57
- exports.ScaleProvider = core.ScaleProvider
58
- exports.FixedScaleProvider = core.FixedScaleProvider
59
- exports.FixedScaleProviderFactory = core.FixedScaleProviderFactory
60
- exports.PositionMemento = core.PositionMemento
61
- exports.PositionProvider = core.PositionProvider
62
- exports.RemoteSessionEventHandler = core.RemoteSessionEventHandler
63
- exports.SessionEventHandler = core.SessionEventHandler
64
- exports.ValidationInfo = core.ValidationInfo
65
- exports.ValidationResult = core.ValidationResult
66
- exports.CoordinatesTypeConversionError = core.CoordinatesTypeConversionError
67
- exports.DiffsFoundError = core.DiffsFoundError
68
- exports.NewTestError = core.NewTestError
69
- exports.OutOfBoundsError = core.OutOfBoundsError
70
- exports.TestFailedError = core.TestFailedError
71
- exports.MatchResult = core.MatchResult
72
- exports.NullRegionProvider = core.NullRegionProvider
73
- exports.RegionProvider = core.RegionProvider
74
- exports.RunningSession = core.RunningSession
75
- exports.SessionType = core.SessionType
76
- exports.FailureReports = core.FailureReports
77
- exports.TestResults = core.TestResults
78
- exports.TestResultsFormatter = core.TestResultsFormatter
79
- exports.TestResultsStatus = core.TestResultsStatus
80
- exports.BatchClose = core.BatchClose
package/lib/Eyes.js DELETED
@@ -1,471 +0,0 @@
1
- 'use strict'
2
-
3
- const {
4
- ArgumentGuard,
5
- TypeUtils,
6
- FileUtils,
7
- EyesError,
8
- MutableImage,
9
- RectangleSize,
10
- EyesBase,
11
- RegionProvider,
12
- NullRegionProvider,
13
- EyesSimpleScreenshot,
14
- GeneralUtils,
15
- Location,
16
- } = require('@applitools/eyes-sdk-core')
17
-
18
- const {Target} = require('./fluent/Target')
19
- const VERSION = require('../package.json').version
20
-
21
- /**
22
- * The main type - to be used by the users of the library to access all functionality.
23
- */
24
- class Eyes extends EyesBase {
25
- /**
26
- * Initializes an Eyes instance.
27
- *
28
- * @param {string} [serverUrl] The Eyes server URL.
29
- * @param {?boolean} [isDisabled=false] - Will be checked <b>before</b> any argument validation. If true, all method
30
- * will immediately return without performing any action.
31
- */
32
- constructor(serverUrl, isDisabled) {
33
- super(serverUrl, isDisabled)
34
-
35
- this._getBatchInfo = GeneralUtils.cachify(
36
- this._serverConnector.batchInfo.bind(this._serverConnector),
37
- )
38
- /** @type {String} */ this._title = undefined
39
- /** @type {String} */ this._domString = undefined
40
- /** @type {Location} */ this._imageLocation = undefined
41
- this._inferred = ''
42
-
43
- /** @type {MutableImage} */ this._screenshot = undefined
44
- /** @type {String} */ this._screenshotUrl = undefined
45
- /** @type {ImageProvider} */ this._screenshotProvider = undefined
46
- }
47
-
48
- /**
49
- * @override
50
- */
51
- getBaseAgentId() {
52
- return `eyes.images.javascript/${VERSION}`
53
- }
54
-
55
- /**
56
- * Starts a test.
57
- *
58
- * @param {string} appName - The application being tested.
59
- * @param {string} testName - The test's name.
60
- * @param {RectangleSize} [imageSize] - Determines the resolution used for the baseline. {@code null} will
61
- * automatically grab the resolution from the image.
62
- * @return {Promise}
63
- */
64
- open(appName, testName, imageSize) {
65
- return super.openBase(appName, testName, imageSize)
66
- }
67
-
68
- /**
69
- * Perform visual validation for the current image.
70
- *
71
- * @signature `checkImage(base64String, name, ignoreMismatch, retryTimeout)`
72
- * @sigparam {string} base64String - A base64 encoded image to use as the checkpoint image
73
- * @sigparam {string} [name] - Tag to be associated with the validation checkpoint.
74
- * @sigparam {boolean} [ignoreMismatch] - True if the server should ignore a negative result for the visual validation.
75
- * @sigparam {number} [retryTimeout] - timeout for performing the match (ms).
76
- *
77
- * @signature `checkImage(url, name, ignoreMismatch, retryTimeout)`
78
- * @sigparam {string} url - A URL of the PNG image to download and use as the checkpoint image
79
- *
80
- * @signature `checkImage(filePath, name, ignoreMismatch, retryTimeout)`
81
- * @sigparam {string} filePath - Path to a local PNG file to use as the checkpoint image
82
- *
83
- * @signature `checkImage(imageBuffer, name, ignoreMismatch, retryTimeout)`
84
- * @sigparam {Buffer} imageBuffer - A Buffer object that contains an image to use as checkpoint image
85
- *
86
- * @signature `checkImage(mutableImage, name, ignoreMismatch, retryTimeout)`
87
- * @sigparam {MutableImage} mutableImage - An in memory image to use as the checkpoint image
88
- *
89
- * @signature `checkImage(imageProvider, name, ignoreMismatch, retryTimeout)`
90
- * @sigparam {ImageProvider} imageProvider - An instance of class (object) which implements {@link ImageProvider}
91
- * (has a method called {@code getImage} which returns {@code Promise<MutableImage>})
92
- *
93
- * @param {string|Buffer|ImageProvider|MutableImage} image - The image path, base64 string, image buffer or MutableImage.
94
- * @param {string} [name] - Tag to be associated with the validation checkpoint.
95
- * @param {boolean} [ignoreMismatch] - True if the server should ignore a negative result for the visual validation.
96
- * @param {number} [retryTimeout] - timeout for performing the match (ms).
97
- * @return {Promise<boolean>} - True if the image matched the expected output, false otherwise.
98
- * @throws {DiffsFoundError} Thrown if a mismatch is detected and immediate failure reports are enabled.
99
- */
100
- async checkImage(image, name, ignoreMismatch = false, retryTimeout = -1) {
101
- return this.check(
102
- name,
103
- Target.image(image)
104
- .ignoreMismatch(ignoreMismatch)
105
- .timeout(retryTimeout),
106
- )
107
- }
108
-
109
- /**
110
- * Perform visual validation for the current image.
111
- *
112
- * @signature `checkRegion(base64String, region, name, ignoreMismatch, retryTimeout)`
113
- * @sigparam {string} base64String - A base64 encoded image to use as the checkpoint image
114
- * @sigparam {Region|RegionObject} region - The region of the image which should be verified, or {undefined}/{null} if the
115
- * entire image should be verified.
116
- * @sigparam {string} [name] - Tag to be associated with the validation checkpoint.
117
- * @sigparam {boolean} [ignoreMismatch] - True if the server should ignore a negative result for the visual validation.
118
- * @sigparam {number} [retryTimeout] - timeout for performing the match (ms).
119
- *
120
- * @signature `checkRegion(url, region, name, ignoreMismatch, retryTimeout)`
121
- * @sigparam {string} url - A URL of the PNG image to download and use as the checkpoint image
122
- *
123
- * @signature `checkRegion(filePath, region, name, ignoreMismatch, retryTimeout)`
124
- * @sigparam {string} filePath - Path to a local PNG file to use as the checkpoint image
125
- *
126
- * @signature `checkRegion(imageBuffer, region, name, ignoreMismatch, retryTimeout)`
127
- * @sigparam {Buffer} imageBuffer - A Buffer object that contains an image to use as checkpoint image
128
- *
129
- * @signature `checkRegion(mutableImage, region, name, ignoreMismatch, retryTimeout)`
130
- * @sigparam {MutableImage} mutableImage - An in memory image to use as the checkpoint image
131
- *
132
- * @signature `checkRegion(imageProvider, region, name, ignoreMismatch, retryTimeout)`
133
- * @sigparam {ImageProvider} imageProvider - An instance of class (object) which implements {@link ImageProvider}
134
- * (has a method called {@code getImage} which returns {@code Promise<MutableImage>})
135
- *
136
- * @param {string|Buffer|ImageProvider|MutableImage} image - The image path, base64 string, image buffer or MutableImage.
137
- * @param {Region|RegionObject} region - The region of the image which should be verified, or {undefined}/{null} if the
138
- * entire image should be verified.
139
- * @param {string} [name] - An optional tag to be associated with the validation checkpoint.
140
- * @param {boolean} [ignoreMismatch] - True if the server should ignore a negative result for the visual validation.
141
- * @param {number} [retryTimeout] - timeout for performing the match (ms).
142
- * @return {Promise<boolean>} - True if the image matched the expected output, false otherwise.
143
- * @throws {DiffsFoundError} Thrown if a mismatch is detected and immediate failure reports are enabled.
144
- */
145
- async checkRegion(image, region, name, ignoreMismatch = false, retryTimeout = -1) {
146
- return this.check(
147
- name,
148
- Target.region(image, region)
149
- .ignoreMismatch(ignoreMismatch)
150
- .timeout(retryTimeout),
151
- )
152
- }
153
-
154
- /**
155
- * @param {string} name - An optional tag to be associated with the validation checkpoint.
156
- * @param {ImagesCheckSettings|CheckSettings} checkSettings - The settings to use when checking the image.
157
- * @return {Promise<boolean>} - A promise which is resolved when the validation is finished. Indicates whether
158
- * matchResults was as expected or not.
159
- */
160
- async check(name, checkSettings) {
161
- ArgumentGuard.notNull(checkSettings, 'checkSettings')
162
-
163
- if (this.getIsDisabled()) {
164
- this._logger.verbose(`check('${name}', checkSettings): Ignored`)
165
- return false
166
- }
167
-
168
- if (TypeUtils.isNotNull(name)) {
169
- checkSettings.withName(name)
170
- } else {
171
- name = checkSettings.getName()
172
- }
173
-
174
- try {
175
- let regionProvider = new NullRegionProvider()
176
-
177
- // Set the title to be linked to the screenshot.
178
- this._title = name
179
- this._domString = checkSettings.getDomString()
180
- this._imageLocation = checkSettings.getImageLocation()
181
-
182
- if (checkSettings.getTargetRegion()) {
183
- regionProvider = new RegionProvider(checkSettings.getTargetRegion())
184
- }
185
-
186
- if (checkSettings.getImageUrl()) {
187
- this._screenshotUrl = checkSettings.getImageUrl()
188
-
189
- if (!this._viewportSizeHandler.get() && checkSettings.getImageSize()) {
190
- await this.setViewportSize(checkSettings.getImageSize())
191
- }
192
- } else if (checkSettings.getImageProvider()) {
193
- this._screenshotProvider = checkSettings.getImageProvider()
194
- } else {
195
- this._screenshot = await this._normalizeImageFromCheckSettings(checkSettings)
196
-
197
- if (!this._viewportSizeHandler.get()) {
198
- await this.setViewportSize(this._screenshot.getSize())
199
- }
200
- }
201
-
202
- const matchResult = await super.checkWindowBase(
203
- regionProvider,
204
- name,
205
- checkSettings.getIgnoreMismatch(),
206
- checkSettings,
207
- )
208
- return matchResult.getAsExpected()
209
- } finally {
210
- this._title = undefined
211
- this._domString = undefined
212
- this._imageLocation = undefined
213
-
214
- this._screenshot = undefined
215
- this._screenshotUrl = undefined
216
- this._screenshotProvider = undefined
217
- }
218
- }
219
-
220
- async extractText(regions) {
221
- if (!TypeUtils.isArray(regions)) regions = [regions]
222
-
223
- const extractTextInputs = []
224
-
225
- for (const userRegion of regions) {
226
- const region = {...userRegion}
227
-
228
- const screenshot = await this._normalizeImage(region.image)
229
-
230
- if (!region.target) {
231
- region.target = {
232
- left: 0,
233
- top: 0,
234
- width: screenshot.getWidth(),
235
- height: screenshot.getHeight(),
236
- }
237
- }
238
-
239
- await this.getAndSaveRenderingInfo()
240
- const screenshotUrl = await this._serverConnector.uploadScreenshot(
241
- GeneralUtils.guid(),
242
- await screenshot.getImageBuffer(),
243
- )
244
- extractTextInputs.push({
245
- screenshotUrl,
246
- region: {...region.target, expected: region.hint},
247
- minMatch: region.minMatch,
248
- language: region.language,
249
- })
250
- }
251
-
252
- const results = await Promise.all(
253
- extractTextInputs.map(input => this._serverConnector.extractText(input)),
254
- )
255
-
256
- return results.reduce((strs, result) => strs.concat(result), [])
257
- }
258
-
259
- async extractTextRegions(config) {
260
- ArgumentGuard.notNull(config.patterns, 'patterns')
261
-
262
- const screenshot = await this._normalizeImage(config.image)
263
-
264
- await this.getAndSaveRenderingInfo()
265
- const screenshotUrl = await this._serverConnector.uploadScreenshot(
266
- GeneralUtils.guid(),
267
- await screenshot.getImageBuffer(),
268
- )
269
-
270
- return this._serverConnector.extractTextRegions({
271
- screenshotUrl,
272
- patterns: config.patterns,
273
- ignoreCase: config.ignoreCase,
274
- firstOnly: config.firstOnly,
275
- language: config.language,
276
- })
277
- }
278
-
279
- /**
280
- * @private
281
- * @param {ImagesCheckSettings} checkSettings - The settings to use when checking the image.
282
- * @return {Promise<MutableImage>}
283
- */
284
- async _normalizeImageFromCheckSettings(checkSettings) {
285
- if (checkSettings.getMutableImage()) {
286
- return checkSettings.getMutableImage()
287
- }
288
-
289
- if (checkSettings.getImageBuffer()) {
290
- return new MutableImage(checkSettings.getImageBuffer())
291
- }
292
-
293
- if (checkSettings.getImageString()) {
294
- return new MutableImage(checkSettings.getImageString())
295
- }
296
-
297
- if (checkSettings.getImagePath()) {
298
- try {
299
- const data = await FileUtils.readToBuffer(checkSettings.getImagePath())
300
- return new MutableImage(data)
301
- } catch (err) {
302
- throw new EyesError(`Can't read image [${err.message}]`)
303
- }
304
- }
305
-
306
- throw new EyesError("Can't recognize supported image from checkSettings.")
307
- }
308
-
309
- async _normalizeImage(image) {
310
- if (image instanceof MutableImage) {
311
- return image
312
- } else if (TypeUtils.isBuffer(image)) {
313
- return new MutableImage(image)
314
- } else if (TypeUtils.isBase64(image)) {
315
- return new MutableImage(image)
316
- } else if (TypeUtils.isString(image)) {
317
- try {
318
- const data = await FileUtils.readToBuffer(image)
319
- return new MutableImage(data)
320
- } catch (err) {
321
- throw new EyesError(`Can't read image [${err.message}]`)
322
- }
323
- }
324
-
325
- throw new EyesError("Can't recognize supported image from checkSettings.")
326
- }
327
-
328
- /**
329
- * Replaces the actual image in a running session.
330
- *
331
- * @param {number} stepIndex - The zero based index of the step in which to replace the image.
332
- * @param {string|Buffer|MutableImage} image - The image base64 string, image buffer or MutableImage.
333
- * @param {string} [tag] - A tag to be associated with the validation checkpoint.
334
- * @param {string} [title] - A title to be associated with the validation checkpoint.
335
- * @param {Trigger[]} [userInputs] - An array of user inputs to which lead to the validation checkpoint.
336
- * @return {Promise<boolean>} - True if the image matched the expected output, false otherwise.
337
- * @throws {DiffsFoundError} Thrown if a mismatch is detected and immediate failure reports are enabled.
338
- */
339
- async replaceImage(stepIndex, image, tag, title, userInputs) {
340
- ArgumentGuard.notNull(stepIndex, 'stepIndex')
341
- ArgumentGuard.notNull(image, 'image')
342
-
343
- if (this.getIsDisabled()) {
344
- this._logger.verbose(
345
- `replaceImage('${stepIndex}', Image, '${tag}', '${title}', '${userInputs}'): Ignored`,
346
- )
347
- return false
348
- }
349
-
350
- if (TypeUtils.isBuffer(image) || TypeUtils.isString(image)) {
351
- image = new MutableImage(image)
352
- }
353
-
354
- this._logger.verbose(
355
- `replaceImage('${stepIndex}', Image, '${tag}', '${title}', '${userInputs}')`,
356
- )
357
- const results = await super.replaceWindow(stepIndex, image, tag, title, userInputs)
358
- return results.getAsExpected()
359
- }
360
-
361
- /**
362
- * Adds a mouse trigger.
363
- *
364
- * @param {MouseTrigger.MouseAction} action Mouse action.
365
- * @param {Region} control - The control on which the trigger is activated (context relative coordinates).
366
- * @param {Location} cursor The cursor's position relative to the control.
367
- */
368
- addMouseTrigger(action, control, cursor) {
369
- super.addMouseTriggerBase(action, control, cursor)
370
- }
371
-
372
- /**
373
- * Adds a keyboard trigger.
374
- *
375
- * @param {Region} control - The control's context-relative region.
376
- * @param {string} text - The trigger's text.
377
- */
378
- addTextTrigger(control, text) {
379
- super.addTextTriggerBase(control, text)
380
- }
381
-
382
- /**
383
- * @inheritDoc
384
- */
385
- async getViewportSize() {
386
- return this._viewportSizeHandler.get()
387
- }
388
-
389
- /**
390
- * Set the viewport size.
391
- *
392
- * @param {RectangleSize|RectangleSizeObject} viewportSize - The required viewport size.
393
- * @return {Promise}
394
- */
395
- async setViewportSize(viewportSize) {
396
- ArgumentGuard.notNull(viewportSize, 'size')
397
-
398
- this._viewportSizeHandler.set(new RectangleSize(viewportSize))
399
- }
400
-
401
- /**
402
- * @inheritDoc
403
- */
404
- async getInferredEnvironment() {
405
- return this._inferred
406
- }
407
-
408
- /**
409
- * Sets the inferred environment for the test.
410
- *
411
- * @param {string} inferred - The inferred environment string.
412
- */
413
- setInferredEnvironment(inferred) {
414
- this._inferred = inferred
415
- }
416
-
417
- /**
418
- * @inheritDoc
419
- */
420
- async getScreenshot() {
421
- if (this._screenshotProvider) {
422
- const screenshot = await this._screenshotProvider.getImage()
423
- return new EyesSimpleScreenshot(screenshot.image || screenshot)
424
- }
425
-
426
- if (this._screenshot) {
427
- return new EyesSimpleScreenshot(this._screenshot)
428
- }
429
-
430
- return undefined
431
- }
432
-
433
- /**
434
- * @inheritDoc
435
- */
436
- async getScreenshotUrl() {
437
- return this._screenshotUrl
438
- }
439
-
440
- /**
441
- * @inheritDoc
442
- */
443
- async tryCaptureDom() {
444
- return this._domString
445
- }
446
-
447
- /**
448
- * @inheritDoc
449
- */
450
- async getImageLocation() {
451
- return this._imageLocation || Location.ZERO
452
- }
453
-
454
- /**
455
- * @inheritDoc
456
- */
457
- async getTitle() {
458
- return this._title
459
- }
460
-
461
- getAndSaveRenderingInfo() {
462
- return this._serverConnector.renderInfo()
463
- }
464
-
465
- async _getAndSaveBatchInfoFromServer(batchId) {
466
- ArgumentGuard.notNullOrEmpty(batchId, 'batchId')
467
- return this._getBatchInfo(batchId)
468
- }
469
- }
470
-
471
- exports.Eyes = Eyes