Mountebank - Creating a response based on a file template and modifying it

In the previous two blog post, I have explained about how to setup mountebank (here) and how to create a virtualised respone(here) . Now coming to more detailed use cases which we might encounter in daily life. In this blog post, I will explain how we can use mountebank to create a virtualised response based on a template response stored in a file and modifying certain fields in response based on the request coming through. ...

April 6, 2017 · Aby George A

Creating HTML report for test execution result

How to create HTML report with details of test execution Very often , we will be required to create a report with details of test execution , so that it can be presented to various stakeholders. Specflow provides a feature to create HTML reports. Let us look into more details about how is this done Read through and understand details of reporting from specflow. Ensure packages for Specflow, Nunit, Nunit console runner are already installed. If you are using Nunit 3, install NUnit.Extension.NUnitV2ResultWriter package via nuget package manager. If this is not installed, we will get an error “Unknown result format: nunit2”. Follow setups required for running specflow test cases from command line. Details can be found here. Modify the bat file to create nunit2 reports. PathToNunitConsolerunner\nunit3-console.exe --labels=All --out=TestResult.txt "--result=TestResult.xml;format=nunit2" PathTo\AcceptanceTests.dll Add below command into Bat file. This will create HTML Report called “MyResult.html” PathToSpecfloPackage\specflow.exe nunitexecutionreport PathTo\AcceptanceTests.csproj /out:MyResult.html Final bat file will look like below. REM bat file to run test cases from console and create xml result file .\..\..\..\packages\NUnit.ConsoleRunner.3.8.0\tools\nunit3-console.exe --labels=All --out=TestResult.txt "--result=TestResult.xml;format=nunit2" .\AcceptanceTest.dll REM Generate html report from test output .\..\..\..\packages\SpecFlow.2.1.0\tools\specflow.exe nunitexecutionreport .\..\..\AcceptanceTest.csproj /out:MyResult.html EDITED: If it throws below error in newer version of Visual Studio then ensure MS Build tool 2013 is installed. It can be downloaded from https://www.microsoft.com/en-US/download/details.aspx?id=40760 ...

March 5, 2017

Running Specflow Test from command line using Nunit

How to run specflow test cases from command line We can use nunit console runner for running specflow test cases from command line. Running specflow test cases through nunit console runner will help to create test results in xml file, which can then be used for creating html reports. Procedure for command line test execution are Define Nunit as the test runner. This is done in config file <specFlow> <unitTestProvider name="NUnit"/> </specFlow> Include Nunit.Console.Runner package to solution via nuget package manager Run specflow test cases using below command. We can create a bat file with below command and execute them as required. pathToNunitConsoleRunner\nunit3-console.exe PathToProject.dll example will be .\..\..\..\packages\NUnit.ConsoleRunner.3.8.0\tools\nunit3-console.exe .\BDDFramework.dll

March 4, 2017

Mountebank - Your first service Virtualisation

In current development world, there will be scenarios were both API and its consumers are developed in parallel. Inorder to decouple their dependencies, we can mock an api response using mountebank. In this example, I will explain how to get started with your first service virtualisation using mountebank. After installing mountebank as mentioned in here (Install Mountebank), we will proceed with configuring mountebank. It can be done in few ways. The method which I explain below is by using file based configuration. This involve setting up an imposter file and a stub response ...

March 3, 2017 · Aby George A

Service Virtualisation Using Mountebank

What is Mountebank? In short mountebank is a open source service virtualisation tool . Mountebank uses imposters to act as on demand test doubles. Hence our test cases communicate to Mountebank and mountebank responds back with relevant stubs as defined. How to Setup Mountebank ? Installation can be done via two methods npm Mountebank can be installed as a npm package. Node.js should be installed for this option to work ...

February 13, 2017 · Aby George A

UI Testing- decoupling back end dependency

The traditional approach for automating UI test cases is to create selenium web driver based ( or any UI testing tools) scripts for exercising complete end to end flow. However, it comes with its own challenges. It will have multiple steps as pre-requiste for reaching required UI page and hence it behaves as an E2E integration test rather than UI test. A typical web application architecture will have one or more front-end application, which will talk to multiple back-end services, API’s etc. They will, in turn, talk to other back-end services or to different databases. On High level , architecture looks like below ...

February 12, 2017

Powershell - Copying Folders and Files

Two options for copying files are below. Robocopy - More details can be found at Robocopy Copy_Item cmdlet - More details can be found at Copy-Item Copying Folder structure Only $source = "C:\tools\DevKit2\octopress-blog\source" $dest = "D:\delete" Copy-Item $source $dest -Filter {PSIsContainer} -Recurse -Force #OR robocopy $source $dest /e /xf *.* # /e denotes all folder including empty folders. /xf denotes all files except one of format *.* # /e can be replaced with /s for ignoring empty folders Flattening Folder structure - Copy all files from nested folders to a single folder $source = "C:\tools\DevKit2\octopress-blog\source" $dest = "D:\delete" # Below is required only if we need to create destination folder. Uncomment below line if folder needs to be created #New-Item $dest -type directory Get-ChildItem $source -Recurse | ` Where-Object { $_.PSIsContainer -eq $False } | ` ForEach-Object {Copy-Item -Path $_.Fullname -Destination $dest -Force} Copy same folder structure $source = "C:\tools\DevKit2\octopress-blog\source" $dest = "D:\delete" robocopy $source $dest /e

October 10, 2016

Git - How to solve filename too long error

Git for windows is normally shipped with long path support disabled due to mysys not supporting file path/name greater than 260 character. While cloning repository with large nested directory structute may cause error “file name too long”. This can be fixed by below command. It can be executed using powershell or cmd directly in project ( or anywhere if git variable is available) git config --system core.longpaths true

September 23, 2016

Running Command Line from C#

Code Snippet private void RunCLIjobsOnLocal(string arguments, int WaitTimePerCommand) { var psi = new ProcessStartInfo(); psi.CreateNoWindow = true; //This hides the dos-style black window that the command prompt usually shows psi.FileName = @"cmd.exe"; psi.Arguments = "/C " + arguments; psi.RedirectStandardOutput = true; psi.RedirectStandardInput = true; psi.RedirectStandardError = true; psi.UseShellExecute = false; var sspw = new SecureString(); foreach (var c in password) { sspw.AppendChar(c); } psi.Domain = domain; psi.UserName = userName; psi.Password = sspw; psi.WorkingDirectory = @"C:\"; using (Process process = new Process()) { try { process.StartInfo = psi; process.Start(); var procId = process.Id; string owner = GetProcessOwner(procId); // Synchronously read the standard output of the spawned process. StreamReader reader = process.StandardOutput; string output = reader.ReadToEnd(); reader = process.StandardError; string error = reader.ReadToEnd(); if(error.Length >0) process.WaitForExit(); } catch (Exception e) { log.Error(e.Message + "\n" + e.StackTrace); } } } private string GetProcessOwner(int processId) { string query = "Select * From Win32_Process Where ProcessID = " + processId; ManagementObjectSearcher searcher = new ManagementObjectSearcher(query); ManagementObjectCollection processList = searcher.Get(); foreach (ManagementObject obj in processList) { string[] argList = new string[] { string.Empty, string.Empty }; int returnVal = Convert.ToInt32(obj.InvokeMethod("GetOwner", argList)); if (returnVal == 0) { return argList[1] + "\\" + argList[0]; } } return "NO OWNER"; }

September 8, 2016

Element Location Using XPath Axis Part 2

In previous post, I have mentioned different ways of identifying web elements using XPath . Very often , we will have to identify child elements while automating using selenium. Let us consider below example . This is an HTML layout of table <table id=table1 style="width:100%"> <tr> <td>John</th> <td>Smith</th> <td>50</th> </tr> <tr> <td>Jill</td> <td>Smith</td> <td>50</td> </tr> <tr> <td>Eve</td> <td>Jackson</td> <td>94</td> </tr> </table> Assuming we need to iterate across all the rows to identify which row have the name “Eve” and then do some action on that row . This can be achieved by below ...

September 7, 2016