Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add context to before/after scenario hooks issue 5394 #5483

Conversation

osmolyar
Copy link
Contributor

@osmolyar osmolyar commented Jun 11, 2020

Proposed changes

Add context to before/after scenario hooks to resolve issue #5394

//: # Addressing issue #5394.

Types of changes Modeled on changes in https://github.com/webdriverio/webdriverio/pull/4545/files to add context parameter to hooks

  • Bugfix (non-breaking change which fixes an issue)
  • [ x] 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

Reviewers: @webdriverio/project-committers

tests/helpers/cucumber-hooks.conf.js Outdated Show resolved Hide resolved
@@ -7,9 +7,10 @@ exports.config = Object.assign({}, config, {
await browser.pause(30)
browser.Cucumber_Test = 0
},
beforeScenario: () => {
beforeScenario: (world) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

world should be the 5th parameter, no?

Copy link
Contributor Author

@osmolyar osmolyar Jun 11, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes; suspended work on this for now as it's not working. Erwin Heitzman suggested the hooks should be wrapped (similar to before/afterStep) but that also didn't seem to work.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Managed to link @wdio/cucumber-framework but it doesn't seem to be working at all. (In fact, can't even get context to console.log in before/afterStep where it is supposed to already be supported). Will close PR for now.

@@ -27,9 +28,15 @@ exports.config = Object.assign({}, config, {
}
browser.Cucumber_Test = 1
},
afterScenario: () => {
afterScenario: (world) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

Co-authored-by: Christian Bromann <github@christian-bromann.com>
@osmolyar
Copy link
Contributor Author

Not working locally; closing for now

@osmolyar osmolyar closed this Jun 12, 2020
@christian-bromann
Copy link
Member

Not working locally; closing for now

I recommend to use our smoke test to check if changes work. You can just try reproduce your desired scenario in our cucumber smoke project and run it while you are changing files.

@osmolyar
Copy link
Contributor Author

Thanks for the tips. Am a little confused about how to use the cucumber smoke project because the thing that isn't 'working' is logging out the 'context' parameter in before/afterStep, before/afterScenario hood (before/afterStep even before the changes in this PR), and there is no config file with hooks in the smoke project. In any case the cucumberTestrunner tests are also failing but it's not clear why:

PS C:\webdriverio> npm run test:smoke cucumberTestrunner

webdriverio-monorepo@1.0.0 test:smoke C:\webdriverio
babel-node ./tests/smoke.runner.js "cucumberTestrunner"

Running smoke tests...

Execution of 2 spec files started at 2020-06-12T16:42:03.397Z

[BABEL] Note: The code generator has deoptimised the styling of C:\webdriverio\packages\wdio-webdriver-mock-service\node_modules\lodash\lodash.js as it exceeds the max of 500KB.
[0-1] FAILED
[0-0] FAILED

Spec Files: 0 passed, 2 failed, 2 total (100% completed) in 00:00:13

========== LOG OUPUT wdio-0-0.log

========== LOG OUPUT wdio-0-1.log

========== LOG OUPUT wdio.log
2020-06-12T16:42:09.930Z INFO @wdio/local-runner: Start worker 0-0 with arg: cucumberTestrunner
2020-06-12T16:42:10.063Z INFO @wdio/local-runner: Start worker 0-1 with arg: cucumberTestrunner
2020-06-12T16:42:16.810Z DEBUG @wdio/local-runner: Runner 0-1 finished with exit code 1
2020-06-12T16:42:16.829Z DEBUG @wdio/local-runner: Runner 0-0 finished with exit code 1
2020-06-12T16:42:16.961Z INFO @wdio/local-runner: Shutting down spawned worker
2020-06-12T16:42:17.225Z INFO @wdio/local-runner: Waiting for 0 to shut down gracefully

Error: Smoke test failed
at C:\webdriverio\tests\helpers\launch.js:39:11
at cucumberTestrunner (C:\webdriverio\tests\smoke.runner.js:101:7)
at runTests (C:\webdriverio\tests\smoke.runner.js:35:7)
at runTests (C:\webdriverio\tests\smoke.runner.js:35:7)
at C:\webdriverio\tests\smoke.runner.js:300:3
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! webdriverio-monorepo@1.0.0 test:smoke: babel-node ./tests/smoke.runner.js "cucumberTestrunner"
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the webdriverio-monorepo@1.0.0 test:smoke script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\osmolyar\AppData\Roaming\npm-cache_logs\2020-06-12T16_42_19_295Z-debug.log

@christian-bromann
Copy link
Member

In any case the cucumberTestrunner tests are also failing but it's not clear why:

Is this with your change or without?

@osmolyar
Copy link
Contributor Author

Both with and without changes.

@christian-bromann
Copy link
Member

Can you try on a fresh checked out repository? These tests should pass (see CI pipeline).

@osmolyar
Copy link
Contributor Author

Tried with a freshly cloned/checked out repository and the tests still fail. (Also had to install @wdio/local-runner separately after npm install and npm run setup-full to run smoke tests.)

@osmolyar
Copy link
Contributor Author

@christian-bromann just fyi the cucumber smoke tests pass when run in a standalone command prompt, but not from the same directory within VSCode.

@christian-bromann
Copy link
Member

when run in a standalone command prompt, but not from the same directory within VSCode.

Can you explain a bit further what you mean by that?

@osmolyar
Copy link
Contributor Author

Sorry, the above comment is incorrect. The command "npm run test:smoke cucumberTestrunner" results in the same Failed result both in a command prompt and in VSCode's terminal window. It only says "All tests passed" when misspelled as "npm run test:smoke cucumberTestrunne" (presumably because then there are no tests to run). In any case the PR should be closed as the code changes don't work.

@osmolyar osmolyar closed this Jun 22, 2020
@christian-bromann
Copy link
Member

@osmolyar I think the change still makes a lot of sense? Let's re-open and we jump on a 1:1 session through the WebdriverIO Office Hours?!

@osmolyar
Copy link
Contributor Author

Ok- in a meeting for the next hour but otherwise anytime. Thanks

@osmolyar osmolyar reopened this Jun 22, 2020
@christian-bromann
Copy link
Member

but otherwise anytime

Please use the link to schedule a time. Thanks!

Copy link
Member

@christian-bromann christian-bromann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Thanks so much! That was a successful session.

@christian-bromann christian-bromann added PR: Bug Fix 🐛 PRs that contain bug fixes PR: Polish 💅 PRs that contain improvements on existing features and removed PR: Bug Fix 🐛 PRs that contain bug fixes labels Jun 24, 2020
@christian-bromann christian-bromann merged commit 44869f4 into webdriverio:master Jun 24, 2020
christian-bromann added a commit that referenced this pull request Jul 14, 2020
Co-authored-by: Christian Bromann <github@christian-bromann.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR: Polish 💅 PRs that contain improvements on existing features
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants