rquellh / testcafe-cucumber Goto Github PK
View Code? Open in Web Editor NEWIntegration of TestCafe and CucumberJS
License: MIT License
Integration of TestCafe and CucumberJS
License: MIT License
Hi,
First of all, thanks for creating this project which is helping me to integrate cucumber.
I would really appreciate if we can integrate the allure-js framework for reporting as well as we can use that for historical records.
Thanks,
Ash
Hello,
Can you give an example, how to implement the mocking feature to your tests?
According to testCafe, for mock response from server we need to write:
import { RequestLogger, RequestMock } from 'testcafe';
const logger = RequestLogger('http://example.com');
const mock = RequestMock()
.onRequestTo('http://external-service.com/api/')
.respond({ data: 'value' });
fixture My fixture
.page('http://example.com')
.requestHooks(logger);
test
.requestHooks(mock)
('My test', async t => {
await t
.click('#send-logged-request')
.expect(logger.count(() => true)).eql(1)
.removeRequestHooks(logger)
.click('#send-unlogged-request')
.expect(logger.count(() => true)).eql(1)
.addRequestHooks(logger)
.click('#send-logged-request')
.expect(logger.count(() => true)).eql(2);
})
But I can not find fixtures and tests in your steps.
Hello, can you please provide an example of how and where to set setLocalStorageItem(key, value)
within the code? I am unable to setLocalStorage with my token and have tried many different ways to no avail. Your response is very much appreciated. Thanks!
Hi @rquellh,
I came across your code repository. It looks fantastic ๐ .
I was able to run tests on my development machine straight forward enough.
I notice Testcafe supports testing with docker, saucelabs & browserstack. I'm new enough to Testcafe so I have only seen samples whereby integration with these providers have been through Testcafe command line. So my question would be, is their a way to run the tests against any of those providers given the way the tests are initiated in this project (via cucumberjs runner).
If their was a sample that would be very useful, because essentially I would think the project offering would be on par (if not better) with other alternatives (for example cucumberjs & protractor or cucumberjvm & selenium) which support that out of the box already.
Thoughts?
testcafe-cucumber/features/support/hooks.js
Lines 13 to 22 in 11644e3
fixture
. Even if I import it above alongside test
like const { fixture, test} = require("testcafe");
But when it's generated during runtime, it works without any problem. Any reason to explain this? Thanks.
Hi @rquellh ,
Thank you so much for this, I really like it! I took a lot of inspiration from you and also started doing my own cucumber-testcafe suite.
I have one question though: do you know how I report function timeouts properly? Let's say I have an element on a page (Selector
) and testcafe waits for it 20 seconds but doesn't find it - Cucumber then in that case will just report "a function timed out", wheras testcafe would have said on which line it stopped. Is it somehow possible to access the testcafe report as well as the cucumber reporting?
I already tried it with the reporters specified by testcafe in the runner API, but they all don't log anything - only the list
reporter prints out anything at all something, but this is only restricted to "Running tests on Chrome / Windows 10" and "Ran 1 test successfully" in the end.
const stream = fs.createWriteStream('report.json');
runner
.src('tests/sample-fixture.js')
.browsers('chrome')
.reporter('json', stream)
.reporter('list')
.run()
.then(failedCount => {
stream.end();
});
I cloned this repo and did the following steps
ร Before # features\support\hooks.js:46
Error: function timed out, ensure the promise resolves within 20000 milliseconds
at Timeout._onTimeout (C:\Users\A418097\Desktop\TestCafe\github\testCafeBDD\testcafe-cucumber\node_modules\cucumber\src\user_code_runner.js:61:18)
at ontimeout (timers.js:482:11)
at tryOnTimeout (timers.js:317:5)
at Timer.listOnTimeout (timers.js:277:5)
and then this error as well
ร After # features\support\hooks.js:60
ReferenceError: testController is not defined
at Object.exports.addErrorToController (C:\Users\A418097\Desktop\TestCafe\github\testCafeBDD\testcafe-cucumber\features\support\errorHandling.js:5:5)
at CustomWorld.<anonymous> (C:\Users\A418097\Desktop\TestCafe\github\testCafeBDD\testcafe-cucumber\features\support\hooks.js:65:23)
I am able to run testCafe cases without cucumber and I do that by adding this line to my package.json
"scripts": {
"test": "testcafe chrome Tests/ -e --proxy https.proxy.domain.com:8000"
},
I am guessing this is the problem why the tests timeout. Could someone point me in the right direction.
This may be a feature request; i'm not sure.
We're using remote browsers for browser-compatibility tests -- and iOS and OSX browsers do not like the standard 1338 port. With testcafe, I can set the port on which to connect to the browsers via the ports parameter, like this:
testcafe 'browserstack:iPad [email protected]' --ports 9000,9100 <tests>
However, we're not sure how to set that with testcafe-cucumber. Could someone give us some pointers on how to go about this? Thanks in advance!
Hello, hope somebody can help.
I have successfully been running all my TestCafe Cucumber tests on OSX with: ./node_modules/.bin/cucumber-js
I have also been able to run: $ ./node_modules/.bin/cucumber-js --world-parameters '{"browser": "firefox"}'
But I cannot add other TestCafe Command Line Interface when running my tests, as they are not recognised.
Example:
$ ./node_modules/.bin/cucumber-js --skip-js-errors
error: unknown option `--skip-js-errors'
In fact it seems I can only use commands from these docs: https://github.com/rquellh/testcafe-cucumber/wiki/Running-Tests
Is there a restriction here I am not aware of?
Hi,
I have tried running using the param '--parallel' and enabling concurrency in TestCafe but I'm getting an error saying:
Error: listen EADDRINUSE: address already in use :::1338
Is this an issue with TestCafe/CucumberJS?
Cheers
S
HI
I am unable to generate html report
I am trying to implement an inheritance/override model where I want to have a 'generic' step definition which will be imported in and specific steps overridden as necessary.
I was able to import the step definitions from my generic file, but the override (I used the same step definition name) seems to not be overriding the step definitions.
ex:
Generic file
Given('User navigates to x page', async () => {
await pAPage.navigateTo('x')
});
Specific/inherited file
Given('User navigates to x page', async () => {
await pAPage.navigateTo('y')
});
PS: Our software has a number of applications that are all similar but vary (differently) a bit from the base configuration based on the client. Having to define the common steps multiple times will create a maintenance nightmare. Hence we want to group the common step definitions in the generic file and import/override by client as needed.
Appreciate all the help in advance.
import { ClientFunction } from 'testcafe'; or const {ClientFunction} = require('testcafe');
When I try to use ClientFunction for JQuery in Cucumber-Testcafe frame-work, I get below error.
"ClientFunction cannot implicitly resolve the test run in context of which it should be executed. If you need to call ClientFunction from the Node.js API callback,
pass the test controller manually via ClientFunction's .with({ boundTestRun: t })
method first. Note that you cannot execute ClientFunction outside the test code."
I'm trying to call below JQuery, can you help me how to call it '.with({ boundTestRun: t })'
returnDefValue: ClientFunction(function (pageElem) {
return document.querySelectorAll(pageElem)[0].value;
}),
After few more tries, I wrapped JQuery in Client function like this :
returnDefValue: function (pageElem, t) {
return ClientFunction(document.querySelectorAll("select[name='dropdown-emailGroupBy']")[0].value).with({ boundTestRun: t });
},
it gives me the response , "ReferenceError: document is not defined"
===
So I'm not able to use the JQuery function with Cucumber, that is usually supported by a Client Function wrapper in testcafe ..
e.g export const returnDefValue = ClientFunction(function (pageElem) {
// window.scrollBy(0, 1000);
return document.querySelectorAll(pageElem)[0].value
});
Hi I tired using @tags on cli to skip features and scenarios and it didn't work. I am new to this so please provide an example on how to skip the Features and Scenarios when running tests.
I am using the testcafe with cucumber. I have the following list row values as shown in the image and I need to verify the values shown in the list as per the expected text.
I am trying with below code where data is passed from the feature file,
for(let i = 0 ; i < 3 ; i++){
const fieldName = Selector("div.nba-meta-action>div.nba-row>div.nba-row-left").with({ boundTestRun: testController }).withText(data[i].field);
testController.expect(fieldName.exists).ok();
const fieldValue = Selector("div.nba-meta-action>div.nba-row>div.nba-row-right").with({ boundTestRun: testController }).withText(data[i].value);
testController.expect(fieldValue.exists).ok();
}
I get error as "errMsg: 'AssertionError: expected false to be truthy'".
Can someone please help here.
Thanks
Bug
When you running a cucumber report the screenshot is not attached to the report on failure.
The screenshot should be attached to the report on failure.
Run a cucumber report with a failure and inspect the report.
operating system: Windows 10.0.0
nodejs version: 8.9.3
Currently I'm running parallel executions but the issue is test cafe starts on 1338 and its not allowing to run the second script simultaneously as fetches the below error. Do we have any option where we can mention it as random so that another test cafe execution picks different port?
Any help is much appreciated. Thank you
Hello, can you please provide an example of how and where to setLocalStorageItem(key, value)
within the code? I am unable to setLocalStorage with my token and have tried many different ways to no avail. Your response is very much appreciated. Thanks!
Hi
I renamed the features folder to e2e_tests, created features folder under e2e_tests and moved all the features file under features folder I change the path name for TestController and errorHandling as below
fs.writeFileSync('test.js',
'import errorHandling from "./e2e_tests/support/errorHandling.js";\n' +
'import testControllerHolder from "./e2e_tests/support/testControllerHolder.js";\n\n' +
If I run the a scenario or feature, it I am not getting error but none of the steps are executed
$ node ./node_modules/.bin/cucumber-js
(node:1491) ExperimentalWarning: The fs.promises API is experimental
0 scenarios
0 steps
0m00.000s
Done in 0.32s.
Any idea?
Thanks
Hi,
I have a problem finding out where does 'testController' comes from in github.js or google.js.
E.g.:
How do this test files know where this is defined? I thought this should be defined in hooks.js, but it seems I'm missing something.
Thnx!
Hi there,
I'm wondering is there a way to make parametrization of step?
What I mean is to pass an array to the scenario or step and run the scenario several times with every element from array?
Thanks
You are a good man!
Thanks for this awesome repository!!!!!
Hi there,
I ran the sample tests on a few browser configurations. I notice though the tests fail at the Before hook stage on some configuration types (chrome Mac) & (edge win). I think it fails at the 'waitForTestController' API call. It seems to fail on the second test for each feature file.
โ Before # features/support/hooks.js:46
Error: function timed out, ensure the promise resolves within 20000 milliseconds
at Timeout._onTimeout (/Users/bhrein.brannick/Documents/src/testcafe-cucumber/node_modules/cucumber/src/user_code_runner.js:61:18)
at ontimeout (timers.js:498:11)
at tryOnTimeout (timers.js:323:5)
at Timer.listOnTimeout (timers.js:290:5)
I guess this is a different type of failures as sample test scenario number 4 fails as expected due to a test assertion error, however what I describe above is due to setup failures. Incidentally the sample tests run ok (chrome win), (ie win) & (firefox Mac & Win). Let me know if you need any more info.
Hi!
Firstly, thank you for this awesome integration!
I'm using this on a poc to migrate my tests suite to testcafe. However, i've been facing a small issue:
It seems testControllerHolder.free();
is taking a little bit longer when the application which i'm working on to complete.
When this happens, the second test of my feature is not "allowed" to start and the browser "breaks".
Also, this only happens in chrome, everything else looks fine.
Currently i'm a little bit out of time to work on this, so i wrote a paliative:
//TODO: Forgive me oh god please
function waitFor () {
return new Promise( (resolve) => {
setTimeout( () => {
resolve()
}, 1000)
})
}
After(async function () {
fs.unlinkSync('test.js');
testControllerHolder.free();
await waitFor()
});
But it would be interesting if we could handle this in a better way.
I've used this as a baseline for creating a generic Cucumber/Testcafe Library of step definitions, and importing the support files and step definitions works fine so the 2nd project only container the .feature
/ BDD side of things.
However, when I then add a test/dummy example step definition in the 2nd project I get this error.
The "boundTestRun" option value is expected to be a test controller.
I've debugged and logged and everything seems to be as expected, so wondering is I'm missing something about how cucmberJS sets up the environment??
logging testController I have it as expected -
TestController {
testRun:
TestRun {
domain: null,
_events: { done: [Function] },
_eventsCount: 1,
_maxListeners: undefined,
uploadStorage: UploadStorage { uploadsRoot: '/Users/..../...-bdd' },
id: 'RmElLchgu',
cookies: Cookies { cookieJar: [CookieJar] },
....
Would like to use this approach so any help is appreciated and happy to provide more example or info if required.
thanks for the repo.
"dependencies": {
"base64-img": "^1.0.4",
"cucumber": "^4.2.1",
"eslint": "^4.19.1",
"npm": "^6.0.0",
"testcafe": "^0.23.2"
},
I have been trying to run a scenario which looks something like this
@gpnotification
Feature: As a patient, I want to select my preferred GP Surgery
so that I can keep my GP informed of LOD online consultation
Background: A patient already added a product to basket and is on delivery page
Given I am on delivery page on desktop
@verifyGPNotification
Scenario Outline: Verify that a patient can see GP notification on delivery page when Feature flag is ON
And I choose my "<deliveryoptions>"
When I access the page with feature flag ON
Then I verify that I can see GP notification
Examples:
| deliveryoptions |
| nextdaydelivery |
| clickncollect |
| standarddelivery |
When I run - npm test - testcafe runs only for the first row in the example table. It doesnt iterate. I get the following output in console but there is nothing more to debug
[email protected] test C:\Users\krish.murthy\intellijworkspace\archive\testcafe-cucumber
cucumber-js.cmd
Running tests in:
fixture
....... โ test
1 passed (40s)
npm ERR! Test failed. See above for more details.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.