Last active
January 19, 2020 14:47
-
-
Save sengupta-saikat/48974fcaa93f3b8878111c3d42507acc to your computer and use it in GitHub Desktop.
TestCafe Assertions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Selector } from 'testcafe'; | |
fixture `Getting Started` | |
.page `https://news.ycombinator.com/`; | |
/** | |
* Docs: https://devexpress.github.io/testcafe/documentation/test-api/assertions/assertion-api.html | |
* Signature: await t.expect( actual ).eql( expected, message, options ); | |
* | |
*/ | |
test('Assertion API', async t => { | |
// Deep Equal | |
await t.expect(Selector('table').count).eql(4, 'Text shoud be 4', { timeout: 500 }); | |
// Not Deep Equal | |
await t.expect(Selector('table').count).notEql(40); | |
// Ok | |
await t.expect(Selector('#hnmain').exists).ok(); | |
// Not Ok | |
await t.expect(Selector('#hnmainfun').exists).notOk(); | |
// Contains | |
await t.expect(['apple', 'banana', 'cherry']).contains('banana', 'Found his favorite fruit!'); | |
// Not Contains | |
await t.expect(['apple', 'banana', 'cherry']).notContains('avocado', 'Not found his favorite fruit!'); | |
// Type of | |
await t.expect(Selector('#pagespace').getAttribute('style')).typeOf('string'); | |
// Not Type of | |
await t.expect(Selector('#pagespace').getAttribute('style')).notTypeOf('object'); | |
// Greater than | |
await t.expect(Selector('#pagespace').count).gt(0); | |
// Greater than or Equal to | |
await t.expect(Selector('#pagespace').count).gte(1); | |
// Less than | |
await t.expect(Selector('#pagespace').count).lt(2); | |
// Less than or Equal to | |
await t.expect(Selector('#pagespace').count).lte(1); | |
// Within | |
await t.expect(Selector('#pagespace').count).within(1, 10); | |
// Not Within | |
await t.expect(Selector('#pagespace').count).notWithin(10, 100); | |
// Match | |
await t.expect('foobar').match(/^f/); | |
// Not Match | |
await t.expect('foobar').notMatch(/^b/); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment