How to use withinAssertNumber method in Testcafe

Best JavaScript code snippet using testcafe

test-run-error-formatting-test.js

Source:test-run-error-formatting-test.js Github

copy

Full Screen

1const { assert, expect } = require('chai');2const { pull: remove, chain, values } = require('lodash');3const TestRun = require('../../lib/test-run');4const TEST_RUN_PHASE = require('../../lib/test-run/phase');5const { TEST_RUN_ERRORS, RUNTIME_ERRORS } = require('../../lib/errors/types');6const TestRunErrorFormattableAdapter = require('../../lib/errors/test-run/formattable-adapter');7const testCallsite = require('./data/test-callsite');8const assertTestRunError = require('./helpers/assert-test-run-error');9const {10 AssertionExecutableArgumentError,11 AssertionWithoutMethodCallError,12 AssertionUnawaitedPromiseError,13 ActionIntegerOptionError,14 ActionPositiveIntegerOptionError,15 ActionIntegerArgumentError,16 ActionPositiveIntegerArgumentError,17 ActionBooleanOptionError,18 ActionBooleanArgumentError,19 ActionSpeedOptionError,20 ActionSelectorError,21 ActionOptionsTypeError,22 ActionStringArgumentError,23 ActionNullableStringArgumentError,24 ActionStringOrStringArrayArgumentError,25 ActionStringArrayElementError,26 ActionFunctionArgumentError,27 PageLoadError,28 UncaughtErrorOnPage,29 UncaughtErrorInTestCode,30 UncaughtErrorInClientFunctionCode,31 UncaughtNonErrorObjectInTestCode,32 UncaughtErrorInCustomDOMPropertyCode,33 UnhandledPromiseRejectionError,34 UncaughtExceptionError,35 ActionElementNotFoundError,36 ActionElementIsInvisibleError,37 ActionSelectorMatchesWrongNodeTypeError,38 ActionAdditionalElementNotFoundError,39 ActionAdditionalElementIsInvisibleError,40 ActionAdditionalSelectorMatchesWrongNodeTypeError,41 ActionElementNonEditableError,42 ActionElementNonContentEditableError,43 ActionRootContainerNotFoundError,44 ActionElementNotTextAreaError,45 ActionIncorrectKeysError,46 ActionCannotFindFileToUploadError,47 ActionElementIsNotFileInputError,48 ActionUnsupportedDeviceTypeError,49 ActionInvalidScrollTargetError,50 ClientFunctionExecutionInterruptionError,51 ActionElementNotIframeError,52 ActionIframeIsNotLoadedError,53 CurrentIframeIsNotLoadedError,54 CurrentIframeNotFoundError,55 CurrentIframeIsInvisibleError,56 MissingAwaitError,57 ExternalAssertionLibraryError,58 DomNodeClientFunctionResultError,59 InvalidSelectorResultError,60 NativeDialogNotHandledError,61 UncaughtErrorInNativeDialogHandler,62 SetNativeDialogHandlerCodeWrongTypeError,63 CannotObtainInfoForElementSpecifiedBySelectorError,64 WindowDimensionsOverflowError,65 ForbiddenCharactersInScreenshotPathError,66 InvalidElementScreenshotDimensionsError,67 SetTestSpeedArgumentError,68 RoleSwitchInRoleInitializerError,69 ActionRoleArgumentError,70 RequestHookNotImplementedMethodError,71 RequestHookUnhandledError,72 UncaughtErrorInCustomClientScriptCode,73 UncaughtErrorInCustomClientScriptLoadedFromModule,74 UncaughtErrorInCustomScript,75 UncaughtTestCafeErrorInCustomScript,76 ChildWindowIsNotLoadedError,77 ChildWindowNotFoundError,78 CannotSwitchToWindowError,79 CloseChildWindowError,80 ChildWindowClosedBeforeSwitchingError,81 WindowNotFoundError,82 ParentWindowNotFoundError,83 PreviousWindowNotFoundError,84 SwitchToWindowPredicateError,85 CannotCloseWindowWithChildrenError,86 MultipleWindowsModeIsDisabledError,87 CannotCloseWindowWithoutParentError,88 MultipleWindowsModeIsNotAvailableInRemoteBrowserError,89 CannotRestoreChildWindowError,90 TimeoutError,91 ActionCookieArgumentError,92 ActionCookieArgumentsError,93 ActionUrlCookieArgumentError,94 ActionUrlsCookieArgumentError,95 ActionRequiredCookieArguments,96 ActionStringOptionError,97 ActionDateOptionError,98 ActionNumberOptionError,99} = require('../../lib/errors/test-run');100const untestedErrorTypes = Object.keys(TEST_RUN_ERRORS).map(key => TEST_RUN_ERRORS[key]);101const userAgentMock = 'Chrome 15.0.874.120 / macOS 10.15';102function equalAssertArray () {103 expect([1, 2, 3, [4, 5], 6]).eql([1, 4, 2, 3, [5, 6, [7]]]);104}105function equalAssertBoolean () {106 expect(true).eql(false);107}108function equalAssertBuffer () {109 expect(Buffer.from('test')).eql(Buffer.from([1, 2, 3]));110}111function equalAssertEmptyString () {112 expect([]).eql('');113}114function equalAssertFunction () {115 expect(function () {116 return true;117 }).eql(function () {118 return false;119 });120}121function equalAssertNumber () {122 expect(1).eql(2);123}124function equalAssertObject () {125 const obj1 = {126 first: {127 second: {128 third: {129 fourth: {130 fifth: {131 hello: 'world',132 six: '6',133 },134 },135 },136 },137 },138 };139 const obj2 = {140 first: {141 second: {142 third: {143 fourth: {144 fifth: {145 hello: 'world',146 },147 },148 },149 },150 },151 };152 expect(obj1).eql(obj2);153}154function equalAssertString () {155 expect('line1\nline2').eql('line1');156}157function equalAssertUndefinedNull () {158 expect(void 0).eql(null);159}160function notEqualAssertString () {161 assert.notEqual('foo', 'foo');162}163function okAssertBoolean () {164 expect(false).ok;165}166function notOkAssertBoolean () {167 expect(true).not.ok;168}169function containsAssertString () {170 expect('foo').contains('bar');171}172function notContainsAssertString () {173 expect('foobar').not.contains('bar');174}175function matchAssertRegExp () {176 expect('some text').match(/some regexp/);177}178function notMatchAssertRegExp () {179 expect('some text').not.match(/some \w+/);180}181function typeOfAssertNull () {182 assert.typeOf(false, 'null');183}184function notTypeOfAssertNull () {185 assert.notTypeOf(null, 'null');186}187function withinAssertNumber () {188 expect(0).within(1, 2);189}190function notWithinAssertNumber () {191 expect(0).not.within(0, 1);192}193function ltAssertNumber () {194 expect(1).lt(0);195}196function lteAssertNumber () {197 expect(1).lte(0);198}199function gtAssertNumber () {200 expect(0).gt(1);201}202function gteAssertNumber () {203 expect(0).gte(1);204}205const createAssertionError = fn => {206 try {207 fn();208 }209 catch (err) {210 return err;211 }212 return null;213};214const ASSERT_ERRORS = {215 equal: {216 array: createAssertionError(equalAssertArray),217 boolean: createAssertionError(equalAssertBoolean),218 buffer: createAssertionError(equalAssertBuffer),219 emptyString: createAssertionError(equalAssertEmptyString),220 function: createAssertionError(equalAssertFunction),221 number: createAssertionError(equalAssertNumber),222 object: createAssertionError(equalAssertObject),223 string: createAssertionError(equalAssertString),224 undefinedNull: createAssertionError(equalAssertUndefinedNull),225 },226 notEqual: { string: createAssertionError(notEqualAssertString) },227 ok: { boolean: createAssertionError(okAssertBoolean) },228 notOk: { boolean: createAssertionError(notOkAssertBoolean) },229 contains: { string: createAssertionError(containsAssertString) },230 notContains: { string: createAssertionError(notContainsAssertString) },231 match: { regexp: createAssertionError(matchAssertRegExp) },232 notMatch: { regexp: createAssertionError(notMatchAssertRegExp) },233 typeOf: { null: createAssertionError(typeOfAssertNull) },234 notTypeOf: { null: createAssertionError(notTypeOfAssertNull) },235 within: { number: createAssertionError(withinAssertNumber) },236 notWithin: { number: createAssertionError(notWithinAssertNumber) },237 lt: { number: createAssertionError(ltAssertNumber) },238 lte: { number: createAssertionError(lteAssertNumber) },239 gt: { number: createAssertionError(gtAssertNumber) },240 gte: { number: createAssertionError(gteAssertNumber) },241};242const longSelector = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua';243function getErrorAdapter (err) {244 const screenshotPath = '/unix/path/with/<tag>';245 return new TestRunErrorFormattableAdapter(err, {246 userAgent: userAgentMock,247 screenshotPath: screenshotPath,248 callsite: testCallsite,249 testRunPhase: TEST_RUN_PHASE.initial,250 });251}252function assertErrorMessage (file, err) {253 assertTestRunError(err, '../data/expected-test-run-errors/' + file);254 // NOTE: check that the list of error types contains an255 // error of this type and remove tested messages from the list256 expect(untestedErrorTypes.includes(err.code)).to.be.ok;257 remove(untestedErrorTypes, err.code);258}259describe('Error formatting', () => {260 describe('Errors', () => {261 it('Base error formattable adapter properties', () => {262 const testRunMock = TestRun.prototype;263 testRunMock._ensureErrorId = err => {264 err.id = 'error-id';265 };266 Object.assign(testRunMock, {267 session: { id: 'test-run-id' },268 browserConnection: { userAgent: 'chrome' },269 errScreenshotPath: 'screenshot-path',270 phase: 'test-run-phase',271 callsite: 'callsite',272 errs: [],273 });274 TestRun.prototype.addError.call(testRunMock, { callsite: 'callsite' });275 const err = testRunMock.errs[0];276 expect(err).instanceOf(TestRunErrorFormattableAdapter);277 expect(err).eql({278 userAgent: 'chrome',279 screenshotPath: 'screenshot-path',280 testRunId: 'test-run-id',281 testRunPhase: 'test-run-phase',282 callsite: 'callsite',283 id: 'error-id',284 });285 });286 it('Should not throw if the specified decorator was not found', () => {287 expect(() => {288 const error = new ExternalAssertionLibraryError(createAssertionError(equalAssertArray), testCallsite);289 error.diff = '<div class="unknown-decorator">text</div>';290 getErrorAdapter(error).formatMessage('', 100);291 }).to.not.throw();292 });293 it('Should format "actionIntegerOptionError" message', () => {294 assertErrorMessage('action-integer-option-error', new ActionIntegerOptionError('offsetX', '1.01'));295 });296 it('Should format "actionPositiveIntegerOptionError" message', () => {297 assertErrorMessage('action-positive-integer-option-error', new ActionPositiveIntegerOptionError('caretPos', '-1'));298 });299 it('Should format "actionIntegerArgumentError" message', () => {300 assertErrorMessage('action-integer-argument-error', new ActionIntegerArgumentError('dragOffsetX', 'NaN'));301 });302 it('Should format "actionPositiveIntegerArgumentError" message', () => {303 assertErrorMessage('action-positive-integer-argument-error', new ActionPositiveIntegerArgumentError('startPos', '-1'));304 });305 it('Should format "actionBooleanOptionError" message', () => {306 assertErrorMessage('action-boolean-option-error', new ActionBooleanOptionError('modifier.ctrl', 'object'));307 });308 it('Should format the "actionBooleanArgumentError" message', () => {309 assertErrorMessage('action-boolean-argument-error', new ActionBooleanArgumentError('isAsyncExpression', 'object'));310 });311 it('Should format "actionSpeedOptionError" message', () => {312 assertErrorMessage('action-speed-option-error', new ActionSpeedOptionError('speed', 'object'));313 });314 it('Should format "pageLoadError" message', () => {315 assertErrorMessage('page-load-error', new PageLoadError('Failed to find a DNS-record for the resource', 'http://some-url.example.com'));316 });317 it('Should format "uncaughtErrorOnPage" message (with error stack)', () => {318 const errStack = [319 'Test error:',320 ' at method3 (http://example.com):1:3',321 ' at method2 (http://example.com):1:2',322 ' at method1 (http://example.com):1:1',323 ].join('\n');324 assertErrorMessage('uncaught-js-error-on-page', new UncaughtErrorOnPage(errStack, 'http://example.org'));325 });326 it('Should format "uncaughtErrorInTestCode" message', () => {327 assertErrorMessage('uncaught-js-error-in-test-code', new UncaughtErrorInTestCode(new Error('Custom script error'), testCallsite));328 });329 it('Should format "uncaughtNonErrorObjectInTestCode" message', () => {330 assertErrorMessage('uncaught-non-error-object-in-test-code', new UncaughtNonErrorObjectInTestCode('Hey ya!'));331 });332 it('Should format "uncaughtErrorInAddCustomDOMProperties" message', () => {333 assertErrorMessage('uncaught-error-in-add-custom-dom-properties-code', new UncaughtErrorInCustomDOMPropertyCode(testCallsite, new Error('Custom script error'), 'prop'));334 });335 it('Should format "unhandledPromiseRejectionError" message', () => {336 assertErrorMessage('unhandled-promise-rejection-error', new UnhandledPromiseRejectionError('Hey ya!'));337 });338 it('Should format "uncaughtExceptionError" message', () => {339 assertErrorMessage('uncaught-exception-error', new UncaughtExceptionError('Hey ya!'));340 });341 it('Should format "actionElementNotFoundError" message', () => {342 assertErrorMessage('action-element-not-found-error', new ActionElementNotFoundError(null, {343 apiFnChain: [longSelector, 'one', 'two', 'three'],344 apiFnIndex: 1,345 }));346 });347 it('Should format "actionElementIsInvisibleError" message', () => {348 assertErrorMessage('action-element-is-invisible-error', new ActionElementIsInvisibleError());349 });350 it('Should format "actionSelectorMatchesWrongNodeTypeError" message', () => {351 assertErrorMessage('action-selector-matches-wrong-node-type-error', new ActionSelectorMatchesWrongNodeTypeError('text'));352 });353 it('Should format "actionElementNonEditableError" message', () => {354 assertErrorMessage('action-element-non-editable-error', new ActionElementNonEditableError());355 });356 it('Should format "actionRootContainerNotFoundError" message', () => {357 assertErrorMessage('action-root-container-not-found-error', new ActionRootContainerNotFoundError());358 });359 it('Should format "actionElementNonContentEditableError" message', () => {360 assertErrorMessage('action-element-non-content-editable-error', new ActionElementNonContentEditableError('startSelector'));361 });362 it('Should format "actionElementNotTextAreaError" message', () => {363 assertErrorMessage('action-element-not-text-area-error', new ActionElementNotTextAreaError());364 });365 it('Should format "actionElementNotIframeError" message', () => {366 assertErrorMessage('action-element-not-iframe-error', new ActionElementNotIframeError());367 });368 it('Should format "actionSelectorError" message', () => {369 assertErrorMessage('action-selector-error', new ActionSelectorError('selector', { rawMessage: 'Yo!' }, true));370 });371 it('Should format "actionOptionsTypeError" message', () => {372 assertErrorMessage('action-options-type-error', new ActionOptionsTypeError(typeof 1));373 });374 it('Should format "actionAdditionalElementNotFoundError" message', () => {375 assertErrorMessage('action-additional-element-not-found-error', new ActionAdditionalElementNotFoundError('startSelector', {376 apiFnChain: [longSelector, 'one', 'two', 'three'],377 apiFnIndex: 1,378 }));379 });380 it('Should format "actionAdditionalElementIsInvisibleError" message', () => {381 assertErrorMessage('action-additional-element-is-invisible-error', new ActionAdditionalElementIsInvisibleError('startSelector'));382 });383 it('Should format "actionAdditionalSelectorMatchesWrongNodeTypeError" message', () => {384 assertErrorMessage('action-additional-selector-matches-wrong-node-type-error', new ActionAdditionalSelectorMatchesWrongNodeTypeError('startSelector', 'text'));385 });386 it('Should format "actionStringArgumentError" message', () => {387 assertErrorMessage('action-string-argument-error', new ActionStringArgumentError('text', typeof 1));388 });389 it('Should format "actionNullableStringArgumentError" message', () => {390 assertErrorMessage('action-nullable-string-argument-error', new ActionNullableStringArgumentError('text', typeof 1));391 });392 it('Should format "actionIncorrectKeysError" message', () => {393 assertErrorMessage('action-incorrect-keys-error', new ActionIncorrectKeysError('keys'));394 });395 it('Should format "actionNonEmptyStringArrayArgumentError" message', () => {396 assertErrorMessage('action-non-empty-string-array-argument-error', new ActionStringOrStringArrayArgumentError('array', null));397 });398 it('Should format "actionStringArrayElementError" message', () => {399 assertErrorMessage('action-string-array-element-error', new ActionStringArrayElementError('array', 'number', 1));400 });401 it('Should format "actionElementIsNotFileInputError" message', () => {402 assertErrorMessage('action-element-is-not-file-input-error', new ActionElementIsNotFileInputError());403 });404 it('Should format "actionCannotFindFileToUploadError" message', () => {405 const filePaths = ['/path/1', '/path/2'];406 const scannedFilepaths = ['full-path-to/path/1', 'full-path-to/path/2'];407 const err = new ActionCannotFindFileToUploadError(filePaths, scannedFilepaths);408 assertErrorMessage('action-cannot-find-file-to-upload-error', err);409 });410 it('Should format "actionUnsupportedDeviceTypeError" message', () => {411 assertErrorMessage('action-unsupported-device-type-error', new ActionUnsupportedDeviceTypeError('device', 'iPhone 555'));412 });413 it('Should format "actionInvalidScrollTargetError" message', () => {414 assertErrorMessage('action-invalid-scroll-target-error', new ActionInvalidScrollTargetError(false, true));415 });416 it('Should format "actionIframeIsNotLoadedError" message', () => {417 assertErrorMessage('action-iframe-is-not-loaded-error', new ActionIframeIsNotLoadedError());418 });419 it('Should format "currentIframeIsNotLoadedError" message', () => {420 assertErrorMessage('current-iframe-is-not-loaded-error', new CurrentIframeIsNotLoadedError());421 });422 it('Should format "currentIframeNotFoundError" message', () => {423 assertErrorMessage('current-iframe-not-found-error', new CurrentIframeNotFoundError());424 });425 it('Should format "currentIframeIsInvisibleError" message', () => {426 assertErrorMessage('current-iframe-is-invisible-error', new CurrentIframeIsInvisibleError());427 });428 it('Should format "missingAwaitError"', () => {429 assertErrorMessage('missing-await-error', new MissingAwaitError(testCallsite));430 });431 describe('Should format "externalAssertionLibraryError"', () => {432 const filepath = function (assertion, filename) {433 return `../data/expected-test-run-errors/external-assertion-library-errors/builtin/${assertion}/${filename}`;434 };435 it('Deep Equal', () => {436 assertTestRunError(new ExternalAssertionLibraryError(ASSERT_ERRORS.equal.array, testCallsite), filepath('equal', 'array'));437 assertTestRunError(new ExternalAssertionLibraryError(ASSERT_ERRORS.equal.boolean, testCallsite), filepath('equal', 'boolean'));438 assertTestRunError(new ExternalAssertionLibraryError(ASSERT_ERRORS.equal.buffer, testCallsite), filepath('equal', 'buffer'));439 assertTestRunError(new ExternalAssertionLibraryError(ASSERT_ERRORS.equal.emptyString, testCallsite), filepath('equal', 'empty-string'));440 assertTestRunError(new ExternalAssertionLibraryError(ASSERT_ERRORS.equal.function, testCallsite), filepath('equal', 'function'));441 assertTestRunError(new ExternalAssertionLibraryError(ASSERT_ERRORS.equal.number, testCallsite), filepath('equal', 'number'));442 assertTestRunError(new ExternalAssertionLibraryError(ASSERT_ERRORS.equal.object, testCallsite), filepath('equal', 'object'));443 assertTestRunError(new ExternalAssertionLibraryError(ASSERT_ERRORS.equal.string, testCallsite), filepath('equal', 'string'));444 assertErrorMessage('external-assertion-library-errors/builtin/equal/undefined-null', new ExternalAssertionLibraryError(ASSERT_ERRORS.equal.undefinedNull, testCallsite));445 });446 it('Not Deep Equal', () => {447 assertTestRunError(new ExternalAssertionLibraryError(ASSERT_ERRORS.notEqual.string, testCallsite), filepath('not-equal', 'string'));448 });449 it('Ok', () => {450 assertTestRunError(new ExternalAssertionLibraryError(ASSERT_ERRORS.ok.boolean, testCallsite), filepath('ok', 'boolean'));451 });452 it('Not Ok', () => {453 assertTestRunError(new ExternalAssertionLibraryError(ASSERT_ERRORS.notOk.boolean, testCallsite), filepath('not-ok', 'boolean'));454 });455 it('Contains', () => {456 assertTestRunError(new ExternalAssertionLibraryError(ASSERT_ERRORS.contains.string, testCallsite), filepath('contains', 'string'));457 });458 it('Not Contains', () => {459 assertTestRunError(new ExternalAssertionLibraryError(ASSERT_ERRORS.notContains.string, testCallsite), filepath('not-contains', 'string'));460 });461 it('Match', () => {462 assertTestRunError(new ExternalAssertionLibraryError(ASSERT_ERRORS.match.regexp, testCallsite), filepath('match', 'regexp'));463 });464 it('Not Match', () => {465 assertTestRunError(new ExternalAssertionLibraryError(ASSERT_ERRORS.notMatch.regexp, testCallsite), filepath('not-match', 'regexp'));466 });467 it('Type of', () => {468 assertTestRunError(new ExternalAssertionLibraryError(ASSERT_ERRORS.typeOf.null, testCallsite), filepath('type-of', 'null'));469 });470 it('Not Type of', () => {471 assertTestRunError(new ExternalAssertionLibraryError(ASSERT_ERRORS.notTypeOf.null, testCallsite), filepath('not-type-of', 'null'));472 });473 it('Within', () => {474 assertTestRunError(new ExternalAssertionLibraryError(ASSERT_ERRORS.within.number, testCallsite), filepath('within', 'number'));475 });476 it('Not Within', () => {477 assertTestRunError(new ExternalAssertionLibraryError(ASSERT_ERRORS.notWithin.number, testCallsite), filepath('not-within', 'number'));478 });479 it('Less than', () => {480 assertTestRunError(new ExternalAssertionLibraryError(ASSERT_ERRORS.lt.number, testCallsite), filepath('less-than', 'number'));481 });482 it('Less than or Equal to', () => {483 assertTestRunError(new ExternalAssertionLibraryError(ASSERT_ERRORS.lte.number, testCallsite), filepath('less-than-or-equal', 'number'));484 });485 it('Greater than', () => {486 assertTestRunError(new ExternalAssertionLibraryError(ASSERT_ERRORS.gt.number, testCallsite), filepath('greater-than', 'number'));487 });488 it('Greater than or Equal to', () => {489 assertTestRunError(new ExternalAssertionLibraryError(ASSERT_ERRORS.gte.number, testCallsite), filepath('greater-than-or-equal', 'number'));490 });491 });492 it('Should format "uncaughtErrorInClientFunctionCode"', () => {493 assertErrorMessage('uncaught-error-in-client-function-code', new UncaughtErrorInClientFunctionCode('Selector', new Error('Some error.')));494 });495 it('Should format "clientFunctionExecutionInterruptionError"', () => {496 assertErrorMessage('client-function-execution-interruption-error', new ClientFunctionExecutionInterruptionError('eval'));497 });498 it('Should format "domNodeClientFunctionResultError"', () => {499 assertErrorMessage('dom-node-client-function-result-error', new DomNodeClientFunctionResultError('ClientFunction'));500 });501 it('Should format "invalidSelectorResultError"', () => {502 assertErrorMessage('invalid-selector-result-error', new InvalidSelectorResultError());503 });504 it('Should format "nativeDialogNotHandledError"', () => {505 assertErrorMessage('native-dialog-not-handled-error', new NativeDialogNotHandledError('alert', 'http://example.org'));506 });507 it('Should format "uncaughtErrorInNativeDialogHandler"', () => {508 assertErrorMessage('uncaught-error-in-native-dialog-handler', new UncaughtErrorInNativeDialogHandler('alert', 'error message', 'http://example.org'));509 });510 it('Should format "setNativeDialogHandlerCodeWrongTypeError"', () => {511 assertErrorMessage('set-native-dialog-handler-code-wrong-type-error', new SetNativeDialogHandlerCodeWrongTypeError('number'));512 });513 it('Should format "cannotObtainInfoForElementSpecifiedBySelectorError"', () => {514 assertErrorMessage('cannot-obtain-info-for-element-specified-by-selector-error', new CannotObtainInfoForElementSpecifiedBySelectorError(testCallsite, {515 apiFnChain: [longSelector, 'one', 'two', 'three'],516 apiFnIndex: 1,517 }));518 });519 it('Should format "windowDimensionsOverflowError"', () => {520 assertErrorMessage('window-dimensions-overflow-error', new WindowDimensionsOverflowError());521 });522 it('Should format "forbiddenCharactersInScreenshotPathError"', () => {523 assertErrorMessage('forbidden-characters-in-screenshot-path-error', new ForbiddenCharactersInScreenshotPathError('/root/bla:bla', [{524 chars: ':',525 index: 9,526 }]));527 });528 it('Should format "invalidElementScreenshotDimensionsError"', () => {529 assertErrorMessage('invalid-element-screenshot-dimensions-error', new InvalidElementScreenshotDimensionsError(0, 10));530 });531 it('Should format "setTestSpeedArgumentError"', () => {532 assertErrorMessage('set-test-speed-argument-error', new SetTestSpeedArgumentError('speed', 'string'));533 });534 it('Should format "roleSwitchInRoleInitializerError"', () => {535 assertErrorMessage('role-switch-in-role-initializer-error', new RoleSwitchInRoleInitializerError(testCallsite));536 });537 it('Should format "actionRoleArgumentError"', () => {538 assertErrorMessage('action-role-argument-error', new ActionRoleArgumentError('role', 'number'));539 });540 it('Should format "assertionExecutableArgumentError"', () => {541 assertErrorMessage('assertion-executable-argument-error', new AssertionExecutableArgumentError('actual', '1 + temp', { rawMessage: 'Unexpected identifier' }, true));542 });543 it('Should format "assertionWithoutMethodCallError"', () => {544 assertErrorMessage('assertion-without-method-call-error', new AssertionWithoutMethodCallError(testCallsite));545 });546 it('Should format "assertionUnawaitedPromiseError"', () => {547 assertErrorMessage('assertion-unawaited-promise-error', new AssertionUnawaitedPromiseError(testCallsite));548 });549 it('Should format "requestHookNotImplementedError"', () => {550 assertErrorMessage('request-hook-method-not-implemented-error', new RequestHookNotImplementedMethodError('onRequest', 'MyHook'));551 });552 it('Should format "requestHookUnhandledError"', () => {553 assertErrorMessage('request-hook-unhandled-error', new RequestHookUnhandledError(new Error('Test error'), 'MyHook', 'onRequest'));554 });555 it('Should format "uncaughtErrorInCustomClientScriptCode"', () => {556 assertErrorMessage('uncaught-error-in-custom-client-script-code', new UncaughtErrorInCustomClientScriptCode(new TypeError('Cannot read property "prop" of undefined')));557 });558 it('Should format "uncaughtErrorInCustomClientScriptCodeLoadedFromModule"', () => {559 assertErrorMessage('uncaught-error-in-custom-client-script-code-loaded-from-module', new UncaughtErrorInCustomClientScriptLoadedFromModule(new TypeError('Cannot read property "prop" of undefined'), 'test-module'));560 });561 it('Should format "uncaughtErrorInCustomScript"', () => {562 assertErrorMessage('uncaught-error-in-custom-script', new UncaughtErrorInCustomScript(new Error('Test error'), '1+1', 1, 1, 'RAW API callsite'));563 });564 it('Should format "uncaughtTestCafeErrorInCustomScript"', () => {565 const expression = 'Hey ya!';566 const originError = getErrorAdapter(new UncaughtNonErrorObjectInTestCode(expression));567 assertErrorMessage('uncaught-test-cafe-error-in-custom-script', new UncaughtTestCafeErrorInCustomScript(originError, expression, void 0, void 0, 'RAW API callsite'));568 });569 it('Should format "childWindowIsNotLoadedError"', () => {570 assertErrorMessage('child-window-is-not-loaded-error', new ChildWindowIsNotLoadedError());571 });572 it('Should format "childWindowNotFoundError"', () => {573 assertErrorMessage('child-window-not-found-error', new ChildWindowNotFoundError());574 });575 it('Should format "cannotSwitchToWindowError"', () => {576 assertErrorMessage('cannot-switch-to-child-window-error', new CannotSwitchToWindowError());577 });578 it('Should format "closeChildWindowError"', () => {579 assertErrorMessage('close-child-window-error', new CloseChildWindowError());580 });581 it('Should format "childWindowClosedBeforeSwitchingError"', () => {582 assertErrorMessage('child-window-closed-before-switching-error', new ChildWindowClosedBeforeSwitchingError());583 });584 it('Should format "cannotCloseWindowWithChildrenError"', () => {585 assertErrorMessage('cannot-close-window-with-children-error', new CannotCloseWindowWithChildrenError());586 });587 it('Should format "cannotCloseWindowWithoutParentError"', () => {588 assertErrorMessage('cannot-close-window-without-parent-error', new CannotCloseWindowWithoutParentError());589 });590 it('Should format "windowNotFoundError"', () => {591 assertErrorMessage('window-not-found-error', new WindowNotFoundError());592 });593 it('Should format "parentWindowNotFoundError"', () => {594 assertErrorMessage('parent-window-not-found-error', new ParentWindowNotFoundError());595 });596 it('Should format "previousWindowNotFoundError"', () => {597 assertErrorMessage('previous-window-not-found-error', new PreviousWindowNotFoundError());598 });599 it('Should format "switchToWindowPredicateError"', () => {600 assertErrorMessage('switch-to-window-predicate-error', new SwitchToWindowPredicateError('error message'));601 });602 it('Should format "actionFunctionArgumentError"', () => {603 assertErrorMessage('action-function-argument-error', new ActionFunctionArgumentError('predicate', 'number'));604 });605 it('Should format "multipleWindowsModeIsDisabledError"', () => {606 assertErrorMessage('multiple-windows-mode-is-disabled-error', new MultipleWindowsModeIsDisabledError('openWindow'));607 });608 it('Should format "multipleWindowsModeIsNotSupportedInRemoteBrowserError"', () => {609 assertErrorMessage('multiple-windows-mode-is-not-available-in-remote-browser-error', new MultipleWindowsModeIsNotAvailableInRemoteBrowserError('openWindow'));610 });611 it('Should format "cannotRestoreChildWindowError"', () => {612 assertErrorMessage('cannot-restore-child-window-error', new CannotRestoreChildWindowError());613 });614 it('Should format "executionTimeoutExceeded"', () => {615 assertErrorMessage('execution-timeout-exceeded', new TimeoutError(500, 'Scope'));616 });617 it('Should format "actionCookieArgumentError"', () => {618 assertErrorMessage('action-cookie-argument-error', new ActionCookieArgumentError());619 });620 it('Should format "actionCookieArgumentsError"', () => {621 assertErrorMessage('action-cookie-arguments-error', new ActionCookieArgumentsError(0));622 });623 it('Should format "ActionUrlCookieArgumentError"', () => {624 assertErrorMessage('action-url-cookie-argument-error', new ActionUrlCookieArgumentError());625 });626 it('Should format "ActionUrlsCookieArgumentError"', () => {627 assertErrorMessage('action-urls-cookie-argument-error', new ActionUrlsCookieArgumentError(0));628 });629 it('Should format "actionRequiredSetCookieArgumentsAreMissedError"', () => {630 assertErrorMessage('action-required-cookie-arguments', new ActionRequiredCookieArguments());631 });632 it('Should format "actionStringOptionError"', () => {633 assertErrorMessage('action-string-option-error', new ActionStringOptionError('name', 'object'));634 });635 it('Should format "actionExpiresOptionError"', () => {636 assertErrorMessage('action-date-option-error', new ActionDateOptionError('expires', 'string'));637 });638 it('Should format "actionNumberOptionError"', () => {639 assertErrorMessage('action-number-option-error', new ActionNumberOptionError('maxAge', 'object'));640 });641 });642 describe('Test coverage', () => {643 it('Should test messages for all error codes', () => {644 expect(untestedErrorTypes).to.be.empty;645 });646 it('Errors codes should be unique', () => {647 function getDuplicates (codes) {648 return chain(codes).groupBy().pickBy(x => x.length > 1).keys().value();649 }650 const testRunErrorCodes = values(TEST_RUN_ERRORS);651 const runtimeErrorCodes = values(RUNTIME_ERRORS);652 const testRunErrorCodeDuplicates = getDuplicates(testRunErrorCodes);653 const runtimeErrorCodeDuplicates = getDuplicates(runtimeErrorCodes);654 const testRunAndRuntimeErrorCodeDuplicates = getDuplicates(testRunErrorCodes.concat(runtimeErrorCodes));655 expect(testRunErrorCodeDuplicates, 'TestRunErrorCode duplicates').to.be.empty;656 expect(runtimeErrorCodeDuplicates, 'RuntimeErrorCode duplicates').to.be.empty;657 expect(testRunAndRuntimeErrorCodeDuplicates, 'Intersections between TestRunErrorCodes and RuntimeErrorCodes').to.be.empty;658 });659 });...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1import { Selector } from 'testcafe';2test('My first test', async t => {3 .typeText('#developer-name', 'John Smith')4 .click('#submit-button')5 .expect(Selector('#article-header').innerText).eql('Thank you, John Smith!');6});7await t.expect(Selector('#article-header').within(assertNumber).innerText).eql('Thank you, John Smith!');

Full Screen

Using AI Code Generation

copy

Full Screen

1import { Selector } from 'testcafe';2test('My first test', async t => {3 .expect(Selector('#developer-name').value).eql('', 'input is empty')4 .typeText('#developer-name', 'Peter')5 .expect(Selector('#developer-name').value).eql('Peter', 'input has Peter value');6});7test('My second test', async t => {8 .expect(Selector('#developer-name').value).withinAssertNumber(5)9 .typeText('#developer-name', 'Peter')10 .expect(Selector('#developer-name').value).withinAssertNumber(10);11});12test('My third test', async t => {13 .expect(Selector('#developer-name').value).withinAssertNumber(5, 10)14 .typeText('#developer-name', 'Peter')15 .expect(Selector('#developer-name').value).withinAssertNumber(5, 10);16});17test('My fourth test', async t => {18 .expect(Selector('#developer-name').value).withinAssertNumber(5, 10, { message: 'This is a custom message'})19 .typeText('#developer-name', 'Peter')20 .expect(Selector('#developer-name').value).withinAssertNumber(5, 10, { message: 'This is a custom message'});21});22test('My fifth test', async t => {23 .expect(Selector('#developer-name').value).withinAssertNumber(5, 10, { message: 'This is a custom message'})24 .typeText('#developer-name', 'Peter')25 .expect(Selector('#developer-name').value).withinAssertNumber(5, 10, { message: 'This is a custom message'});26});27test('My sixth test', async t => {28 .expect(Selector('#developer-name').value).withinAssertNumber(5, 10, { message: '

Full Screen

Using AI Code Generation

copy

Full Screen

1import { Selector } from 'testcafe';2test('My first test', async t => {3 .expect(Selector('#article-header').innerText).eql('Thank you, John Smith!');4});5import { Selector } from 'testcafe';6test('My first test', async t => {7 .expect(Selector('#article-header').innerText).eql('Thank you, John Smith!');8});9import { Selector } from 'testcafe';10test('My first test', async t => {11 .expect(Selector('#article-header').innerText).eql('Thank you, John Smith!');12});13import { Selector } from 'testcafe';14test('My first test', async t => {15 .expect(Selector('#article-header').innerText).eql('Thank you, John Smith!');16});17import { Selector } from 'testcafe';18test('My first test', async t => {19 .expect(Selector('#article-header').innerText).eql('Thank you, John Smith!');20});21import { Selector } from 'testcafe';

Full Screen

Using AI Code Generation

copy

Full Screen

1import { Selector } from 'testcafe';2test('My test', async t => {3 .typeText('#developer-name', 'John Smith')4 .click('#macos')5 .click('#submit-button');6 const articleHeader = await Selector('.result-content').find('h1');7 let headerText = await articleHeader.innerText;8 let innerHTML = await articleHeader.innerHTML;9});10import { Selector } from 'testcafe';11test('My test', async t => {12 .typeText('#developer-name', 'John Smith')13 .click('#macos')14 .click('#submit-button');15 const articleHeader = await Selector('.result-content').find('h1');16 let headerText = await articleHeader.innerText;17 let innerHTML = await articleHeader.innerHTML;18});19import { Selector } from 'testcafe';20test('My test', async t => {21 .typeText('#developer-name', 'John Smith')22 .click('#mac

Full Screen

Using AI Code Generation

copy

Full Screen

1import { Selector } from 'testcafe';2test('My test', async t => {3 const developerNameInput = Selector('#developer-name');4 .typeText(developerNameInput, 'Peter')5 .click('#tried-test-cafe')6 .click('#submit-button');7});8import { Selector } from 'testcafe';9test('My test', async t => {10 const developerNameInput = Selector('#developer-name');11 .typeText(developerNameInput, 'Peter')12 .click('#tried-test-cafe')13 .click('#submit-button');14});15import { Selector } from 'testcafe';16test('My test', async t => {17 const developerNameInput = Selector('#developer-name');18 .typeText(developerNameInput, 'Peter')19 .click('#tried-test-cafe')20 .click('#submit-button');21});22import { Selector } from 'testcafe';23test('My test', async t => {24 const developerNameInput = Selector('#developer-name');25 .typeText(developerNameInput, 'Peter')26 .click('#tried-test-cafe')27 .click('#submit-button');28});29import { Selector } from 'testcafe';30test('My test', async t => {31 const developerNameInput = Selector('#developer-name');32 .typeText(developerNameInput, 'Peter')33 .click('#tried-test-cafe')34 .click('#submit-button');35});36import { Selector } from 'testca

Full Screen

Using AI Code Generation

copy

Full Screen

1import { Selector } from 'testcafe';2test('My first test', async t => {3 .typeText('#developer-name', 'John Smith')4 .click('#submit-button');5 await t.expect(Selector('#article-header').innerText).eql('Thank you, John Smith!');6});7import { Selector } from 'testcafe';8test('My first test', async t => {9 .typeText('#developer-name', 'John Smith')10 .click('#submit-button');11 await t.expect(Selector('#article-header').innerText).eql('Thank you, John Smith!');12});13import { Selector } from 'testcafe';14test('My first test', async t => {15 .typeText('#developer-name', 'John Smith')16 .click('#submit-button');17 await t.expect(Selector('#article-header').innerText).eql('Thank you, John Smith!');18});19import { Selector } from 'testcafe';20test('My first test', async t => {21 .typeText('#developer-name', 'John Smith')22 .click('#submit-button');23 await t.expect(Selector('#article-header').innerText).eql('Thank you, John Smith!');24});25import { Selector } from '

Full Screen

Using AI Code Generation

copy

Full Screen

1import { ClientFunction } from 'testcafe';2test('My first test', async t => {3});4const withinAssertNumber = ClientFunction(() => {5 return 3;6});7test('within Assert Number', async t => {8 await t.expect(withinAssertNumber()).within(1, 5);9});10const withinAssertString = ClientFunction(() => {11 return 'This is a string';12});13test('within Assert String', async t => {14 await t.expect(withinAssertString()).within('This is a string', 'This is a string');15});16const withinAssertArray = ClientFunction(() => {17 return [1, 2, 3, 4, 5];18});19test('within Assert Array', async t => {20 await t.expect(withinAssertArray()).within([1, 2, 3, 4, 5], [1, 2, 3, 4, 5]);21});22const withinAssertObject = ClientFunction(() => {23 return { a: 1, b: 2, c: 3, d: 4, e: 5 };24});25test('within Assert Object', async t => {26 await t.expect(withinAssertObject()).within({ a: 1, b: 2, c: 3, d: 4, e: 5 }, { a: 1, b: 2, c: 3, d: 4, e: 5 });27});28const withinAssertFunction = ClientFunction(() => {29 return () => { return 1; };30});31test('within Assert Function', async t => {32 await t.expect(withinAssertFunction()).within(() => { return 1; }, () => { return 1; });33});34const withinAssertDate = ClientFunction(() => {35 return new Date();36});37test('within Assert Date', async t => {

Full Screen

Using AI Code Generation

copy

Full Screen

1import { Selector } from 'testcafe';2import { withinAssertNumber } from './utils/assertNumber';3test('My first test', async t => {4 await withinAssertNumber(Selector('#populate'), 1, 0);5});6import { t } from 'testcafe';7export async function withinAssertNumber(selector, max, min) {8 const count = await selector.count;9 await t.expect(count).lte(max);10 await t.expect(count).gte(min);11}12import { t } from 'testcafe';13export async function withinAssertNumber(selector, max, min) {14 const count = await selector.count;15 await t.expect(count).lte(max);16 await t.expect(count).gte(min);17}18import { t } from 'testcafe';19export async function withinAssertNumber(selector, max, min) {20 const count = await selector.count;21 await t.expect(count).lte(max);22 await t.expect(count).gte(min);23}24import { t } from 'testcafe';25export async function withinAssertNumber(selector, max, min) {26 const count = await selector.count;27 await t.expect(count).lte(max);28 await t.expect(count).gte(min);29}30import { t } from 'testcafe';31export async function withinAssertNumber(selector, max, min) {32 const count = await selector.count;33 await t.expect(count).lte(max);34 await t.expect(count).gte(min);35}36import { t } from 'testcafe';37export async function withinAssertNumber(selector, max, min) {38 const count = await selector.count;39 await t.expect(count).lte(max);40 await t.expect(count).gte(min);41}

Full Screen

Using AI Code Generation

copy

Full Screen

1import { Selector } from 'testcafe';2test('My Test', async t => {3 const articleHeader = await Selector('#article-header').innerText;4 const developerName = await Selector('#developer-name').value;5 .expect(articleHeader).eql('Thank you, John Smith!')6 .expect(developerName).eql('John Smith');7});8import { Selector } from 'testcafe';9test('My Test', async t => {10 const articleHeader = await Selector('#article-header').innerText;11 const developerName = await Selector('#developer-name').value;12 .expect(articleHeader).eql('Thank you, John Smith!')13 .expect(developerName).eql('John Smith');14});15import { Selector } from 'testcafe';16test('My Test', async t => {17 const articleHeader = await Selector('#article-header').innerText;18 const developerName = await Selector('#developer-name').value;19 .expect(articleHeader).eql('Thank you, John Smith!')20 .expect(developerName).eql('John Smith');21});22import { Selector } from 'testcafe';23test('My Test', async t => {

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Testcafe automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful