1. What is Nightwatch?
● Nightwatch is an end-to-end automation testing framework for web applications.
● It is written in Node.js and supports Selenium WebDriver.
● It makes our continuous integration testing simpler.
2. How an Application Works?
An application runs due to:
○ Client-side scripting
○ Server-side scripting
3. Client-side scripting?
● Anything that is seen at frontend.
● To develop the front-end, you must equip yourself with HTML, CSS, and
JavaScript.
4. Server-Side Scripting
● Which we can’t see but happening when we interact with the frontend.
● PHP, Ruby on Rails, Python are examples of server-side scripting.
5. Why Node.js?
As JavaScript is a widely used Client-side language, so we require similar Server-side
scripting that must be
● flexible,
● lightweight
● efficient.
Node.js is a server-side implementation of JavaScript. It allows the user to write backend
of the application
6. What is NPM?
● Node package manager, also known as npm, is used to install and configure
node applications and packages.
● npm is the default package manager used for the JavaScript runtime
environment Node.js.
● NPM can be install using npm install
EXERCISE 1:-
Nightwatch Notes
Ans:- Javascript
Ans:- HTML,JAVASCRIPT,CSS
Ans:- Node Package Manager
7. How to create a node application?
Generate a node application using express-generator:
npm install express-generator
This command will generate a node application. Use this command to install globally.
npm install -g express-generator
EXERCISE 2:-
Ans:-npm install express-generator
Answer:- Option 2
Ans:- global installation
Ans:- middleman and template engine
8. Nightwatch - Architecture
This architecture gives you a visual flow of Nightwatch.
● First, your script will reach the test runner.
● The test runner details are defined in the configuration file.
● Test runner will make the script ready for the selenium driver.
● Selenium driver will read the following requests from test runner:
● Which browser is called?
● What framework is defined?
● And other execution details.
● After reading the config file, it will approach the respective browser for
execution.
9. Install Nightwatch
When we type npm install, a node module is created. If we search for the nightwatch
folder inside the node module , we won’t get it. To create a folder we have to install nightwatch
using below syntax.
npm install nightwatch --save-dev
10. Drivers for Nightwatch
Download all the drivers and place it in the./bin folder.
11. Configure Nightwatch
Nightwatch configuration is written in json format. Let's create a folder name nightwatch.json.
EXERCISE 3:-
Ans:- Google chrome
Ans:- cli-args
Ans:- bin
Ans:- False
Ans:- conf.js and JSON both
Ans:-src_folder
12. First Script
13. Run script
npm run test-e2e
EXERCISE 4:-
Ans:-Option a
Ans:- Option c
Ans:- an object
Ans:-Scripts
14. Xpath
XPath is defined as an XML path, which is used to define the path of the element from a
web page.
XPath Syntax
xpath=//Tag_name[@attribute_name=‘value’]
XPath can be written in two ways:
● Relative XPath
● Absolute XPath
Basic Absolute Xpath
XPath using Contains
Multiple Attribute
XPath using AND/OR
And:- //*[@id='login_id' and @name='login']
Or:- Xpath=//*[@type='image' or @name='login']
XPath using starts-with()
For Booking site: When we book a ticket, it generates a unique code, which starts with a
defined Code like PNR_XXXXXX followed by some digit.
Start with:- Xpath=//*[starts-with(@id, ‘PNR’)]
EXERCISE 5:-
Ans:- //Tagname[@attributename=‘value’]
Ans:-//*[@attribute='value'][@attribute1='value1']
Ans:-/html/body/div/input
Ans:- //*[starts-with(@attribute, ‘value’)]
15. XPath using Axes Method
Following
//*[@name='userName']//following::input[1]
Ancestors and Parent
When you hear the word ancestors, the first thing probably that comes to your mind is
your grandparents and their parents.
Here Ancestors refers to the same, node parent and parent's parent.
<tr> Ancestors will be <table> and it has two ancestors.
<tr> has <tbody> as parent or node.
Ancestor:- //*[@name='userName']//ancestor::table
Parent:-
//*[@name='userName']//ancestor::table[2]
or
//*[@name='userName']//parent::tbody
Child and Descendants
The word descendants means the node child and child's child.
EXERCISE 6:-
Ans:- //*[@attribute='value']//parent::value
Ans:- //*[@attribute='value']//following::value
Ans:- Current
Ans:- Before
16. Css selector
CSS Selector is one other process like XPath to find web elements.
You have seen that XPath finds web elements on the website; however, it is not the best
process. Here is the list which makes CSS better than XPath:
● CSS is much faster as compared to XPath.
● It is more readable.
● Programmers who are familiar with CSS coding prefer the CSS selector over XPath.
xpath=//Tagname[@attributename=‘value’]
CSS=Tagname[attributename='name']
CSS Selector: More Attributes
XPath: //*[@class='class_enabled'][@style='display:block']
EXERCISE 7:-
Ans:- .class
Ans:-end with
Ans:- whitesace
Ans:- #id
17. Multi-Scripting: Syntax
Example:-
18. Benefits of Multi-Scripting
Multi-Scripting can beneficial in many ways:
● We can handle our test case separately.
● It will be easier to understand and track if any change is requested.
EXERCISE 8:-
Ans:- .useXpath
Ans:-page_objects_folder
Ans:- .useCss
Ans:-@elementName
EXERCISE 8:-
Ans:-.setValue('xpath','dataVar.userName')
Ans:-{
"value1" : "text",
"value2" : "text2"
}
Ans:-Using require
19. Support Browsers
Normal Browsers
Chrome
Firefox
Internet Explorer
Headless Browsers
A web browser without a graphical user interface(GUI) is called a headless browser. We will
use and control it programmatically.
Chrome Canary
PhantomJS
Ghost
HtmlUnit
We have to download and add an extension of the above mentioned browser to run it
headless.
EXERCISE 9:-
Ans:- .attributeText()
Ans:-.getLocationInView()
Ans:- .init()
Ans:- .end()
Ans:-.saveScreenshot()
20. Disable in Multi Script
21. Run Group Test
nightwatch --group firstScript
22. Skip Group Test
nightwatch --skipgroup firstScript
23. Nightwatch -Cucumber
● A cucumber is a BBD framework that executes plain-English text functional
descriptions as automated tests.
● The test cases are written in simple, plain English.
Nightwatch Final Mcqs:-
Ans:- bin —-> lib
Ans:-/*[@attribute='value']//ancestor::value
Ans:- sub-string
Ans:-1,2,4
Ans:- absolute xpath
Ans:-.attributeText()
Ans:-.useCss
Ans:-cli_args
Ans:-.attributeContains()
Ans:- .class
Ans:-{
"value1" : "text",
"value2" : "text2"
}
Ans:-.waitForElementVisible()
Ans:-JavaScript
Ans:-an object
Ans:-3,5
Ans:- Both the option are correct
Ans:-Scripts
Ans:-src_folder
Ans:- end with
Ans:- .useXapth