TestCafe integration with cucumber - test cases in github project time out - automated-tests

I have been experimenting with javascript frameworks for test automation and one of them is testCafe. I have been able to set up a simple TestCafe project and run some test cases for my application. However, now, the requirement is to have some kinda BDD support built in it. I looked up a few testCafe-cucumber integration projects on GitHub but I can't get them to run. here are a few that I tried:-
1) https://github.com/rquellh/testcafe-cucumber
- I cloned the repo,
- did npm install,
- run the test cases using "npm test",
- blank browser launches but test doesn't run. I see this error in VS code console:
× Before # features\support\hooks.js:46
Error: function timed out, ensure the promise resolves within 20000 milliseconds
at Timeout._onTimeout (C:\Users\Mo\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)
× After # features\support\hooks.js:60
ReferenceError: testController is not defined
Then I tried another gitHub project namely this one : https://github.com/kiwigrid/gherkin-testcafe
the run command in readme doesn't work for me, it doesn't even recognize the "gherkin-testcafe".
When I run my TestCafe test cases without the cucumber I have this line in my package.json
"scripts": {
"test": "testcafe chrome Tests/ -e --proxy https.proxy.mycompany.com:8000"
},
the proxy is mentioned because I am behind a proxy and without this the browser launches but does not run any test cases. I found this fix on testCafe site
I am guessing(not sure yet) this could be the issue with cucumber integration as well. None of these frameworks work as they don't set up the proxy anywhere. Can someone point me in the right direction? if the proxy needs to be set up then where in the framework does it need to go- an example would be helpful?

TestCafe/Cucumber integrations rely on starting TestCafe runner programmatically.
In the repo, search for this sequence:
const runner = tc.createRunner();
return runner
.src('./test.js')
.screenshots('reports/screenshots/', true)
.browsers(browser)
.run()
.catch(function(error) {
console.error(error);
});
or search for this sequence:
await runner
.browsers(browsers)
.specs(specs)
.steps(steps)
.concurrency(concurrency)
.startApp(app, appInitDelay)
.tags(tags)
.run(...)
Chain the useProxy method on runner object (do it before the run()method):
const runner = tc.createRunner();
return runner
.src('./test.js')
.screenshots('reports/screenshots/', true)
.browsers(browser)
.useProxy('username:password#proxy.mycorp.com')
.run()
.catch(function(error) {
console.error(error);
});

Related

Cypress/Next.js E2E test with --watch option works well, but failed with --headless

Thanks for the cypress team.
I have one issue with e2e headless test on command.
When I run the test with --watch option, it passes well.
But it is failed for the --headless option.
I need to run this on CI, so it has to resolve this issues soon.
Here are commands that I run.
yarn nx run checkout-e2e:e2e --watch
yarn nx run checkout-e2e:e2e --headless
I have 3 test files totally, and the specific thing is that the first test doesn't pass after long time delay(around 60 sec) but the rest ones pass.
Here is one code file to run.
The other files are almost same.
const classname = 'buybox--buy-box-example-one-size'
const url = `?path=/story/${classname}`
describe('BuyBox Example visual regression', () => {
it('Matches the snapshot', () => {
cy.visit(url)
cy.viewport(1000, 1500)
cy.get(`#${classname}`)
cy.get('body').type('S')
cy.get('body').type('A')
cy.wait(3000)
cy.get('body').matchImageSnapshot('buyboxOneSizeDesktopExample')
cy.viewport(375, 667)
cy.get(`#${classname}`)
cy.get('body').type('S')
cy.get('body').type('A')
cy.wait(5000)
cy.get('body').matchImageSnapshot('buyboxOneSizeExample')
})
})
My Dev Env:
Windows 10
VS code
Cypress 6.0.1
Node 14.16.1
Storybook 6.2.8
Here is the error screenshot in headless mode.
https://prnt.sc/131k32j
Please reply if anyone knows its reason and solution.
Thanks.
I've tried to solve this issue and found it finally.
Go to plugin/index.js and comment this line...
// on('file:preprocessor', preprocessTypescript(config))
Fixing e2e test failed on headless mode
I am not sure why this works for me but I hope that this will be helped for everyone who has same issue.
If anyone knows the reason of this solution, comment here please.
Thanks.

Next.js - Is it possible to debug getServerSideProps?

Hi as per docs getServerSideProps is a function which is executed only on server side.
export async function getServerSideProps(context) {
console.log("hello world");
debugger;
return {
props: {
age:55
}, // will be passed to the page component as props
}
}
As a consequence simply dropping a debugger keyword won't work.
I have tried:
Attaching the node.js debugger on port 9229
Running node --inspect-brk ./node_modules/next/dist/bin/next
Running cross-env NODE_OPTIONS='--inspect' next dev
But neither console.log() nor debugger keyword seem to have any effect.
However my props from getServerSideProps are passed in correctly, which proves the function is called.
Is it possible to stepthrough getServerSideProps or at least get console.log working? Thanks!
P.S.
The lines of code outside getServerSideProps are debuggable and work as expected.
In order to make the open the debug port open properly, you need to do the following:
// package.json scripts
"dev": "NODE_OPTIONS='--inspect' next dev"
// if you want custom debug port on a custom server
"dev": "NODE_OPTIONS='--inspect=5009' node server.js",
Once the debug port is own, you should be able to use inspector clients of your choice.
I had the same problem and I solved it with following steps. First, I installed cross-envpackage with
npm install cross-env
then I had to adjust my package.json with
"dev": "cross-env NODE_OPTIONS='--inspect' next dev",
After that you should be able to run npm run dev.
Open localhost:3000 or whatever port u are normally running nextjs app on. Open new tab and type
chrome://inspect
You should be able to see path to your app with word inspect at the end. After clicking new devTools will be opened with ability to set up breakpoints inside e.g. getStaticPaths, getStaticProps or getServerSideProps.

Next.js: How to disable telemetry permanently in all environments?

I want to disable Next.js telemetry in all environments, forever (Just because, Ok? Let's not sidetrack the question with irrelevant debate).
I don't want the telemetry to run on developer environments, test builds, CI builds or anywhere else.
I'm trying to find a "code" solution - I don't want to have to do anything manually in an environment in order to switch off telemetry.
Next.js makes it difficult to figure out if telemetry is enabled because it only prints the telemetry warning once on a given machine.
My diagnostic for knowing if telemetry is running is to add the next telemetry status command to my build script in package.json:
"build": "next telemetry status && next build",
I've tried adding the following to next.config.js:
module.exports = {
env: {
NEXT_TELEMETRY_DISABLED: '1',
},
}
And I've tried adding this to .env:
NEXT_TELEMETRY_DISABLED=1
But the telemetry command still reports Status: Enabled
In fact, the NEXT_TELEMETRY_DISABLED env variable doesn't seem to work at all, I tried manually disabling telemetry in my IDE by setting the env variable, but it still reports telemetry is enabled:
Next.js version: 9.5.2
Doco: https://nextjs.org/telemetry
Github issue: https://github.com/vercel/next.js/issues/8851
Adding next telemetry disable command as my prebuild script seems to have done the trick.
"prebuild": "next telemetry disable",
"build": "next build",

Deploy script for Meteor.com hosting via Codeship

I'm using Meteor's built-in hosting for staging, with Codeship handling the continuous deployment. All tests and notifications succeed as expected in Codeship, but nothing is getting deployed.
My script:
expect -c "set timeout 60; spawn meteor deploy staging.myapp.com; expect “Email:” { send $METEOR_DEPLOY_EMAIL\r; expect eof } expect "Password:" { send $METEOR_DEPLOY_PASSWORD\r; expect eof }"
When that script runs during the build process I see the following:
spawn meteor deploy staging.myapp.com
=> Running Meteor from a checkout -- overrides project version (0.8.1)
To instantly deploy your app on a free testing server, just enter your
email address!
ail:
The ail: isn't a typo...that's what Codeship displays. It appears it eventually times out and moves on, though no errors are shown.
First time setting up a CI server (and using Expect), so thanks in advance for the help!
Figured it out...had two syntax issues:
Left/right double quotation marks snuck in there (instead of
standard quotation mark)
Missing semicolon
So, for anyone looking for a script to deploy to *.meteor.com using Codeship, here is the working script:
expect -c "set timeout 60; spawn meteor deploy example.com; expect "Email:" { send $METEOR_DEPLOY_EMAIL\r; expect eof }; expect "Password:" { send $METEOR_DEPLOY_PASSWORD\r; expect eof }"

WebDriver + Protractor with grunt

I'm trying to run end-to-end tests with WebDriver and Protractor. No problem when I run it manually with:
webdriver-manager start
and then
protractor test-UI/e2e/conf.js
Now I would like to launch them from a grunt command, so I tried with grunt-shell, joining them with '&&'. But as WebDriver waits, tests are never started. Did someone try this before?
Thanks.
There is a fork of Grunt-shell called Grunt-shell-spawn (Github Repo) which allows you to run background processes asynchronously. This happens to work very well with starting the selenium webdriver server helping to automate the protractor testing process. There are a few grunt plugins specifically for starting the webdriver server but from my experience they all have small bugs that cause errors once the tests are finished or require you to mark a flag keepAlive: true which means it will not kill the webdriver server process forcing you to ctrl+c or close and re-open the command prompt which can cause a lot of issues when devs are using the functional tests and with continuous integration (CI) servers. Grunt-shell-spawn has the ability to kill the process as you can see at the end of my 'test' task which is really invaluable for maintaining consistency and ease of use.
'use strict';
module.exports = function(grunt) {
grunt.loadNpmTasks('grunt-shell-spawn');
grunt.loadNpmTasks('grunt-protractor-runner');
var path = require('path');
grunt.initConfig({
...
...
...
shell: {
updateserver: {
options: {
stdout: true
},
command: "node " + path.resolve('node_modules/protractor/bin/webdriver-manager') + ' update --standalone --chrome'
},
startserver: {
options: {
stdout:false,
stdin: false,
stderr: false,
async:true
},
command: 'node ' + path.resolve('node_modules/protractor/bin/webdriver-manager') + ' start --standalone'
},
});
grunt.registerTask('test',[
'shell:updateserver',
'shell:startserver',
'protractor:e2e',
'shell:startserver:kill'
]);
You can to install grunt-protractor-runner
npm install grunt-protractor-runner --save-dev
Check this blog with details
http://www.codeorbits.com/blog/2014/01/26/angularjs-end-to-end-testing-with-protractor-easy-set-up-with-yeoman/
Try running grunt --verbose to see more details on whats happening.

Resources