Skip to content
Permalink
Browse files
feat(protractor): Screenplay-style expectations for Protractor
  • Loading branch information
jan-molak committed Feb 3, 2019
1 parent 89f70da commit 5a86862ab31dad8901e1117b11b8d03dffd0b5b1
Showing with 3,631 additions and 9 deletions.
  1. +1 −1 packages/assertions/src/Ensure.ts
  2. +2 −2 packages/assertions/src/expectations/and.ts
  3. +5 −5 packages/assertions/src/expectations/not.ts
  4. +1 −0 packages/assertions/src/index.ts
  5. +1 −0 packages/core/src/index.ts
  6. +3,039 −0 packages/protractor/package-lock.json
  7. +64 −0 packages/protractor/spec/expectations/isClickable.spec.ts
  8. +55 −0 packages/protractor/spec/expectations/isEnabled.spec.ts
  9. +54 −0 packages/protractor/spec/expectations/isPresent.spec.ts
  10. +65 −0 packages/protractor/spec/expectations/isSelected.spec.ts
  11. +56 −0 packages/protractor/spec/expectations/isVisible.spec.ts
  12. +63 −0 packages/protractor/spec/screenplay/interactions/Wait.spec.ts
  13. +11 −1 packages/protractor/src/screenplay/abilities/BrowseTheWeb.ts
  14. +33 −0 packages/protractor/src/screenplay/expectations/ElementFinderExpectation.ts
  15. +32 −0 packages/protractor/src/screenplay/expectations/combined.ts
  16. +5 −0 packages/protractor/src/screenplay/expectations/index.ts
  17. +15 −0 packages/protractor/src/screenplay/expectations/isClickable.ts
  18. +13 −0 packages/protractor/src/screenplay/expectations/isEnabled.ts
  19. +14 −0 packages/protractor/src/screenplay/expectations/isPresent.ts
  20. +15 −0 packages/protractor/src/screenplay/expectations/isSelected.ts
  21. +19 −0 packages/protractor/src/screenplay/expectations/isVisible.ts
  22. +1 −0 packages/protractor/src/screenplay/index.ts
  23. +66 −0 packages/protractor/src/screenplay/interactions/Wait.ts
  24. +1 −0 packages/protractor/src/screenplay/interactions/index.ts
@@ -26,7 +26,7 @@ export class Ensure<Actual> implements Interaction {
match<Outcome<any, Actual>, void>(outcome)
.when(ExpectationNotMet, o => {
throw new AssertionError(
`Expected ${ formatted`${actual}` } to ${ o.message }`,
`Expected ${ formatted`${this.actual}` } to ${ o.message }`,
o.expected,
o.actual,
);
@@ -3,8 +3,8 @@ import { match } from 'tiny-types';
import { Expectation } from '../Expectation';
import { ExpectationNotMet, Outcome } from '../outcomes';

export function and<Actual>(...assertions: Array<Expectation<any, Actual>>): Expectation<any, Actual> {
return new And(assertions);
export function and<Actual>(...expectations: Array<Expectation<any, Actual>>): Expectation<any, Actual> {
return new And(expectations);
}

class And<Actual> extends Expectation<any, Actual> {
@@ -9,22 +9,22 @@ export function not<Expected, Actual>(assertion: Expectation<Expected, Actual>):
}

class Not<Expected, Actual> extends Expectation<Expected, Actual> {
constructor(private readonly assertion: Expectation<Expected, Actual>) {
constructor(private readonly expectation: Expectation<Expected, Actual>) {
super();
}

answeredBy(actor: AnswersQuestions): (actual: Actual) => Promise<Outcome<Expected, Actual>> {

return (actual: any) =>
this.assertion.answeredBy(actor)(actual)
this.expectation.answeredBy(actor)(actual)
.then((outcome: Outcome<Expected, Actual>) =>
match<Outcome<Expected, Actual>, Outcome<Expected, Actual>>(outcome)
.when(ExpectationMet, o => new ExpectationNotMet(this.flipped(this.assertion.toString()), o.expected, o.actual))
.else(o => new ExpectationMet(this.flipped(this.assertion.toString()), o.expected, o.actual)));
.when(ExpectationMet, o => new ExpectationNotMet(this.flipped(this.expectation.toString()), o.expected, o.actual))
.else(o => new ExpectationMet(this.flipped(this.expectation.toString()), o.expected, o.actual)));
}

toString(): string {
return this.flipped(this.assertion.toString());
return this.flipped(this.expectation.toString());
}

private flipped(message: string): string {
@@ -1,3 +1,4 @@
export * from './Expectation';
export * from './expectations';
export * from './Ensure';
export * from './outcomes';
@@ -2,3 +2,4 @@ export * from './errors';
export * from './instance';
export * from './screenplay';
export * from './stage/Cast';
export { Duration } from './model';

0 comments on commit 5a86862

Please sign in to comment.