- it will simulate user actions in web browser and check if function works as expected.
Protractor
- webdriver-manager
- Open Google.com
- Search for Singapore Airlines
- Open Singapore airline website
- Search for flight from Singapore to Bali
- Select date of Start Travel Time = (Current date) & End Travel time = by default selected Value
- Select Business class seat
- Click on search
- install node and npm
brew update
brew install node
- install protractor and webdriver-manager
npm install protractor
as to install all dependendies from package.jsonnpm run webdriver-update
as to update webdriver - Running locally on user machine for testing and debugging purpose we need to comment it out seleniumAddress: 'http://localhost:8080/wd/hub' on conf.js file
2.1. SELENIUM GRID (http://www.seleniumhq.org/docs/07_selenium_grid.jsp)
Currently selenium test is running on Grid using Docker
- The purpose of running test in grid because it speed the time of execution using parallel execution
- To run your tests against multiple browsers, multiple versions of browser, and browsers running on different operating systems.
### To remove existing container
if [ "$(docker ps -a | grep 'selenium/node-chrome:latest')" != "" ]; then
docker ps -a | awk '{ print $1,$2 }' | grep selenium/node-chrome:latest | awk '{print $1 }' | xargs -I {} docker rm -f {}
fi
if [ "$(docker ps -a | grep 'selenium/hub:latest')" != "" ]; then
docker ps -a | awk '{ print $1,$2 }' | grep selenium/hub:latest | awk '{print $1 }' | xargs -I {} docker rm -f {}
fi
### using docker compose set the grid
docker-compose up -d
docker-compose scale chrome=13
New file > Database.js
var mysql = require('mysql');
var sql = {
query: function(query) {
var connection = mysql.createConnection({
host: '',
port: ,
user: '',
password: '',
database: ''
});
return new Promise(function(resolve) {
connection.query(query, function(err, rows) {
if (!err) {
console.log(rows);
resolve(rows);
} else {
console.log(err);
reject(err);
throw err
}
});
browser.driver.sleep(2000);
}).then(connection.end())
}
}
module.exports = sql;
usage in test class
TestCases.js
sqlLib.query("select token from TableName where column ='" + column + "'").then(function(rows) {
console.log("token value :", rows[0].token);
)};
Currently the reports are implemented using plugin
https://github.com/azachar/protractor-screenshoter-plugin
- On failure of test this plugin will generate a screenshot
- Console error Screenshot and console error will help on debugging/analyzing why test are failing .
Relative path
of test report is : SingaporeAir/REPORTS/index.html
Use the below command to run the test
./node_modules/protractor/bin/protractor conf.js
Lib
Folder is having all library functionPage
Folder When writing end-to-end tests, a common pattern is to use Page Objects. Page Objects help you write cleaner tests by encapsulating information about the elements on your application page. A Page Object can be reused across multiple tests, and if the template of your application changes, you only need to update the Page Object.Test Suite
testSuite will have test cases. All test cases will have proper log statement which will be easier for debugging in case of failure. Avoid writing web element directly inside testSuite.js folder as later don’t need to change anything on testSuitedata
contain any test data / hard coded data to be used in test Reuse the test data , ( avoid having duplicates)
https://www.dropbox.com/s/sla9ld728gfises/SingaporeAirlinesAutomatedTest.mov?dl=0
https://gfycat.com/GrimyAcceptableDachshund