How to debug a single Nightwatch JS test in Visual Studio Code - javascript

I am QA Engineer with very minimal developer experience. My skills are limited to writing automated tests and in my time I have always used Visual Studio Enterprise (with selenium webdriver) and TestComplete IDE's with their in built debugger. I have recently made a move to something new and want to get to grips with Nightwatch JS for my end to end tests. I have written some tests and they are running fine. However, I am now at a stage where a test is failing and I want to debug just that one test. How I would do this??? Usually in VS enterprise or TestComplete, I would just pop a break point on a line of code, right click on the one test script and it will pause at the break point.
For my Nightwatch JS project I have used Visual Studio Code. I know that I can run a single test by opening the terminal in VS Code and running the command "nightwatch tests/folder/path/myTest.js". There is not much help on nightwatch out there that has helped me and the only post I found on here was this one but it has not solved my problem. Because when I click the debugger "Play" button it starts to run ALL of my test not the one test I am interested in.
I have tried to play the debugger and then in the terminal run my cmd for the one test but the test will run through and does not hit my break points. Any guru's out there that can help?
Please ask away if you need me to post any information.

You can pass additional options for Nightwatch in your terminal, such as -- --tag.
So, you can tag each single test file you have, like this:
module.exports = {
'#tags': ['iamatag'],
'[EXAMPLE TEST]': (client) => {
code
code
code
}
};
Then, in your terminal, you would run:
$ npm test -- --tag iamatag
Only tests with the tag 'iamatag' will run.
Cheers.

Related

JavaScript on Visual Studio Code - is Node required to run a file?

I am currently trying to catch up with some JS basics, before continuing with my node.js-project.
I wanted to execute the file and kept getting the error 'console is not defined', when I wanted to use console.log('Hello!')
The only helpful way to run the file normally was with: node ./myjsfile.js
I installed node.js for that node project.
But for just running super basic JavaScript I don't want node.js.
What are better (lighter!) ways to run my JavaScript files inside Visual Studio Code?
Like what's the most basic way to do it?
No, if you do not currently have Node, you will not have the 'play button' to run the code. So, if you go to Run in the toolbar at the top, you should see some options to run the file.
I'm pretty sure you can just press F1 and then Run Code

Error message is popping up when running js in vscode

I just started to learn Javascript. I decided the best thing to use was vscode, as I use it for other programming projects. But when I do even a simple statement which I know is right, such as "console.log('hello world')" it gives a error message. Something along the lines of file "c:\Program Files\ Python39\lib\run.py.py" , line 197, in _run_module_as_main. I have tried making a new JavaScript file, and install additional support for js. But It did not work. code:
console.log('hello world')
I think you should start learning by using chrome or firefox console.
Chrome Detail
Firefox Detail
If you want to run JS file on VSCode you can simply go ahead and install node on your machine, and use it run js code in the terminal. Just google it how to install and then use command node <fileName>.js and this will do the job. And in case you don't know how to open terminal in vscode just use command: ctrl + `

Is there an "immediate window" in Visual Studio Code to run Javascript?

Yes, I use F12 in the browser all the time to test out Javascript snippets with the console. I'm tired of that (for the moment anyway).
I've read that in Visual Studio you can use the immediate window to run Javascript interactively.. I've haven't tried it that hard. I think when I did it told me it can't evaluate while in design mode... ugh, what a pain.
I do like to use Visual Studio Code (sublime text historically) sometimes to just mess around with syntax of snippets. Would also be nice if I could just run Javascript there too quickly. Is there a package I could download in VSCode to do so? Or something already built in?
As of (at least) my current version of VS Code (1.5.2), the "Debug Console", while debugging, lets you run arbitrary JavaScript code as you would in the VS Immediate Window. (Similar to as you would for the Chrome Dev Tools Console.)
There is no Immediate Window unlike Visual Studio in VSCode. But you can still execute Javascript in VSCode.
Install the Code Runner Extension - https://marketplace.visualstudio.com/items?itemName=formulahendry.code-runner
Open the JavaScript file in VSCode, then use shortcut Ctrl+Alt+N, the code will run and the output will be shown in the Output Window.
I've found this extension that makes a scrathpad for JS, that runs at the same time as you are typing: https://quokkajs.com/
Works on VS Code, Jet Brains, and Atom.
If you don't want to start a debugging session or installing an extension, a simple way to have a JavaScript console is to start Node in a Terminal.
View -> Terminal
Start node (without any argument -you'll need node in your PATH)
Now you have a repl with auto-complete and value preview.
It doesn't have the features of the Chrome Console, but I find it good enough for evaluating JS code while I'm working.
Run the command node in the terminal below the editor, this will create a node environment where arbitrary JavaScript can be entered. You must first have node (and apparently npm) installed from nodejs.
This might do it: https://code.visualstudio.com/Docs/runtimes/nodejs
Node.js is a platform for building fast and scalable server applications using JavaScript. Node.js is the runtime and NPM is the Package Manager for Node.js modules.
To get started, install Node.js for your platform. The Node Package Manager is included in the Node distribution.

Why do frameworks and git hub ask you to use Terminal?

I'm a newbie and that's ok.
But when I use tutorials, they always tell me to go straight to my terminal and install documents from there in which I have no clue what the next step is and no idea why I have to do it. Is it essential that I install frameworks through terminal or can I just work without it?
ex. http://net.tutsplus.com/tutorials/javascript-ajax/real-time-messaging-for-meteor-with-meteor-streams/
"Let’s create a very simple, browser console based chat application with Meteor Streams. We’ll first create a new Meteor application:"
meteor create hello-stream
I understand this is may not be very challenging, but I don't have a clear answer when I try and simply google it. Anything would help, thanks a lot!
Being a newbie is ok.
The terminal is the go to because writing programs, tools, and scripts with a couple lines of bash or python is, well, a couple of lines versus an entire gui and all the lines of code to go with it.
meteor create hello-stream
That's telling you to run the program called meteor with the supplied arguments (create hello-stream).
If you haven't installed meteor, do that next. From their website, open your terminal and type/paste:
curl https://install.meteor.com | sh
That downloads a file from the URL and pipes (|) it to the sh command. The file it downloads is a shell script that takes care of setup/installation. Now go back and try the meteor command again.
More reading
You might try and find a terminal tutorial. This is the first one I found:
http://www.ee.surrey.ac.uk/Teaching/Unix/
Answer from someone who only recently (as in: within the last year) got into using the Terminal more and more frequently:
It's generally a good idea to get used to using the Terminal for code-related things as you can pretty much use it platform-independently (meaning you can use the same commands on Mac, Linux, Windows,...) and because it makes you understand better what you're actually doing.
Once you've got the hang of it, it can make navigating your system as well as making changes to it easier. Hidden files, for example (like .gitignore files, or files in your .ssh directory, or your .bash_profile), can be viewed, opened and edited easily from the Terminal whereas you have to take multiple, complicated steps (or install other software) to view them from your Finder.
With the help of package managers (like Homebrew), which are also operated from the Terminal, you can also install software that isn't otherwise available for Mac.

Continuous Integration of JavaScript Tests with MSBuild / Visual Studio

Is there a way to get JavaScript tests to do continuous integration with MSBuild or in Visual Studio? What I want to do is have it so anytime my JavaScript or my JavaScript tests change they are built again and ran and if they fall below certain values of acceptance criteria (code coverage, assertions passing, test's passing, etc.) it'll fail my build. Anyone know how to do this?
Thanks!
It looks like Chutzpah has a command-line runner, so you can create a PowerShell script which gets called from your build server to run the tests. See the Chutzpah documentation for more information. I'm not sure how you would integrate the test results with TFS.
I've used a Command Line build step to run my javascript tests with chutzpah.
Add this and point to something like
$(Build.SourcesDirectory)\packages\Chutzpah.4.0.3\tools\chutzpah.console.exe
or whereever you have chutzpah setup to be run on build server. You can then add an argument to tell the chutzpah console where the tests are
$(Build.SourcesDirectory)\YourApp.UnitTests\Tests**strong text**

Categories