Skip to content

Commit bdf4d6a

Browse files
Merge pull request #17 from testla-project/10-inconsistent-assertionquestion-handling
10 inconsistent assertionquestion handling
2 parents 9c9914b + e8ec717 commit bdf4d6a

File tree

8 files changed

+2173
-5400
lines changed

8 files changed

+2173
-5400
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
.eslintcache
33
/lib
44
.DS_Store
5-
.idea/
5+
.idea/

README.md

+61-44
Original file line numberDiff line numberDiff line change
@@ -151,26 +151,26 @@ BrowseTheWeb.as(actor).hover('mySelector', {
151151
});
152152
```
153153

154-
#### isEnabled(selector: string, options?: SelectorOptions)
154+
#### checkEnabledState(selector: string, mode: 'enabled' | 'disabled', options?: SelectorOptions, timeout?: number)
155155

156-
Verify if a locator on the page is enabled.
156+
Verify if a locator on the page is enabled or disabled.
157157

158158
```js
159159
// simple call with just selector
160-
BrowseTheWeb.as(actor).isEnabled('mySelector');
160+
BrowseTheWeb.as(actor).checkEnabledState('mySelector', 'enabled');
161161
// or with options
162-
BrowseTheWeb.as(actor).isEnabled('mySelector', { hasText: 'myText', subSelector: ['mySubSelector', { hasText: 'anotherText' } ]});
162+
BrowseTheWeb.as(actor).checkEnabledState('mySelector', 'disabled', { hasText: 'myText', subSelector: ['mySubSelector', { hasText: 'anotherText' } ]});
163163
```
164164

165-
#### isVisible(selector: string, options?: SelectorOptions)
165+
#### checkVisibilityState(selector: string, mode: 'visible' | 'hidden', options?: SelectorOptions, timeout?: number)
166166

167167
Verify if a locator on the page is visible.
168168

169169
```js
170170
// simple call with just selector
171-
BrowseTheWeb.as(actor).isVisible('mySelector');
171+
BrowseTheWeb.as(actor).checkVisibilityState('mySelector', 'visible');
172172
// or with options
173-
BrowseTheWeb.as(actor).isVisible('mySelector', { hasText: 'myText', subSelector: ['mySubSelector', { hasText: 'anotherText' } ]});
173+
BrowseTheWeb.as(actor).checkVisibilityState('mySelector', 'hidden', { hasText: 'myText', subSelector: ['mySubSelector', { hasText: 'anotherText' } ]});
174174
```
175175

176176
#### press(keys: string)
@@ -470,46 +470,46 @@ Send a request (GET, POST, PATCH, PUT, HEAD or DELETE) to the specified url. Hea
470470
UseApi.as(actor).sendRequest(REQUEST_METHOD.POST, '/items', { authorization: 'Bearer dfh.dasgeq65qg.eyjkhf' }, 'json', { title: 'new item' });
471471
```
472472

473-
#### checkStatus(response: Response, status: number)
473+
#### checkStatus(response: Response, status: number, mode: 'equal' | 'unequal')
474474

475475
Verify if the given response's status is equal to the expected status.
476476

477477
```js
478-
UseApi.as(actor).checkStatus(response, 200);
478+
UseApi.as(actor).checkStatus(response, 200, 'equal');
479479
```
480480

481-
#### checkBody(response: Response, body: ResponseBodyFormat)
481+
#### checkBody(response: Response, body: ResponseBodyType, mode: 'equal' | 'unequal')
482482

483483
Verify if the given response's body is equal to the expected body. The check includes type safety.
484484

485485
```js
486486
// json response
487-
UseApi.as(actor).checkBody(response, { text: 'test' });
487+
UseApi.as(actor).checkBody(response, { text: 'test' }, 'equal');
488488
// text response
489-
UseApi.as(actor).checkBody(response, 'test');
489+
UseApi.as(actor).checkBody(response, 'test', 'unequal');
490490
// buffer response
491-
UseApi.as(actor).checkBody(response, Buffer.from('abc'));
491+
UseApi.as(actor).checkBody(response, Buffer.from('abc'), 'equal');
492492
```
493493

494-
#### checkHeaders(response: Response, headers: {[key: string]: string | undefined })
494+
#### checkHeaders(response: Response, headers: {[key: string]: string | undefined }, mode: 'included' | 'excluded')
495495

496496
Verify if the given headers are included in the given response's headers.
497497
If the header has a value !== undefined, both key and value will be checked. If a header has a value === undefined, only the key will be checked.
498498

499499
```js
500500
// check only keys
501-
UseApi.as(actor).checkHeaders(response, { contentType: undefined });
501+
UseApi.as(actor).checkHeaders(response, { contentType: undefined }, 'included');
502502
// check key and value
503-
UseApi.as(actor).checkHeaders(response, { contentType: 'application/json' });
503+
UseApi.as(actor).checkHeaders(response, { contentType: 'application/json' }, 'excluded');
504504
```
505505

506-
#### checkDuration(response: Response, duration: number)
506+
#### checkDuration(response: Response, duration: number, mode: 'lessOrEqual' | 'greater')
507507

508508
Verify if the reponse (including receiving body) was received within a given duration.
509509

510510
```js
511511
// check if response was received within 2s
512-
UseApi.as(actor).checkDuration(response, 2000);
512+
UseApi.as(actor).checkDuration(response, 2000, 'lessOrEqual');
513513
```
514514

515515
### API Actions
@@ -644,74 +644,91 @@ Sleep.for(5000);
644644

645645
### Available Web Questions
646646

647-
#### Element.isVisible(selector: string, options?: SelectorOptions & { wait?: boolean })
647+
#### Element.toBe
648648

649-
Validates weather an element is visible or not. By default it is waited for this event to happen btu limited by the global playwright timeout settings.
650-
By settings wait to false in the options section this can be overridden.
649+
Checks if a condition is true.
650+
651+
#### Element.notToBe
652+
653+
Checks if a condition is false.
654+
655+
#### Element.*.visible(selector: string, options?: SelectorOptions)
656+
657+
Validates wether an element is visible. A mode operator must be prepended.
651658

652659
```js
653660
// simple call with just selector
654-
Element.isVisible('mySelector');
661+
Element.toBe.visible('mySelector');
655662
// or with options
656-
Element.isVisible('mySelector', {
663+
Element.notToBe.visible('mySelector', {
657664
hasText: 'myText',
658665
subSelector: ['mySubSelector', { hasText: 'anotherText' } ]
659-
wait: false // false means that the selector has to be available without any wait time.
660666
});
661667
```
662668

663-
#### Element.isEnabled(selector: string, options?: SelectorOptions)
669+
#### Element.*.enabled(selector: string, options?: SelectorOptions)
664670

665-
Validates weather an element is enabled or not.
671+
Validates wether an element is enabled. A mode operator must be prepended.
666672

667673
```js
668674
// simple call with just selector
669-
Element.isEnabled('mySelector');
675+
Element.toBe.enabled('mySelector');
670676
// or with options
671-
Element.isEnabled('mySelector', { hasText: 'myText', subSelector: ['mySubSelector', { hasText: 'anotherText' } ]});
677+
Element.notToBe.enabled('mySelector', { hasText: 'myText', subSelector: ['mySubSelector', { hasText: 'anotherText' } ]});
672678
```
673679

674680
### Available Api Questions
675681

676-
#### Response.hasStatusCode(response: Response, code: number)
682+
#### Response.has
683+
684+
Checks if a condition is true.
685+
686+
#### Response.hasNot
687+
688+
Checks if a condition is false.
689+
690+
#### Response.*.statusCode(response: Response, code: number)
677691

678-
Checks if the response has a given status code.
692+
Checks if the response has a given status code. A mode operator must be prepended.
679693

680694
```js
681-
Response.hasStatusCode(response, 200);
695+
Response.has.statusCode(response, 200);
696+
Response.hasNot.statusCode(response, 200);
682697
```
683698

684-
#### Response.bodyEquals(response: Response, body: ResponseBodyType)
699+
#### Response.*.body(response: Response, body: ResponseBodyType)
685700

686-
Checks if the response equals a given body.
701+
Checks if the response body equals a given body. A mode operator must be prepended.
687702

688703
```js
689704
// json format
690-
Response.bodyEquals(response, { key: value });
705+
Response.has.body(response, { key: value });
691706
// text format
692-
Response.bodyEquals(response, 'text' );
707+
Response.hasNot.body(response, 'text' );
693708
// buffer format
694-
Response.bodyEquals(response, Buffer.from('abc') );
709+
Response.has.body(response, Buffer.from('abc') );
695710
```
696711

697-
#### Response.hasHeaders(response: Response, headers: Headers)
712+
#### Response.*.headers(response: Response, headers: Headers)
698713

699-
Checks if the response holds the given headers either by key (value to be set to undefined) or key/value lookup.
714+
Checks if the response has the given headers either by key (value to be set to undefined) or key/value lookup. A mode operator must be prepended.
700715

701716
```js
702717
// only check for header presence by passing undefined as the value
703-
Response.hasHeaders(response, { 'content-type': undefined });
718+
Response.has.headers(response, { 'content-type': undefined });
704719
// lookup for key/value combination to be present
705-
Response.hasHeaders(response, { 'content-type': 'application/json' });
720+
Response.hasNot.headers(response, { 'content-type': 'application/json' });
706721
```
707722

708-
#### Response.wasReceivedWithin(response: Response, duration: number)
723+
#### Response.*.beenReceivedWithin(response: Response, duration: number)
709724

710-
Checks if the reponse (including receiving body) was received within a given duration.
725+
Checks if the reponse (including receiving body) was received within a given duration. A mode operator must be prepended.
711726

712727
```js
713728
// check if response was received within 2s
714-
Response.wasReceivedWithin(response, 2000);
729+
Response.has.beenReceivedWithin(response, 2000);
730+
// check if response was not received within 2s
731+
Response.hasNot.beenReceivedWithin(response, 2000);
715732
```
716733

717734
### Group Actions into a Task
@@ -776,7 +793,7 @@ test.describe('My Test', () => {
776793
await actor.attemptsTo(Login.toApp());
777794

778795
// Check if the login was successful - use the status question from the web package
779-
expect(await actor.asks(Element.isVisible('#logged-in-indicator'))).toBe(true);
796+
await actor.asks(Element.toBe.visible('#logged-in-indicator'));
780797
});
781798
});
782799
```

0 commit comments

Comments
 (0)