Skip to content

(@wdio/runner): support assertion hooks#11714

Merged
christian-bromann merged 3 commits intomainfrom
cb/assertion-hooks
Nov 23, 2023
Merged

(@wdio/runner): support assertion hooks#11714
christian-bromann merged 3 commits intomainfrom
cb/assertion-hooks

Conversation

@christian-bromann
Copy link
Member

@christian-bromann christian-bromann commented Nov 22, 2023

Proposed changes

With v4.6.0 of expect-webdriverio we start to support hooks for assertions. This PR integrates this feature to the WebdriverIO test runner. It integrates it in a way that also allows reporter to use the data.

Here is an example:

Given you have the following hooks in your wdio.conf.js:

    beforeAssertion: (params) => {
        console.log('beforeAssertion', params)
    },
    afterAssertion: (params) => {
        console.log('afterAssertion', params)
    }

and in your tests you have an assertion like this:

await expect(browser).toHaveTitle('WebdriverIO · Next-gen browser and mobile automation test framework for Node.js | WebdriverIO')

Then it will log the following data:

[0-0] beforeAssertion {
[0-0]   matcherName: 'toHaveTitle',
[0-0]   expectedValue: 'WebdriverIO · Next-gen browser and mobile automation test framework for Node.js | WebdriverIO',
[0-0]   options: {
[0-0]     wait: 5000,
[0-0]     interval: 500,
[0-0]     beforeAssertion: [AsyncFunction: beforeAssertion],
[0-0]     afterAssertion: [AsyncFunction: afterAssertion]
[0-0]   }
[0-0] }
[0-0] afterAssertion {
[0-0]   matcherName: 'toHaveTitle',
[0-0]   expectedValue: 'WebdriverIO · Next-gen browser and mobile automation test framework for Node.js | WebdriverIO',
[0-0]   options: {
[0-0]     wait: 5000,
[0-0]     interval: 500,
[0-0]     beforeAssertion: [AsyncFunction: beforeAssertion],
[0-0]     afterAssertion: [AsyncFunction: afterAssertion]
[0-0]   },
[0-0]   result: { pass: true, message: [Function: message] }
[0-0] }

Types of changes

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update

Checklist

  • I have read the CONTRIBUTING doc
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)
  • I have added proper type definitions for new commands (if appropriate)

Further comments

n/a

Reviewers: @webdriverio/project-committers

@christian-bromann christian-bromann added the PR: New Feature 🚀 PRs that contain new features label Nov 22, 2023
@christian-bromann christian-bromann merged commit d503cbe into main Nov 23, 2023
@christian-bromann christian-bromann deleted the cb/assertion-hooks branch November 23, 2023 00:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

PR: New Feature 🚀 PRs that contain new features

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant