Protractor with visual studio code and javaScript/typeScript

Pre – Requisites:

Visual Studio Code Installed

Node Js Installed

(All commands will be in italics)

Setup of Project :


Open Visual Studio code and add new folder.

Step 2 : Init the npm for the package.json file.

Open Terminal from Terminal – > New Terminal

Use below command

npm init

Enter all details – some dummy details, for lisence details you can simply hit enter to generate dummy configuration

After all select yes.

Now you will see the package.json file in the left

Now install protractor locally with following command

npm install –save protractor

if you see below error change the protractor to protractor 2 in the json file and try again


npm install –save jasmine


npm install –save typescript

Create new folder called specs

Create folder inside specs and keep driver inside it.

Now its time to create tsconfig.json file for the configuration of type script.


    “compilerOptions”: {

       //ts “module”:”commonjs”,

        “noImplicitAny”: true,

        “removeComments”: true,

        “preserveConstEnums”: true,

        “moduleResolution”: “node”,

        “sourceMap”: true,



    “typeRoots”: [



    “exclude”: [





Tsconfig.json file is configuration of the tsc compiler.

We are going to use typescript and typescript compiler to compile the code and convert to java script.

Now create the script for our selenium test with scripts.ts in the specs.

Once we start writing the test we don’t see this in the code console, only type script and jasmine are seen. Let us fix this.


npm install -d @types/jest

update the package.json file with below content.


  “name”: “typescript”,

  “version”: “1.1.0”,

  “description”: “test”,

  “main”: “config.js”,

  “dependencies”: {

    “@types/jasmine”: “^3.5.11”,

    “@types/jest”: “^26.0.3”,

    “@types/mocha”: “^7.0.2”,

    “jasmine”: “^3.5.0”,

    “protractor”: “^7.0.0”,

    “typescript”: “^3.9.5”


  “devDependencies”: {},

  “scripts”: {

    “test”: “test”


  “repository”: {

    “type”: “git”,

    “url”: “test”


  “keywords”: [



  “author”: “test”,

  “license”: “ISC”


Also re-install the protractor, if its not got installed already.

npm install –save protractor

 now create test script which opens the google and enters some text.

import {browser, element, by} from ‘protractor’

import {} from ‘jasmine’

    describe(‘sanity’, ()=>


        it(‘expected valuidations’, ()=>









            ).then ( ()=>


                element(‘q’)).sendKeys(‘ConsolidatedChoas’).then( ()=>








Now we need to convert this to java script code wit tsc

Run following command and observe the changes.


Now the code gets compiled and you see new file gets generated in the folder.

Now to run the protractor, we need config.js file which tells the chrome browser for to take the options and capabilities.

Config.js — below

exports.config = {

    // launch locally when fields directConnect and seleniumAddress are not provided

    chromeDriver: ‘./specs/driver/chromedriver.exe’,

    specs: [‘./specs/scripts.js’],

    capabilities: {

      browserName: ‘chrome’,

      chromeOptions: {

        args: [“–headless”, “–disable-gpu”, “–window-size=800×600”]




Now we are all ready to run our first script.

For running follow below step.

Protractor config.js

The result should display as below.

Points to be Noted:

  • Package.json must have all the modules you are using for compiler to understand
  • Tsconfig.json must have include and exclude what you want to include exclude while compiling the code
  • The chrome can be invoked headless or with UI, in this we illustrated headless mode.
  • Check the modules, types that are listed in config files and make sure that you have those in the npm_modules folder for verification.
  • Following is link for the git project.


Winium example with word automation

I have been exploring the new tools for windows based apps automation, having worked on white API and its lack of documentation and complexity in writing the code, i was searching for good alternative.

Winium seems to be one of the options suggested by selenium group of people, as the syntax is similar to selenium.

Winium uses the winium.desktop.driver to start off the listening of the commands sent by the driver and redirect them to the application under test. There are several dependencies that are required just as selenium web driver for the desktop driver.

The basics need to work on WInium is

  1. Winium.desktop.driver.exe (winium.driver.exe)
  2. Eclipse with maven plugin
  3. Inspect tool  / .Net framework with windows tool kit
  4. Selenium background

Eclips with maven plugin : This is required since there are dependencies that are required to work with Winium, with maven plugin and with the POM file we can download all the plugins.  the POM file is given below for the dependencies.

<project xmls="" xmlns:xsi="" xsi:schemaLocation="">


Once you have created the project and updated the project with dependencies. You can create a test case and will be able to use the sample code below.

Just like chrome driver options we can initiate the desktop driver with options.

DesktopOptions option = new DesktopOptions();
option.setApplicationPath("C:\\Program Files\\Microsoft Office\\root\\Office16\\WINWORD.EXE");

First line is to create the options object for the desktop driver.

After creation of the object, set the application under test executable path. In the above case it is windows word.

Let us look at how do we identify the windows objects. In case of web elements we can use firebug, firepath or developer mode in browsers to get required css or xpaths.

In the windows based apps, there is tool called Inspect.exe which will be located in below path.

C:\Program Files (x86)\Windows Kits\8.1\bin\x86\Inspect.exe

Or you can search for it in entire computer, just in case of you don’t find it.

2. Inspect tool : This tool is similar to developer tools of browser. It can tell us the windows object properties. We can make use of some of the properties like classname, name, automation id etc to identify and perform operations on those objects.


In the current context we are trying to do word automation, so to go to insert tab, we can use find element by name of it, as you see the properties description it says name is ‘Insert’

Similarly we can identify the object based on their names. Following is the code for the identification of some of the basic word GUI objects.

//Selects the blank document
driver.findElement("Blank document")).click();
//Goes to insert tab
//Clicks on shapes
//Selects the rectangle
//Clicks on rectangle to get it on the word.
driver.findElement("Page 1")).click();

The entire code is below.

package com.tests;

import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.winium.DesktopOptions;
import org.openqa.selenium.winium.WiniumDriver;

public class Tests 

public void CalcTest() throws MalformedURLException, InterruptedException

DesktopOptions option = new DesktopOptions();
option.setApplicationPath("C:\\Program Files\\Microsoft Office\\root\\Office16\\WINWORD.EXE");

WiniumDriver driver = new WiniumDriver(new URL("http://localhost:9999"), option);
//SLeep is to wait until the word becomes visible
driver.findElement("Blank document")).click();
driver.findElement("Page 1")).click();


Entire code is given in the below git repo.


Before we execute any of the test cases, we need to start the winium driver exe as it is the listener to the events provided by the driver. Also, check the port on which it is running , use the same port while creating the driver.

Following is the demo.


Thank you. Please write in comments in case you need more information on winium automation.

Future of testing Artificial Intelligence and Machine Learning.

As the world progresses, we see automation taking place of human activities. All sectors are hugely disrupted by the AI and ML.

Now the big question comes, AI will take over monotonous and redundant processes where brain power requirement is lower.

The question is how software quality sector is getting ready for it?

How do big companies make use of AI to sustain for the future disruptions in the technologies?

Let’s see the glimpse of possibilities and current implementations in this section.

Artificial Intelligence, is mostly known as learning process by machine using predefined algorithms called supervised learning, the other part of it is unsupervised learning where AI engine deduces predictions by itself by recognizing the patterns example of it is edge detection in photos.

Some of these algos are inspired by the fact that how our brain works. There are several researchers out there understanding the workings of brain to simulate the same in these algorithms.

Some of the AI runs on pure statistics and might not require any learning engine behind.

Let’s coming back to original intent of the content, lets breakdown the areas of testing and see how AI is coming into all the areas.

Tests Preparation

In the quality industry identifying the proper tests for the application or business process is quite tedious process, in this context there are some interesting AI implementations.

Mining of tests – This is carried out by intelligent Natural Language Processing (NLP) algorithms

Test Selection – By analyzing the failure logs from the application, one can design learning engine to select the specified tests for the specified failures. It’s again a NLP algorithm

Test Duplicates Removal – We can remove the duplicate tests by mining the tests and similar tests

Test Creation – This is still ongoing research area where AI engine can automatically derive the test based on the user actions, like record and play back feature in several automation engines

Test Execution

Current test execution process is generally triggered by devops tools such as Jenkins or TFS. What can we do additionally? Can we use AI?

Execution – We can use speech input to trigger the test with Speech to Text and Text to Speech converters, these engines are basically developed by big companies and lot of AI research goes into it now. Amazon Alexa, Apple siri are just tip of iceberg.

ChatBots – Ask Chabot which tests you want to execute and it will pick up that for you, you can choose, group the test you want and star the execution.

Execution Results – There are few interesting use cases when comes to test execution, let’s take for example we have ran suite of several hundred tests and it generated a bulky report, then its time for manual verification of those results, if they are because of the script or because of UI changes, or because of the actual application issues. Here, first thing is to develop robust scripts, but still there is lot of scope to create an engine which will be first supervised to learn and understand the different types of failures and then predicts the cause of the failures. This is not yet implemented case, but when we think about it, there is lot of scope here to tune the engine to classify the failures. This will become classification problem in terms of the AI.

Failed Method to Test Selection: There is possibility to identify the failed method or the type of the error with above mentioned approach, and going further deep we can very well correlate them with what tests to execute for what type of failures, what methods are failing and what are the expected tests to run when the application gets new fixes.

Performance Testing

Machine Performance Analysis – This is the actual area where AI shines. Mostly the data will be plotted in graphs in all tools like LR and Jmeter. But we don’t know the anomalies and insights of the data. We can detect changes in the Disk performance (iops), we can detect anomalies in the CPU utilizations, and one can correlate them with actual transactions happening at that time. All will be done with supervised learning or unsupervised learning. We can implement different algos and see how they are performing.

Transaction Performance – This is good use case similar to above. We can collect the metrics of all transactions and apply different alogs to detect anomalies, peaks in the data. By which we can get to few conclusions. This is the area I have done prototype which I will be sharing in next blog.

So, all in all, there are several use cases which AI can improve the way we work. But nevertheless, it will not replace the ability to create something new something very creative like identifying security bug etc, may be anytime soon.

Please write down below in comments if you think anything can be done with AI in testing or we have already done we can discuss about it in detail.






Protractor setup and example of non angular app simple test – Part 2

In the Part 1 we have seen how to setup the protractor, In this section lets see how to write test spec file and configure the formatted report.

googleTest spec file has below content.

//The above line is specifically written for non angular applications such as google
//Describe the test and expected result in it block
describe('google homepage', function() {
it('should open the page', function() {
var waitEC = protractor.ExpectedConditions;
browser.driver.findElement('q')).sendKeys('Testing Example for Protractor non angular');
expect('Testing Example for Protractor non angular').toEqual('Testing Example for Protractor non angular');
describe('click on search', function() {
it('should click on search button', function() {

The above code is for the protractor spec file to open the google website and search for specific keywork and click on google search button. In the next section will see the formatting part.

As we know, we have different types of formats available for the protractor, among those below is widely used as it is fortmatted console and does not require additional css or etc files to view the results. All results are shown on the console logs it self.

we need to first install the node package for this.  More info jasmine formatter

npm install jasmine-spec-reporter

Once we install the package, it will download necessary module under protractor location.

Once downloaded, we just need to update our conf file with the downloaded formatter.

The sample conf file also given in the above site. Following is the sample conf file used for our googleTest spec.

let SpecReporter = require('jasmine-spec-reporter').SpecReporter;

exports.config = {
framework: 'jasmine2',
jasmineNodeOpts: {
showColors: true,
silent: true,
defaultTimeoutInterval: 360000,
print: function () {
specs: [
capabilities: {
browserName: 'chrome',
'chromeOptions': {
args: ['--test-type']
logLevel: 'WARN',
onPrepare: function () {
jasmine.getEnv().addReporter(new SpecReporter({
spec: {
displayStacktrace: true
summary: {
displayDuration: false

Once we have updated editing the conf file. you will be able to see report in nice colored format shown below.


Please write to me or down below comments section if you are facing any advanced issues in protractor.

Thanks for reading..!!!

Protractor setup and example of non angular app simple test – Part 1

Now a days we see lot of angular JS applications being built.

It is said that at least 10% of the latest developing are based on angular js.

In this section we see how to configure and run a simple protractor test on angular and non angular app

Its very straight forward, mostly thats the reason why its largely adapted.

Step 1 :

Install Node.js, current version of node js when writing this blog is v10.16.2

you can download node js from  Node Js download

select the windows MSI and install it. While installing it select add node js to path.

This option enable us to directly access node commands from cmd without navigating to node directory.

Node JS is like collection of several java script libraries. They are called as node modules

The installation also installs the node package manager which is required to install different node modules.

Once you have installed it  go to command prompt (search-> run – >cmd)

then enter following command

Node -v

It should show the current installed version, if its not there is some issue with the installation.


Now we have node js setup and ready

Open cmd and try to install the protractor, install protractor globally (all users on the machine, if not remove -g)

npm install protractor -g

More information on this site

Usually protractor sets up the web driver manager. But if it’s not then you need to install the webdriver manager as well

webdriver-manager update


Now we have to start our webdriver-manager to kick of the example test

Webdriver manager will look for webdriver connections that are being initiated by protractor.

webdriver-manager start

There is one sample test that comes with protractor we can use it and create couple of more tests.

But, if we want to run on google we might want to make some changes.

At the end of start of webdriver you should see command prompt like below.



Once you started the webdriver manager, open another command prompt and run a angular example test

In the node js installation will happen typically in appdata/roaming folder go to following path, you should see following

Example path :


You should see the following, googleTest is something I have added, you don’t see it by default.


To run a test we need to use following command

Protractor C:\Users\{user_name}\AppData\Roaming\npm\node_modules\protractor\example\conf.js

What does this mean ?

Protractor reads the conf file and executes the specification file mentioned in the conf.js

Protractor uses something called Jasmin framework by default. Its called as “Describe It” framework.

Test start with Describe() – > then It() , which means action and its expected outcome.

All the code is written in java script, we can use type script too.

Once we start the example test it will perform operations on node js site and gives us the following result.

The result displayed below is formatted, I will mention how to configure different types of reports in next section.


In the next part will discuss about following

  • Custom report as shown above.
  • conf.js sections and how to edit.
  • googleTest.js -> non angular application example.


TestNG Annotations list and execution order

TestNG is testing framework enhancing the Junit framework.

Lets look at different annotations it provides for the test execution stand point.

Following is the list of all annotations that one may require to control after or before facts of test execution. These methods will execute before or after the event is called. These annotations does not depend on the test execution status.


the sample test class with annotations produces following output. All the other annotations does not need any parameters except that before and after group annotation, following is how we can mention the group name.

	public void beforeGroups() {
		System.out.println("Calling before groups");

Output from java console :


While doing console logs, I have struggled to get rid off other console messages produced by the chrome driver. Following piece of code is used to suppress the console logs produced by chrome driver, added this just thought might be relevant to share.

System.setProperty("", ChromeDriverPath);
System.setProperty("", "true");





Synchronizing web driver and Ignoring Exceptions in C# Selenium API

In general the website response times may cause issues while doing the UI automation testing. Most of the times test scripts will fail due to synchronizations issues from web-driver and the application web elements.

Following are the common reasons and if we see very frequent issues in synchronization it is suggested to do performance testing and tuning.

  • Location from where we are accessing the application (Latency)
  • Network bandwidth
  • Too much firewall checks
  • Website architecture and technology on which website built on.

Most of these cases are taken care while doing performance tuning and performance engineering, but yet we see page load issues, element enabling issues and visibility issues while doing UI automation.

In selenium we have several methods that we can use to make sure that these things are taken care. Following is the just enough explanation about waits in Selenium driver.

Implicit waits will wait until the defined action (example page loading ) is complete.

Example of it is managed time outs, and they are defined at driver level.

Driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(30);
Driver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(30);

When we want to wait explicitly at certain number of seconds we will use explicit waits. As the name suggests the test execution will be halted during this time. Example of it is sleep


here the parameter indicates the number of milliseconds to wait for.

The other case of waiting for dynamic web elements is using wait until or web driver waits. These are most common implicit waits that are used. There are two ways we can use these.

We can declare the web driver wait and and it will wait for max wait in this case it is 30 seconds, and repeatedly we can check for the expected conditions i this case we are looking for visibility of the element google search text box.

IWebElement textbox;
WebDriverWait waits = new WebDriverWait(Driver, TimeSpan.FromSeconds(30));
textbox = waits.Until(SeleniumExtras

There is another way we can use this as function delegate, following is how it is used.

//there is another way using function delegate
//delegate parameters and return value = new delegate parameters return value of passed parameters
//delegate is on the fly function generator
Func<IWebDriver,IWebElement>checkForvisibilityOfWebElement = new Func<IWebDriver, IWebElement>((IWebDriver Driver) =>
     IWebElement textBoxDelegate = Driver.FindElement(By.Name(SEARCH_TEXT_BOX_NAME));
       if (textBoxDelegate.Displayed)
           return textBoxDelegate;
          return null;
 textbox = waits.Until(checkForvisibilityOfWebElement);

When you look at above code, its function delegate takes one argument as IWebDriver and returns the IWebElement. The last argument of function delegate is always a return type.

The wait until function will take this and checks for the condition mentioned in the delegate periodically.

If you look at the until you can clearly see this text.


But if we look closely, the description says it will throw exception if it is not listed in the Ignore Exception list.

For that purpose. We have to configure our waits object what exceptions that we want to ignore while we periodically check for our condition. We can achieve this by following.

IWebElement textbox;
WebDriverWait waits = new WebDriverWait(Driver, TimeSpan.FromSeconds(30));


There are list of exceptions that we may want to ignore, following is the snap shot.


And finally following is the list of element states we can wait for.


Please comment if you see anything is incorrect or you want to add something you know. Thank you.


J soup example for editing html

In static web pages some times we might need parse and edit the pages.

Simple example would be generating static html report we might want to make use of html parser or html editing libs.

Jsoup is one of the good create/editing libs that is available.

Below is simple example of editing the html file with Jsoup.

There are three simple steps in the process for the editing of htmls with Jsoup.

Step 1 : Parsing the html code.

Following is the example for parsing the html file with Jsoup. The document is type of html document.

Document reportDoc = Jsoup.parse(new File(filePath), "UTF-8");

Now that we have reportDoc as html document that we need to update, lets just say if html is containing below structure, problem statement is to add data to the following table in the existing html doc.

Step 2 : Update/Append or change the text in the doc


In general all html objects (I.E the elements that are inside the tags) are called as elements in Jsoup.

Steps to insert data would be to find the “Element” with table tag and append the element with a row i.e “tr” tag and then add the data to the table in td tags. We can insert all data at once or we can edit data by index of the tr and td as shown below.

Element ele = reportDoc.getElementsByTag("tbody").last();
ele.append("<tr class='styleincss'>
     <td style='text-align: center;'>1</td>
     <td style='text-align: left;'>desc</td>
     <td style='text-align: left;'>col3</td>
     <td style='text-align: left;'>col4</td>
     <td style='text-align: left;'>col5</td>
     <td style='text-align: center;'>col6</td>
     <td style='text-align: center;'>Complete</td>
//This will generte the html

//If we want to change the values of existing rows we can write

//If you want to change or add attribute
reportDoc.getElementsByTag("a").last().attr("style", "text-align: center;Color: " + colorCode);


In the above code we have seen ways to add inline html, editing dynamically with rows and columns, we can loop through as well and write some intelligent code to go to particular column and particular row and edit data.

We can also set attributes for example as color, or href for links shown in above example.

But we just appended the document, how do we save ?

Step 3 : Save and flush to disk

We can use Buffered-reader to read the html that J soup has just appended to the original document.

Lets just say you have file name that you want to create and also appended document, below is the code to save to disk.

public static void writeToFileAndFlushToDisk(Document doc, String outputFile) throws IOException {
BufferedWriter htmlWriter = new BufferedWriter(
new OutputStreamWriter(new FileOutputStream(outputFile), "UTF-8"));
//Optional new line


This is general idea on how to use J Soup for editing html files. I have used this and created simple html reporting for LeanFT tests. We can create files and dynamically update link references so that test results can be systematically generated.

Please write to me if you need more information.

Design Selenium Framework with C# – Part 5

Now since we have created the basic framework and page classes. Lets look at NUnit framework to create tests.

NUnit 3.0 supports parallel testing, and prior to that it supports the testing multiple iterations with different parameters.

Here if you see TestFixture attribute allows the test class to take the constructor parameter. I.E parameters you are defining in the testfixture will be passed to constructor of the test class if matching definition is found. This is very useful when we need to execute same tests with different browsers, we can define BrowserType to achieve the same purpose. The test class will be initiated and tests will be executed for each of those test fixtures.

Also Prallalizable (ParllelScope.Self) will run the test methods in parallel. More information can be found in below link.  Nunit documentation

If you look at the below code, constructor of the test class has browsertype as parameter which is matching with the parameter defined the test fixture. So the test class will run for each browser type.


And the SetUp attribute is similar to TestSetup in MSTest framework or BeforeTest in TestNG. This will sets up the preconditions for each test.

If you look at the test execution flow

  • Starts at calling DriverFactory.InitDriver(browserType)
  • This will invoke and create corresponding BrowserDriver class object
  • Driver property will be set in the DriverFactory Class with the type of the driver
  • Using the DriverFactory.GetDriver() method we are getting driver to the thread which has initiated it.
  • It will be passed to the Page Classes to do the rest of the test flow.DriverGet

If you look at the test explorer it identifies the tests based on the TestFixture types.


When you click on run it will run all tests in parallel. You can see the results in the test explorer for each iteration Results


This is the simplest explanation I could give quickly for the Selenium with C# implementation with interface design pattern.

I have not touched any Reporting/Logging part for the framework.

As It can be implemented with ILogger interface with different logging methods so that each logging type (Excel logging, Text, Word/pdf, html) can be implemented easily.

Having said this, it will conclude our discussion on creating the framework.

Please feel free to follow and write to me if you need help in understanding any of these items.

Design Selenium Framework with C# – Part 4

In this part lets look at creating the page objects in most generic way.

As discussed in the last post the selenium support of page object initiation is getting deprecated from next releases of the selenium. So lets create page objects in most generic format.


In the above class, we are declaring the all const string or identification strings may be xpath or ids or css selectors as const strings.

And we are assuming that driver object is being sent to the class. We are creating class property as driver and assigning the sent driver while creating the page class object from test.  So the constructor of the page class takes one parameter driver, also if you look at it it take parameter type IWebDriver that means, any type of driver which implements IWebDriver is good enough, this will make class independent of the driver type.


In the above code we have created the web elements as properties of the class

And the actions as methods. We can create the elements in the methods as well. But to make differentiation between actions and elements, its good practice to keep the elements as properties.

I am not creating utility class as of now to keep the common methods in there, also there is no BasePage which has global objects of the application. We can very well do that, but for the simplicity , I have not added additional classes which makes it bit complex to understand the execution flow.

Similar to the above the class, we can create search results page and validation of the search results page in another class called GoogleSearchResults.


And verification method for verifying the returned search result.


Now that we have every thing ready we are good to create NUnit test and understand the execution flow. I will discuss it in next section.

Design Selenium Framework with C# – Part 5