Open argentlynx opened 1 year ago
Hi @argentlynx
I have no experience using nightwatchjs, so I actually don't know if your request could be easly implemented. There are only 2 mandatory features required to run the tests:
If this is achievable with nightwatchjs than I guess we can implement something like that. I was privately testing something like you requested to enable code coverage while running cucumberjs tests using a third party executable.
Can you please give some feedback about the requirements?
Thanks 👍
Thanks @Balrog994
I downloaded the sourcecode for cucumber-test-runner to try to implement it. I might have something that works but still experimenting with it.
Nightwatch is actually kind of a pain to do this with. It does not accept cucumber *.feature files as parameters, only tags. So I'm messing around with converting the filename and test line number into a tag to pass as a parameter to nightwatch (and then I'll just tag the scenarios in cucumber with the filename)
Not sure if it's a good fit really, so I don't know how much time I'll dedicate to this, but here is what I did so far in case anyone gets interested in this or if you're interested in looking into this later if people want it.
testRunner.ts
@line:187 itemsOptions - convert this to tags const itemsTags = itemsOptions.map(x => "@" + x.split("\").pop().replace(/[.: -]/g,'_'));
then itemsTags as a parameter for nightwatch
var tagParameter = "--tags " + itemsTags[0];
(or you could use itemsTags.join(" AND") but I think there is a bug in nightwatch not allowing multiple tags to be passed for the moment so I'm just passing a single tag.
@line:211 Modify the cucumberProcess = spawn( to...
const cucumberProcess = spawn(
`npx`, // we need to run nightwatch with npx, not with node
[[], `${workspace.uri.fsPath}/node_modules/nightwatch/bin/runner.js`, tagParameter, "", "", []],
{
cwd: workspace.uri.fsPath,
env: env,
}
);
[haven't tried yet] (possibly) detect if a tag is matching the feature, if so, spawn with npx nightwach, if not, spawn normal node cucumber
References
Installing the nightwatchjs project with cucumberjs support https://www.browserstack.com/guide/nightwatchjs-tutorial
So maybe the best thing for the time being is I will just hide the nightwatch tests in the test runner. Not sure yet. Leaving my notes here in case someone else is trying it.
OK got a draft working but using the minified code. It's a one-liner but if you want to somehow make a feature for this in the future I donate it to the code penny jar.
after installing the nightwatch project (at url listed above)
Edit your nightwatch.feature file, add tag @nightwatch_feature_8 to the scenario "Searching the Rijksmuseum" (because Scenario: Searching the Rijksmuseum appears on the .feature file line 8)
goto the .vscode/extensions/balrog994.cucumber-test-runner-0.5.0/dist/main.js file
remove this line
let w=(0,Va.spawn)("node",[...R,${a.uri.fsPath}/node_modules/@cucumber/cucumber/bin/cucumber.js
,...n,"--format","message",...y],{cwd:a.uri.fsPath,env:c});
let w=(0,Va.exec)("npx " + ${a.uri.fsPath}/node_modules/nightwatch/bin/runner.js
+ (" --tags \"" + n.map(x => "@" + x.split("\").pop().replace(/[.: -]/g,'_'))[0] + "\""),{shell:true,cwd:a.uri.fsPath});
Save
Re-open VS Code
Open cucumber-test-runner
Click "Run" icon next to the nightwatch.feature - Google Search test
Done, now it works (but the code is rough)
C:\WINDOWS\system32\cmd.exe C:\WINDOWS\system32\cmd.exe,/d,/s,/c,"npx c:\Users{youruseridinwindows}{pathtoyournightwatchfolder}\NightwatchTestFolder/node_modules/nightwatch/bin/runner.js --tags "@nightwatch_feature_8"" stdout: Using: [1;34mchrome[0m[0;33m (114.0.5735.199)[0m on [0;36mWINDOWS[0m. stdout: ...[0;32m√[0m Testing if the page title equals [0;33m'Rijksmuseum Amsterdam, home of the Dutch masters'[0m [0;90m(56ms)[0m stdout: .[0;32m√[0m Element <#rijksmuseum-app> was visible after 33 milliseconds. stdout: .[0;32m√[0m Testing if element [0;33m<.search-results>[0m contains text [0;33m'Operation Night Watch'[0m [0;90m(1263ms)[0m stdout: .. stdout: 1 scenario (1 passed) stdout: 5 steps (5 passed) stdout: 0m08.358s (executing steps: 0m08.341s) stdout: [0;90m Wrote HTML report file to: c:\Users{whateveryourpathistothisfolder}\NightwatchTestFolder\tests_output\nightwatch-html-report\index.html stdout: [0m
If this becomes a feature I imagine it would have to have a setting or something to enable it in the settings page, and be able to detect whether or not the filename matches a tag to decide whether to run it using "npx nightwatch" vs. "node cucumber" or something like that, dunno but there it is. : D
In the future is there any plan to allow a custom command when executing tests? I have some tests that need to be run with cucumberjs and others require nightwatchjs as the command (which then calls cucumber).
Wasn't sure how to raise this as a feature request, sorry if it's the wrong place feel free to just delete this after you read it.