Can't download a pdf file in npx cypress run --headed mode? - javascript

Hope to get some help with what is my first question to the community...
I'm using the Tricentis Sample App to practice some testautomation with Cypress (javascript) and I'm having issues with the final step. (Downloading the mock invoice and checking the presence of it in the downloads folder)
//This function displays the "download pdf" button
function selectPriceOption(cy){
cy.get('#selectplatinum').check({force:true})
}
//this function is supposed to download the pdf
function downloadQuote(cy){
cy.wait(2000)
cy.get('#downloadquote').click()
cy.wait(20000)
}
//This function checks if file exists in the download folder
function checkFileExists(cy){
cy.readFile('C:/xxx/Documents/cypress/downloads/Tricentis_Insurance_Quote.pdf')
}
module.exports = {
enterAutoPage,
enterVehicleData,
enterInsuranceData,
enterProductData,
selectPriceOption,
checkFileExists,
downloadQuote
//sendQuote
}
When I'm running the script on npx cypress open mode, it downloads the pdf generated without a hitch. But as soon as I use npx cypress run --headed it doesn't manage to download the pdf file and as a consequence the test case throws a fail... Btw, I know the cy.wait command is not needed, it was just my last attempt to see if it needed additional waiting time. Still didn't work!
Now, here's what bugs me... If I run the script in open mode first, the download is successful and if I then go for the "run --headed" mode afterwards, it finds the file! I'm running trashAssetsBeforeRuns: false in the config file. So the check file function is working as intended. But when the folder is empty and I only use --headed mode then the download is NOT successful and the test case fails due the file is missing when the script reaches the last test step. I hope this explanation makes sense... #newbietechnicaltester
PS: Leaving the possibility open to something funky going on with the Tricentis site that is causing the code to not work as intended

Related

VS Code Terminal not running

when I go for console.log("hello world") my vs code terminal is not working unless I switch to java script debug terminal?
any one who know the solution please help
Try this ===>
1 Type node in terminal
2 console.log("Hello World")
Its pretty simple, just 2 clicks away
=> 1. Click on File
=> 2. Click on Auto Save
Option 1: Make sure that you installed Node.js After that, you need to type in Terminal window: node [whateverYourFilenameIs], click entre. //you type the word node, followed by your filename without the square brackets.
Option 2: Make sure you installed Node.js and install the VSCode extension Code Runner, restart VSCode, click on ctrl+Alt+N to run your file in terminal.
It is simple
write some code example: console.log("javascript");
ctrl +s
on terminal node and your js file name ...click enter ....and there will be no error

Having trouble with http-server ,the computer keeps downloading the file and not loading the html file I need

I tried created a server to load a html file when I use javascript with Babel, I follow the instruction: I download Node.js, then npm install http-server, then copy the path into command prompt as "http-server [path] " then command prompt return "Starting up http-server, etc.. Available on "127.0.0.1" but when I enter it into the browser, the browser keep asking me to download the file into computer and not loading anything in the screen. Every step I follow is okay except the last part, I stuck at it for days, please help, I am having serious trouble with my company because of it, I never have it before.
I tried:
-Check the path to the file into my computer, doesnt work.
-Re install http-server
-Watching several tutorial on youtube, each step i exactly the same, except the last and most important part, the file just not loading and keep downloading that file again into my laptop.

Can i run protractor e2e sanity testsuit from the UI by clicking html button

enter image description hereReq: Build one testing page (Using Html&css), where anyone can run the protractor test case by click on "run" button.
so I want to integrate HTML button with protractor script. plz, give me any lead on the solution.
(but dont want use php so can )
conf.js
exports.config = {
framework : "jasmine",
directConnect: true,
specs : [
"./spec.js"
]
};
spec.js
describe('prot', function () {
it('test', function () {
browser.get('https://angularjs.org');
// element(by.model('todoList.todoText')).sendKeys('write first protractor test');
});
});
page.html
<!DOCTYPE html>
<html>
<body>
<button>Analytics Sanity</button>
<script src="server.js"></script>
</body>
server.js
const shell = require('shelljs');
shell.exec('./bash.sh')
bash.sh
#script1.sh
clear
echo "Starting shell script";
protractor conf.js
echo "ending of the script";
cat script1.sh
couldn't attach the image to the comments
this is what jenkins may look like
non technical people save the bookmark to the page, open it whenever need to run tests, specify all desired parameters from available dropdowns/inputs/checkboxes
and click Build button to run the tests
Reports are also available within the jenkins along with screenshots and video recordings. Capabilities include sending email or slack notifications, history of execution etc.
I think this covers what you need and much more and most of the functionality comes out of the box. For others, you just need to install existing jenkins plugins
The method I've used to run the e2e protractor script using an html button is with the help of a HTA application

How can i debug a nodejs backend with node-inspector?

I am trying to debug my backend and i am not really sure if i am doing it the correct way.
I have set up the debugging as follows:
Node 6.9.1 and node-inspector 0.12.8
open a command prompt and run the following command:
node-inspector --web-port=3030 (server app port)
open another command prompt and run the following command:
node --inspect --debug-brk server.js
browse to the given URL in the second command prompt log on screen
press F8 to make the server run
eventually put some others breakpoints
browse on another tab to your app (address and port defined in 1-)
see server execution stops on breakpoints defined on step 5.
Now when i run node --inspect app.js and everything looks good so far. I can debug the first start in the app.js. But if I want to debug an endpoint with POSTMAN, I get the error "Cannot POST /api/trainingsWeek". The endpoint works if I don't debug.
Do I have to take another address? Or another tool than POSTMAN?
ANd what is the difference between node --inspect app.js and node-debug
GitHub Issue
UPDATE
This was my stupid mistake :P Here is the solution: https://github.com/node-inspector/node-inspector/issues/907#issuecomment-280620108
I use VS Code to debug. I guess you don't need node-inspector, it will run with the integrated debugger from Node. To get it running, open your project and the debug view. There should be no configuration available. Click on the little wheel -> choose node.js as the environment.
After that the standard json will be created and looks like this:
And then click on the play button with the selection start programm. With that the debugging should run. Now you can use POSTMAN with the same url when you just run your server and the debugger from VS Code should hit your breakpoint.

NodeJS fs.open failing on existing file (not a path issue)

I've been dealing with this for a long time, so any help is much appreciated. So, I'm downloading a file and saving it using PhantomJS and CasperJS. Let me point out that they aren't the issue. The file is downloaded without a problem.
The problem is that NodeJS won't recognize or open the file after it is downloaded. I can't fs.stat, fs.open, etc.. Nothing works.
I'll share the code in a second, but here's the log:
Here: bdTcK6hSdownload.csv
[ '2puzZMeLdownload.csv',
'2s5ICbKNdownload.csv',
'bdTcK6hSdownload.csv',
'izIfagwCdownload.csv' ]
fs.js:230
return binding.open(pathModule._makeLong(path), stringToFlags(flags), mode);
Error: ENOENT, no such file or directory './caspertemp/bdTcK6hSdownload.csv'
at Object.openSync (fs.js:230:18)
at Object.processCSV (/Users/Home/dev/node_modules/inviter/index.js:64:29)
at /Users/Home/dev/node_modules/inviter/index.js:36:33
at ChildProcess.exithandler (child_process.js:281:7)
at ChildProcess.emit (events.js:70:17)
at maybeExit (child_process.js:361:16)
at Process.onexit (child_process.js:397:5)
As you can see, I'm printing out the created file name, then printing the contents of the directory and then trying to open the file. As you can see, bdTcK6hSdownload.csv exists in the directory but fails on open.
The simple code snippet is here:
console.log('Here: ' + filename);
filenames = fs.readdirSync('./caspertemp/');
console.log(filenames);
var fd = fs.openSync('./caspertemp/' + filename, 'r');
console.log(fd);
There's a bunch more going on before and after this but none of it matters since this basic function fails. Please help! This has been nagging for weeks.
My guess is that it's a discrepancy in current working directory. Are you starting the casperJS and node.js processes from the same directory? Do either of them change working directory at runtime? Try something like this, where node's __dirname will give you the directory path of the currently executing .js file
var path = require("path");
var filename = "bdTcK6hSdownload.csv";
var csvPath = path.resolve(path.join(__dirname, "caspertemp", filename));
console.log(csvPath);
Another possibility is timing.
I've had situations in the past where a file entry appears in the folder straight away but the file is unusable as the thing writing it has either not finished or not yet released it's handle. Under those conditions it isn't unusual to need to either defer processing or to do some other checks to see if things are ready.
On those occasions it may be that a restart 'fixes' things but only because as a side effect it either releases the handle or delays processing, so when your code trys again it's all fine.
This occurs only when you are giving wrong path. I have come across the same problem.
Initially I was running the file directly node xyz.js and required static files are in same repository. But When I do npm start, code was throwing above error :
fs.js 495
return binding.open(pathModule._makeLong(path), stringToFlags(flags), mode);
**Error: ENOENT, no such file or directory**
Then I moved static resources, renamed path and It worked. Hope this may help you.
File extension could be entered twice hence not found. Navigate to the file directory with your command prompt and get the list of files in that directory
command:
dir
or
ls
Get the actual file name there and use it. In my case I had saved a text document as "readMe.txt" and on command prompt it appeared as "readMe.txt.txt". I did not have to append the file extension when saving and this created the problem.

Categories