Getting started with nightwatch.js - node.js

Can anyone provide me with a detailed explanation on how to setup nightwatch and start writing browser tests? I have searched for such information online and was unable to find it. The nightwatch.js website had good information about various nightwatch command line commands, but not about actually setting up a nightwatch project, which is what I am having trouble with.
Specifically, I do not have a good understanding of the various files that come with installation of nightwatch, and how I am supposed to use them.

Step-by-Step Beginner's Tutorial
We needed an up-to-date, well-researched and maintained tutorial for Nightwatch for our team so we wrote one: https://github.com/dwyl/learn-nightwatch
We (highly) recommend using a nightwatch.conf.js (.js) file for configuring Nightwatch because (unlike a .json file) it allows you leave in-line comments to your fellow developers (i.e avoid "WTF" moments by communicating) and to evolve your configuration with variables & functions as needed.
Also, we prefer to install Nightwatch (and its required dependencies) locally so it's clear to everyone exactly what is required to run the project and which versions we are using.
Using the selenium-download module will download the latest versions of Selenium Standalone Server and Chromedriver (both required to run a basic Nightwatch test) for your OS and means you will be up-and-running much faster.
Rather than including the whole tutorial here we invite you to Star/Fork it on GitHub: https://github.com/dwyl/learn-nightwatch#step-by-step-tutorial
Feedback / questions / updates / improvements are always welcome!

You need basiclly two things:
The nightwatch.json file in the root of your project
And nightwatch installed (npm install -g nightwatch).
After that you use it on the command line as described in the documentation here and it will automatically grab your nightwatch.json file and run your tests based on the default test_setting.
I opened up an issue to add a nightwatch init command, so the setup of the nightwatch.json file is easier.
Further reading
How to setup nightwatch.json
Github Repository

You can go through this step-by-step method to get better understanding
Nightwatch.js Part 1
Nightwatch.js Part 2

one big problem for users "is not worked on count 1-2-3".
so we find many-many-many times our all internet :)
and.
1) nightwatch is installed (by .rpm, .deb, npm, downloaded). is haven't questions
2) is worked by execution "nightwatch" on CLI
3) but where wunderbar example?????????????
of course, on internet!
4) by my bad memory and catalog list in simple test:
- create catalog
- create in catalog 2 dirs:
bin for web-drivers (add chromedriver, selenium-server-standalone as minimum)
tests for tests
5) we need this simple config - nightwatch.json in catalog (use any simple which access have)
6) create-copy-paste any simple test in test catalog (it's one on planet :)
7)it's all, run in catalog by CLI: nightwatch
you need only this? for first time, before documentation readings? ;)

$ npm install -g yo
$ npm install -g generator-selenium-nightwatch
$ yo selenium-nightwatch
$ npm install
$ npm test

Related

Missing module "aws-exports" among other Amplify and AWS files

I was sent a "trial project" by a company looking to hire. It's a simple project but uses Amplify and AWS. The CTO told me I need to have a certain version of Node (10.18.1 or 10.19.0) and that I should run yarn install and everything will be good to go. So I completely uninstalled Node, installed NVM and the version of node I'm supposed to use. Then I opened the project and ran yarn install.
When I open the project in browser I am apparently a module, ./aws-exports, among other files that seem to be related to Amplify and AWS. I've noticed that most of these files are in the gitignore. But again, the CTO told me that I shouldn't have to do any setup.
I've tried installing with Npm instead. Using different versions of node. All sorts of silly little fixes and I'm just totally lost.
The file ./aws-exports will be created after the initialisation of Amplify
(https://aws-amplify.github.io/docs/cli-toolchain/quickstart?sdk=js#the-init-process)
It is in .gitignore because it contains configurations information of the AWS account, which you have configured in your terminal.
Does the project have a README? If so, read that. If not, don't work there.
Google the missing package name. If you find nothing, it is likely a private package.
A quick Google search gets me this: https://bit.dev/bondz/react-epic-spinners/orbit-spinner
And this: https://docs.bit.dev/docs/installing-components#configuring-bit-registry
Use Google.

Do I need to run the command npm install every time I want to compile my project?

I am currently working on a project at a large company, and according to the project I am working on, every time I want to quickstart the app, I would need to first run the command npm install and then run all the additional compiling instructions, but the problem is that running npm install can take a long time, and that is why I am wondering if it is necessary to run this command every time I make a change to the code, and then want to compile and run it.
What exactly does npm install do? If you could explain to me in terms of how we compile and run java code i.e. javac bob.java && java bob and try to make analogies on that basis, that would greatly help me understand the concept. The way I am currently thinking about it right now is that npm install kind of runs like how javac runs, but I am not sure if that is correct. Thanks in advance!
NPM Install
npm install simply reads your package.json file, fetches the packages listed there from (usually) https://www.npmjs.com/, and sometimes engages in the build steps for those packages.
So you only have to run npm install when you change your package.json file, and need to fetch new dependencies.
Keep in mind that npm install --save <packagename> (or npm install -S <packagename>) will update your package.json and run npm install all in one line!
You can view the results of your npm install inside ./node_modules/.
To compare to java
This might be a helpful resource if you're trying to get stuff done: Getting Started with Node.js for the Java Developer
Javascript is not a compiled language, unlike java. When you invoke javac, the java compiler reads in all your .java files, compiles them to java bytecode, and then writes them to .class files, which can then be bundled together into a .jar for execution.
Javascript doesn't do any of this! When you invoke node foo.js, the node executable wakes up, reads foo.js, and gets to work invoking it line by line**. Node does other cool things, including maintaining an event loop (which allows it to operate "asynchronously", and allows it to be very efficient as a webserver-- it doesn't sit around waiting for requests to complete, it carries forward with the next event in the queue.
Node also performs JIT and optimization, these details allow it to improve the performance of sections code it notices are running "hot".
Note also that node.js uses the V8 javascript engine (also used in Google Chrome). Really everything I've said above is handled by V8.
(** Technically there is a syntax checker which is run first, before execution. But this is not a compile step!)
It is not necessary to do "npm install" each time you want to compile. You just need to do it when you change the dependencies of your project.
NPM basically is the package manager for node. It helps with installing various packages and resolving their various dependencies. It greatly helps with your Node development. NPM helps you install the various modules you need for your web development and not just given you a whole bunch of features you might never need.
When you start an app, it comes with a package.json file. That package contains the list of node_modules you are gonna need. Whenever you enter npm install, what you are doing is to download that list of node_modules. So yeah, you have to download the modules all over again.
#NOTE: In your project, you have a file called package.json. this file is responsible for holding track of your project's dependencies. That's why you have to install it every time#.

How to automate testing user-version of npm package instead of running the development version on continious integration?

It happens occasionally that the development version of a module works in my development workspace and passes on Travis-CI but after publishing to npm it turns-out the end-user package is broken.
For example if you use a sub module that should be in dependencies but had it in devDependencies then CI will pass (but there are plenty other possible breakages).
How do you automate testing this? Do you use external rigging? Is there a secret module? Do you have a user acceptance test suite?
I use Github with Travis-CI but the standard setup uses the development install.
Once upon a time I discovered that npm would let me publish packages that are uninstallable. So I've added a target to my Gruntfile that does this:
Issue npm pack to create a package from my source.
Into a directory created (automatically by my Gruntfile) just for testing install the new package using npm install <path to the package created in the previous step>.
I have a target for publishing a new version that will publish only if the steps above are successful.
The steps above would not catch the dependency problem you mentioned in the question but they could easily be extended to catch it. To do this, I'd add one or more tests that cause the package installed in step 2 above to call require with all that it depends on.
I would suggest to set up your own CI server that does essentially one thing, npm install package ; cd node_modules/package ; npm test. This would ensure that your package is installable at least on your server.
I heard that Jenkins is good for this (at least, that's what node.js core team seems to be using), but don't have any first hand experience yet. We're just planning to set in up in a couple of weeks.
Also, having some external module that depends on you and testing it helps a bit. :)

Dependency management for nodejs that controlls versions of not just modules, but npm and node itself

It seems that npm does a good job at managing the dependencies
of modules for a given project, with declarative dependency
management (in the package.json file).
I would like to go one step further, and declaratively
control which version of nodejs and npm from source control
(i.e. specifying these versions in some file that is
in the project' git repo, just like package.json)
On a freshly deployed machine, I would like to have only these steps :
1) clone a git repo of the nodejs project
2) install or update the versions of npm and nodejs
3) npm install
I woud then use this to have a single step deploy/update
probably a script that does (2) and (3) and that feeds
from a config file that is source controlled.
I'd be perfectly satisfied with a solution that only works on linux,
or even for a given flavor of linux
Take a look at what Nodejitsu does with their Package.json. In particular you will see the following lines:
"engines": {
"node": "v0.8.x"
}
Then take a look at the Node Version Manager available here. There's a reasonable write-up on basic usage here.
Given that your deploys should all have a package.json this seems like a pretty straightforward method to achieve what you're looking for. Should be a limited amount of "glue" code and it's clearly possible as Nodejitsu is doing it.

How to do a dojo build using nodejs?

I'm currently using the dojotoolkit and its build system.
I read the new build tutorial for 1.8 at http://dojotoolkit.org/documentation/tutorials/1.8/build/.
In the tutorial it mentions that you can speed up your build by using nodejs.
The build tool itself relies on Java (and, optionally, Node.js for even faster builds), so make sure that have you that installed as well.
But it fails to mention how to do this. Anyone know how this works?
I normally run it like this:
> node dojo/dojo.js load=build --profile myprofile.profile.js --release
This would build a release for the profile contained in myprofile.profile.js. It assumes you are in a directory, which contains both dojo and util as sub-directories. It also assumes that the path to node is set correctly.
If node is not configured in the path variable, you will need to use the full path to node:
> <path to node here> dojo/dojo.js load=build --profile myprofile.profile.js --release
On windows the path is normally C:\Program Files\nodejs\ but you might have to configure it as C:\PROGRA~1\nodejs\ to get it working.
Windows Notes:
The build scripts do not work with Node on Windows (except using Cygwin). If you are using Windows you can get it to work via the following patch:
Windows Patch
Use the attached node-win.patch file to edit the files: util/build/main.js and util/build/transforms/writeOptimized.js. The patch has worked for me 100% of the time and it a simple matter editing a few lines of code.
I've personally found the alternative to Node, using Rhino, useless. It always fails to detect the build paths correctly, no-matter what I set basePath to. I would strongly advise using Node over Rhino as it is more reliable and easier to setup.
The buildscript util/buildscripts/build.sh checks if node is in your path and if so uses it.
This is currently not working under Windows (http://bugs.dojotoolkit.org/ticket/15413).

Resources