Because after the year began to study Appium framework, because Appium client is written with Node.js, so to learn about node.js knowledge. installation
Download the installation package installed on the line, after installation after the CMD knock down the following command:
D:\node.js\0210>node-v
v0.12.0
If the version number is displayed, it means that the installation was successful. Helloworld Direct command Line
D:\node.js\0210>node
> Console.log (' HelloWorld ')
HelloWorld
undefined
>
file
Recommended in this way
Create a new JS file, named Helloworld.js
Then navigate to the directory where the file is located in command line mode, and then execute the command
D:\node.js\0210>node helloworld.js
HelloWorld
d:\node.js\0210>
assert
Create a new assert.js and enter the following:
var assert = require (' Assert ')
fail
Assert.fail (actual, expected, message, operator)
Will always throw an exception
var assert = require (' assert ')
assert.fail (5,5,null, ' = = = ')
assert.fail (5,5,undefined, ' = = = '
) Assert.fail (5,5, "test", ' = = = ')
Output after the node command is executed:
D:\node.js\0209>node assert.js
assert.js:86
throw new assert. Assertionerror ({
^
Assertionerror:5 = = 5 at
object.<anonymous> (d:\node.js\0209\assert.js:2:8) At
Module._compile (module.js:460:26) at
object.module._extensions. JS (module.js:478:10) at
module.load (module.js:355:32) at
function.module._load (module.js:310:12)
At Function.Module.runMain (module.js:501:10) at
startup (node.js:129:16) at
Node.js:814:3
Then we annotate the second line:
var assert = require (' assert ')
//assert.fail (5,5,null, ' = = = ')
assert.fail (5,5,undefined, ' = = = '
) Assert.fail (5,5, "test", ' = = = ')
At this time we are doing the same result as above. shows that null and undefined are the same effect. This time we annotate the third line:
var assert = require (' assert ')
//assert.fail (5,5,null, ' = = = ')
//assert.fail (5,5,undefined, ' = = = '
) Assert.fail (5,5, "test", ' = = = ')
This time the output is not the same:
D:\node.js\0209>node assert.js
assert.js:86
throw new assert. Assertionerror ({
^
assertionerror:test at
object.<anonymous> (d:\node.js\0209\assert.js:4:8) At
Module._compile (module.js:460:26) at
object.module._extensions. JS (module.js:478:10) at
module.load (module.js:355:32) at
function.module._load (module.js:310:12)
At Function.Module.runMain (module.js:501:10) at
startup (node.js:129:16) at
node.js:814:3
d:\ Node.js\0209>
So from the example above, fail asserts that whatever the parameters are, it will jump out of the execution of the program, except that the printed exception information is different. Construction Method
ASSERT (value, message)
Determines whether the first parameter value is true, jumps out the program if it is not true, and prints the message
The above is called the construction method, because I think it uses assert itself, not joined. Number to invoke the method. So let's use the construction method to define the bar.
var assert = require (' assert ')
assert (2>3, ' 2 not bigger than 3 ')
To execute the program:
D:\node.js\0209>node assert.js
assert.js:86
throw new assert. Assertionerror ({
^
assertionerror:2 not bigger than 3 at
object.<anonymous> (D:\node.js\0209\ assert.js:5:1) at the
Module._compile (module.js:460:26) at
object.module._extensions. JS (module.js:478:10) at
module.load (module.js:355:32) at
function.module._load (module.js:310:12)
at Function.Module.runMain (module.js:501:10) at
startup (node.js:129:16) at
node.js:814:3
D:\node.js\ 0209>
If we reverse the position of 2 and 3, it will not throw an exception.
var assert = require (' assert ')
assert (3>2, ' 2 not bigger than 3 ')
D:\node.js\0209>node assert.js
d:\node.js\0209>
OK
Assert.ok (value, [message])
Is the same as the way it was constructed. Equal
Assert.equal (actual, expected, [message])
To determine if the values of actual and expected are equal, and if not equal, throw an exception and print the message
A shallow test is equivalent to using ' = = ' to make an equal judgment
The following program at first look a bit confused, mainly to detect whether Hello and hello1 are equal, if not equal to print Hello2, and throw exceptions, then Hello and hello1 nature is not equal. That executes the following program throws an exception
var assert = require (' assert ')
assert.equal (' Hello ', ' hello1 ', ' Hello2 ')
D:\node.js\0209>node assert.js
assert.js:86
throw new assert. Assertionerror ({
^
Assertionerror:hello2 at
object.<anonymous> (d:\node.js\0209\assert.js:2:8) At
Module._compile (module.js:460:26) at
object.module._extensions. JS (module.js:478:10) at
module.load (module.js:355:32) at
function.module._load (module.js:310:12)
at Function.Module.runMain (module.js:501:10) at
startup (node.js:129:16) at
node.js:814:3
D:\node.js\ 0209>
notequal
Assert.notequal (actual, expected, [message])
Shallow test, equal to use '. = ' Make unequal judgments
Contrary to the equal logic
Using the above example, just change the equal to NotEqual:
var assert = require (' assert ')
assert.notequal (' Hello ', ' hello1 ', ' Hello2 ')
The above code executes without an error, because HELLO!=HELLO1
D:\node.js\0209>node assert.js
d:\node.js\0209>
Want an error? If you want, you can change hello to Hello1. deepequal/notdeepequal
Depth/non-depth matching
What do you mean. What is the depth?
That is, if it is an object, the attributes inside are matched.
so notdeepequal is not a depth match.
Of course not, still used is the depth matching principle, jump out of the program logic is not the same, notdeepequal will be in 2 object properties are equal to jump out of the degree. As for the two methods I do not give examples, because I do not know how to define the object. strictequal/notstrictequal
Using the strict matching principle
What is a strict match?
is to use the = = = Symbol for equality,!== to represent the unequal.