Data Driven Framework - XML
I am not going to explain what is data driven framework or what is its benefits. All of them are pretty well-known . If not, just google it.
Here I am going to explain a sample code which can be used to read from xml data files. This will be helpful to implement a data driven frame work for BDD testing , using Specflow or Cucumber
Pre - requiste
Code is written in Csharp . We need to add below reference to visual studio solution
Add reference to System.xml
Add reference to System.Xml.Linq
XML Format
[code language=“xml” ]
[/code]
Node names in above example are Scenario1, Scenario2 and Scenario3
Element or Attribute name are username, password, Email .
You can add any number of nodes and attributes depending on the test scenario
Read specific Value from XML
Below code provides a solution to read values of existing Key/Attribute from a specific node.
1 2 3 4 5 6 7 8 |
|
Read All values for a Scenario from XML
This code gives a solution for reading details of all attributes/key from a node. This comes very handy for reading all data required for a scenario and adding them to scenario context , so that data can be shared across specflow/cucumber step definitions
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
|
Write Data into XML
Below function gives a solution to update value on an existing key/attribute in data sheet . Sometime the data sheet will be copied over to bin folder when we build the solution. That makes it necessary to update both original data sheet and the one in bin folder so that modified data can be used in same test without another rebuild.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
|
Data Driven Framework - Excel
In previous blog post, I have explained about how use XML for making a data driven framework for automation testing . It can be found here. I have also written about how to use jxl library for reading from excel and writing into Excel.
Below is another code snippet to read all values of a row and save it into a hash map for accessing later during automation test.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
|
Nodejs
This post is just for making notes during my learning of Node.js through various courses and online material. This will be always a work in progress blog post
Node.js is an open source server side runtime environment, which is cross platform.It uses Javascript as its language
check node version
node --version
Making web request in Node we can make webrequest by using inbuilt http or by using ‘request’ example : For making web request by http
1 2 3 4 5 6 |
|
example: Please note that there is no space between key and : while defining options
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
|
Example: We can simply by giving GET . There is no need to close request since we are not going to send any more information to request
1 2 3 4 5 6 7 8 9 10 11 12 13 |
|
Another option is
1 2 3 4 5 6 7 8 9 10 11 12 13 |
|
Starting with Node.js and Express
1
|
|
Above command will create a package.json. Leave details are default or change accordingly
1
|
|
Above will install express and also add it as dependency in package.json
1
|
|
Above will create a app.js file. In package.json add below
1 2 3 4 |
|
Now, if we run “npm start” from command line, it will run app.js
Bower
Package manager for web/front end. It is installed with NPM and have flat package hierarchy(doesnt install dependency underneath one level) .It works similar to NPM and have Bower.json for dependency managament.
Create a .bowerrc file and have project specific settings. Now move the components from bower_component to public folder defined earlier. update .bowerrc with below
1 2 3 |
|
now run below
1 2 3 4 |
|
Gulp
It is a task manager for web projects. It have code based config. It is packaged base so that we can use different external packages
Mongo DB
- Install MongoDB from website
- mongoD is command for running server
- mongo is command for running another terminal for interacting with mongo db
- show dbs will show list of db
- Install MongoDB Node.js driver using NPM ```
Volunteering Experience
A couple of months back , I helped out to organize clinical examination for RACP. I created a tool ( Excel Macro) for finalizing exam schedules for all attendees. The roster should consider employee preference, examiner availability, timeslot, venue and other parameters. Below is what I got in return ( even though they misspelled my name).
Selenium
Difference between / and // in XPath
/ is used to create absolute XPath which starts from root. This is highly brittle since any changes to UI will change element locator.
// is used to create relative XPath . The XPath is created relative to another element in UI
Difference between driver.get() and driver.navigate().to()
Both driver.get()
and driver.navigate().to()
will try to open a webpage and wait for the page to load. It means, it will wait till Onload
event has fired. But it will not wait for all AJAX calls to trigger and process. Both of them are essentially the same. How ever Navigate() interface exposes the ability to move backward and forward in browser history.
1 2 3 4 |
|
Difference between driver.close() and driver.quit()
driver.close() will close the window which is currently accessed by webdriver. driver.quit() will close all windows that are opened by the webdriver during current execution.
Java - Writing Into Specific Cell in Excel
In my previous blog post , I have mentioned how to read from an excel file using jxl jar files in Java. It can be found here
In this post, I will explain how to write into an excel using same library. Below example will update the excel cell content with the value passed and also update its formatting . The color of the cell will change depending on value we pass. We can use similar functions for updating any other cell format.
Below is the import section
1 2 3 4 5 6 |
|
Below is the function for writing into excel
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
|
Java - Reading a Specific Cell in Excel
Below is a code snippet for reading a specific cell from Excel using Java.
It is done by using importing jxl jar files which can be found here.
Import below in class file
1 2 3 4 5 6 |
|
Below is function for reading value from specific cell in Excel
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
|
Below is an example of how to read from a cell based on row number and Column NAME
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
|