Writing Cypress tests in BDD format

As discussed in previous posts here and here, we use Cypress for writing tests to validate GUI and API tests. In many companies we use behaviour driven development practises where the requirements or acceptance criteria are specified in Gherkin format. As a results, test automation scenarios are also written in Gherkin format. Cucumber , Specflow etc are some of such framework used extensively . In this post, let us examine how we can write BDD test cases in Cypress. ...

December 9, 2020

How to validate XHR in Cypress

In the previous post we saw about working with Cookies in Cypress. Now let us look at how we can work with XHR request in Cypress. XHR stands for XMLHttpRequest. It is an API in the form of an object whose methods transfer data between a web browser and a web server. Cypress provides inbuilt functionality to work with XHR request. It provides us with objects with information about request and response of these calls. It will help to do various assertions on header, url , body , status code etc as needed. It also help us to stub the response if needed. ...

November 25, 2020

How to read browser cookies in Cypress

Cypress has inbuild support to read browser cookies. There are two commands for this - GetCookie and GetCookies. Refer documentation for more details ###GetCookie This command get a cookie by its name. cy.getCookie(name) cy.getCookie(name, options) Note: name is the name of cookie . Options can be used to change default behaviour like logging , timeout Examples usage is as below //Below line is added to get intellisense while writing code in visual studio code /// <reference types="cypress" /> it('Read Cookies In Cypress',() => { cy.visit("www.commbank.com.au"); //GetCookie returns an object with properties like name, domain, httpOnly, path, secure, value, expiry ( if provided), sameSite(if provided) //Checking for individual cookie property value cy.getCookie('s_cc').should('have.property','value','true'); cy.getCookie('s_cc').should('have.property','domain','.commbank.com.au'); // Checking multiple properties of a cookie. *cy.getCookie* will get an object. *Then* helps to work with object yielded from previous cy.getCookie('s_cc').then((cookie) => { cy.log(cookie); cy.log(cookie.name); expect(cookie.domain).to.equal('.commbank.com.au'); expect(cookie.name).to.equal('s_cc'); expect(cookie.httpOnly).to.equal(false); expect(cookie.path).to.equal('/'); expect(cookie).to.not.have.property('expiry'); }) }) Results from test run will look like below ...

November 19, 2020

How to modify environment variables for a different not logged in user in windows

Modifying environment variables for a logged in user is straight forward. However there are some instances when we need to modify environment variables for a different user. One frequent usage which I have come across is when we need to modify PATH variables for a service account in a CI box. Service account may not have local logon rights to the machine Or we may not know its password. Hence I always end up using below method to update path variables ...

October 14, 2020

Generating C# classes from xsd

XML Schema Definition tool will help to generate classes that conform to a schema. Steps are as follows. Open VS Command prompt . ( Start Menu » Visual Studio 2019 » Developer command prompt for VS2019) Pass xml schema as an argument to xsd.exe . \c at the end denotes to generate classes xsd.exe C:\Temp\sampleschema.xsd /c /o:C:\Temp There are other options as well. Main ones are below. xsd.exe <schema.xsd> /classes|Dataset [/e:] [/l:] [/n:] [/o:] [/s:] /classes | Dataset : denotes whether to generate class or dataset /e: Element from schema to process /l: Language to use for generated ode . Choose from 'CS','VB','JS','VJS','CPP'. Default is CS /n: Name os namespace /o: Output directory for generated classes There are other options as well. Details can be found on help “xsd /?” ...

May 13, 2020

Exercism

Most crucial factor for effectively learning a programming language are below. Having hands own experience Having a structured learning path Having a mentor to guide and review the code. I was recently looking to learn more about javascript and came across Exercism.io. Exercism.io offer a solution for all above factors and is free of cost All language track will have a series of exercises starting with very basic hello world program and then moving to complex concepts. User should download the exercise , which will have a failing test suite. Once we implement the code and ensure test cases are now passing , we can submit the code for mentor review. Mentors review the code and suggest better ways of doing it, if any. Exercism.io will prevent us from jumping ahead and force to complete one exercise before moving to next one. This actually helps to follow a structured learning path . ...

January 9, 2020

Sending Emails through SMTP in C#

Recently I was looking for some code for sending emails via SMTP in C#. Below are few links which I found with some reusable code. Overall it looks fine , but have to include multiple validations for error handling . https://gist.github.com/robertgreiner/1529127 https://gist.github.com/gzuri/2850914 https://gist.github.com/pranavq212/1cbecac15abb229d40f1ad0765aa4dce https://gist.github.com/TrailCoder502/6254bdfcfe71c4000600 In Nutshell, flow is as below Define a function to send email which accepts an input Email object Validate the email object to ensure all mandatory fields are present and correct Create a new MailMessage object and SMTPClient Object and send email Above gist links have some reusable code to achieve step 3 of above.

April 9, 2019

Creating utility tool as portable EXE

Recently one of my colleague approached me asking to help on creating a utility tool using selenium web driver. The requirement was simple which includes accepting few arguments from the command line and then open a browser and complete some actions on browser based on inputs provided. Having worked on selenium web driver for a few years, I thought this is relatively simple and can be done quickly. It is implemented as a C# console app which had reference to selenium web driver. It accepts few arguments from command line and based on the values it opens up chrome browser and completes the action. The initial version was already there on which I made some modifications. We gave a demo to the user and thought it is all done. ...

October 3, 2018

Find DotNet Version Using Powershell

I recently faced an issue where one utility tool created by me was not running properly on another machine which had different dot net version installed. During troubleshooting, I was looking for ways to identify the installed dotnet version. Most of the links in google suggested to look for release value in registry as specified here. Below powershell script will list down installed dotnet version on a machine. This is based on dotnet version listed on https://docs.microsoft.com/en-us/dotnet/framework/migration-guide/how-to-determine-which-versions-are-installed. We may have to update below snippet as when new versions are released. Currently it supports upto dotnet 4.7.2 ...

October 3, 2018

Deploying Octopress to AWS S3 and CloudFront

I was hosting my blog on github pages for past one year. Last week I decided to move hosting of my blog to AWS S3. There are obvious advantages of hosting a static site on S3. Moreover the cost of hosting is also minimal. There are many blogs in internet which explains the steps for hosting an octopress blog on S3. Since this is my first exposure to AWS world, I did had a learning curve to get this done. Below are highlevel steps involved in hosting in S3. ...

September 23, 2018