Archive for the ‘Miscellaneous’ Category

Recently we came across an issue where users complained about not receiving emails from our website. We have our own SMTP server setup for that website/application.
After verifying application logs as well as Pickup/Drop/Queue/BadMail SMTP folders on the server, everything looked fine. So, now the question is how to verify if the service is really sending emails or not. We might not be able to force the application to send a test email. In this scenario, we could test email functionality from command prompt using telnet. In this article, I put together the steps to send email using telnet.

To start with, we need to enable Telnet client on the machine from where we want to connect to SMTP service.

Steps to enable Telnet client:
Open Run window and type “appwiz.cpl”
It opens “Programs and Features” window.
Click on “Turn Windows features on or off” link from left pane.
“Windows Features” window will be opened.
Scroll down until you find “Telnet Client” option. Check the checkbox and say OK.
If it prompts for System restart, you can select “do not restart now” option because enabling Telnet Client option doesn’t require system reboot.

Testing email functionality:
Open command prompt.
Run the following commands to open telnet connection.

open <servername/IP> 25

25 is the default port number where SMTP service listens. Make sure your SMTP service is configured with default port number. If not use appropriate port number.
In the above command, we are opening telnet first and then opening a session with Server.
Instead we could use the following single command:

telnet <servername/IP> 25

If it is not able to establish a connection, then an error message would be displayed as “Could not open connection to the host…”. Then you need to check for connection error/firewall settings etc.

Assuming we successfully established the connection, the next step is to say hello to the server using following command. You would get a hello response from service.


Now, start creating an email. First enter from address using following command.
Note that there is a space between colon (:) and email address. After multiple attempts, I realized that space is mandatory.  Without a colon, it throws some random error and the error message doesn’t help much.

mail from:

Enter the recipient’s address using following command. Here space is not required after colon (I didn’t know why?)


Next step is to enter email text. To do this, type following command and press enter.


Then enter email Subject. Press “Enter” twice. Then enter email body/content. Then press “Enter” twice. In the end enter a period (.) and press “Enter”.

Subject:(email subject…)
(email content goes here… )

Once you press Enter, you would see a confirmation message saying the message was sent successfully. You can check your email and verify email headers. The headers should show the SMTP server name from where the message was sent.

While testing this functionality, I observed that sometimes it throws random errors though you enter correct commands.  I realized that if we re-execute the same command next time, it would be successful.



Please provide your feedback/comments/suggestions that will help me improve my blogging.


In this article, we are going to discuss on Web browser automation and how to leverage test cases so that a single test case can run on different type of browsers.
Here, we are focusing on Web Driver approach, where we instantiate specific browser driver and run the tests locally. There are other options like Selenium RC and Selenium Grid where the test cases can be run on a remote server and also has options like parallel processing etc.

Selenium IDE:
Selenium IDE is an extension for FireFox which can be used for recording test steps and generate test scripts. It provides different export options including NUnit test cases for .Net.
Install Selenium IDE extension for FireFox from and follow the instructions.

Open Selenium IDE from FireFox browser. The typical screen looks like below.


Now click on the Red button to capture steps. Perform test steps on the web page. You could observe that each action would be captured on IDE. Now you may want to add an assertion for verifying results. For instance, we may want to verify text on particular label. Select assertText Command from Command dropdown and click on Select. Now you could select a field on the web page and when you click on a field on the page, it would be selected as Target on Selenium IDE. Enter the value as “Results” in value field on IDE. Now we are asserting against the value “Results”. If it matches, then test would succeed otherwise it would fail. For more details on capturing test steps on Selenium IDE, you may search on google or youtube for help videos.

Exporting Test Cases:
We have captured test steps using Selenium IDE and now we would export the test cases in C# .Net syntax. Selenium supports multiple formats for Exporting. However, we want to export as C# NUnit test cases in this example.
Go to File -> Export Test Case As and select C# /NUnit /Webdriver. Save file as Results.cs to local drive.

Selenium IDE provides few configuration settings which are important for generating test code. For instance, XPath selector doesn’t work on Internet Explorer or Edge browsers. So, we could tell IDE to include only specific Selectors. To do this, go to Options -> Locator Builders. Locator Builder window will be opened.  We can reorder the locator list based on our requirement.  In this example, I have moved xpath:position selector to end of the list, so that it would be the last option for IDE to use while generating test cases.

Single Test class for different browsers:
Now we have exported the test case to C# code and generated a N-Unit test case. Visual Studio has an extension called NUnit Test Adapter for N-Unit test cases. Once we install it we could run NUnit tests inside Visual Studio Test Explorer along with VS test cases.

The next step is to install web drivers for different browsers. The following nuget packages are available for this.

Define the Test class as generic of type IWebDriver. TestFixture attribute takes driver type as a parameter. In the test class constructor, instantiate the generic type. Depending on current type, the appropriate driver will be instantiated. We can specify different TextFixutre attributes depending on what all browsers we want to test. See the code snippet below.

public class LoginTest<TDriver> where TDriver : IWebDriver, new()
        private ISelenium driver;
        private StringBuilder verificationErrors;

        public void SetupTest()
            driver = new TDriver();
            baseURL = "http://localhost:33517/";
            verificationErrors = new StringBuilder();

        public void TeardownTest()
            catch (Exception)
                // Ignore errors if unable to close the browser
            Assert.AreEqual("", verificationErrors.ToString());

        public void LoginTest()
            driver.FindElement(By.CssSelector("#login-form form")).Submit();

            //Assert here for success

Once we apply TextFixtures for number of different browser drivers, we could see those many number of Tests in Visual Studio Test Explorer. In above case, there will be 4 tests with the name LoginTest. On mouse hover, each test case can be seen with different browser name.
NUnit provides setup and cleanup methods, which are applied with SetUp and TearDown attributes. These will be executed for each and every test.

Issues observed with different browsers:

  • Xpath selectors aren’t supported by IE and Edge drivers. Replace them with CSS selectors.
  • For Internet Explorer, if element.Click() desn’t work then we can use element.SendKeys(Keys.Enter) as an alternate.
  • Implement wait on Find element scenarios to address the issue of finding elements before they are loaded. See code below:

public void Login()
     var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));

  • Use Thread.Sleep() for scenarios where click event doesn’t actually trigger the action.
  • For Edge browser, you may have to run click command twice in some scenarios.

Creation of Desktop and Start Menu shortcuts:

In this article I would discuss on creating Start Menu and Desktop shortcuts for an application using Wix installer scripts. I would also discuss about a warning message 1910 which is related to unable to delete desktop shortcut while uninstalling and how to address the issue.
(here I am not going to discuss about creating a Wix installer for the application, rather I assume we
already have a Wix installer and we will be adding Start Menu and Desktop shortcuts to it).

First step, we need to add componentRef’s for start menu and desktop short cuts under Feature element. They are named as ApplicationShortcut, ApplicationShortcutDesktop respectively in the below example.

<Feature Id="ProductFeature" Title="<App name>" Level="1">
      <ComponentRef Id="ApplicationShortcut" />
      <ComponentRef Id="ApplicationShortcutDesktop" />

Second step, add directories under Fragment for these two folders using ProgramMenuFolder and DesktopFolder keywords as shown below.

<Directory Id="ProgramMenuFolder">
        <Directory Id="ApplicationProgramsFolder" Name="<App name>" />
      <Directory Id="DesktopFolder" Name="Desktop"></Directory>

Add component for ApplicationShortcut under ApplicationProgramsFolder directory reference.

We need to generate a unique guid for each component. Add shortcut for ApplicationStartMenuShortcut under component. Target property need to refer to Installation folder and should specify the executable name. Assign install folder for WorkingDirectory property so that app related file I/O refers to this location.

The next step is to add RemoveFolder, which will be called during uninstallation process.

Final step is to add a RegistryValue and specify as current user.

Follow the same steps for adding desktop shortcut.

The complete section looks like below:

 <Feature Id="ProductFeature" Title="<App name>" Level="1">
      <ComponentRef Id="ApplicationShortcut" />
      <ComponentRef Id="ApplicationShortcutDesktop" />
    <Directory Id="TARGETDIR" Name="SourceDir">
      <Directory Id="ProgramFilesFolder">
        <Directory Id="INSTALLFOLDER" Name="<App name>">
          <Directory Id="ENRESOURCESFOLDER" Name="en" />
      <Directory Id="ProgramMenuFolder">
        <Directory Id="ApplicationProgramsFolder" Name="<App name>" />
      <Directory Id="DesktopFolder" Name="Desktop"></Directory>
    <DirectoryRef Id="ApplicationProgramsFolder">
      <Component Id="ApplicationShortcut" Guid="<add guid>">
        <Shortcut Id="ApplicationStartMenuShortcut" Name="<app name>" Description="<your app description>" Target="[INSTALLFOLDER]YourApp.exe" WorkingDirectory="INSTALLFOLDER" />
        <RemoveFolder Id="RemoveApplicationProgramsFolder" Directory="ApplicationProgramsFolder" On="uninstall" />
        <RegistryValue Root="HKCU" Key="Software\<Your app folder>" Name="installed" Type="integer" Value="1" KeyPath="yes" />
    <DirectoryRef Id="DesktopFolder">
      <Component Id="ApplicationShortcutDesktop" Guid="<Add guid>">
        <Shortcut Id="ApplicationDesktopShortcut" Name="<Your app name>" Description="<Your app description>" Target="[INSTALLFOLDER]YourApp.exe" WorkingDirectory="INSTALLFOLDER" />
        <RemoveFolder Id="RemoveDesktopFolder" Directory="DesktopFolder" On="uninstall" />
        <RegistryValue Root="HKCU" Key="Software\<Your app folder>" Name="installed" Type="integer" Value="1" KeyPath="yes" />

Warning 1910:
One of the issue I have observed with desktop shortcut is, it throws following warning while uninstalling.

Warning 1910. Could not remove Shortcut . Verify that the shortcut file exists and that you can access it.

Uninstallation process can’t delete the desktop shortcut due to above warning. It happens only for desktop shortcut and there are no issues with start menu shortcut. The uninstallation would be successful even though there is warning, however the desktop shortcut wouldn’t be deleted. Based on analysis it looks like it is happening due to file/directory attribute settings of desktop.

To fix this issue, go to C:\Users\Public\Desktop and find desktop.ini file. This is a system file. So if you don’t see it then go to folder options and uncheck following check boxes under view tab to view hidden/system files.

  • Don’t show hidden files, folders, or drives.
  • Hide protected operating system files (Recommended).

Un check above check boxes and desktop.ini file would be visible now.

Go to file properties of desktop.ini and Un-check Read-only to remove read only property.
Now try to uninstall your application and you wouldn’t see the earlier warning message.


An app for Office is basically a webpage that is hosted inside an Office client application.  It enables users to run the same solutions across applications, platforms and devices.  The applications are developed by using the powerful web technologies such as HTML5, XML, CSS3, JavaScript and REST API’s.    Refer MSDN documentation on Office Apps for more details.

The three basic types of Office apps are task pane, content and mail apps.  In this article I am going to explain how to develop an Office 2013 Excel Task pane app that acts as a live data work book.  The app will have following functionalities:

  • Communicating with an external WCF service to fetch live data
  • Write data into excel work sheet from Task pane app.
  • Track data modifications in excel work sheet.
  • Save modifications to Database through WCF service.


Connecting to a WCF data service:

Here I am going to start with WCF communication part.  However if you are looking for instructions on how to create a basic Excel task pane app, please refer MSDN.  The task pane app can communicate with an external WCF data service in following ways:

  1. Office Client (JavaScript) to External WCF service
  2. Web Service to WCF Service

1)     Office Client (JavaScript) to External WCF data service:

In this approach the communication part is written in java script, which is executed at client side.

Use JQuery to communicate with WCF data service as shown below.    The first step is construct an URI which should be understandable to WCF Data service.  Writing complex URI queries is tricky however a tool called LINQPad can be used for URI construction.  In this example Dataservice is hosted at http://localhost:17203/MyService end point.


One of the major issue with java script client side communication is same-origin policy limitation.  Generally browsers don’t allow clients talking to servers which are not in same domain.  One of the way to overcome this issue is enabling CORS.  The following setting will do that.

$.support.cors = true;

Tip: When you add a project of type “Office 2013 App”, visual studio creates a web project for you for developing UI for the app.   If you run app in debug mode from Visual Studio, the web project will be hosted on IIS Express on SSL.  In that case, above code may throw following exception “Access denied”.  To resolve this issue, host the web application on IIS (basic http) or use a self-hosted Web service.

The other approach is using JayData. JayData library comes with a utility called JaySvcUtil.exe which can be used to generate a context file in java script.  Use following command to generated the context file.pic3

Once context.js file is created, add it to the project.  Below is the command to generate java script context.

Tip: WCF data service by default enables metadata on $metadata end point.  So make sure to append ‘$metadata’ to the service end point while generating context.


Generating static context with JaySvcUtil.exe may have maintenance issues.  Whenever service contracts are changed we need to regenerate proxy and add it to the project.  We can avoid that by creating context dynamically with following command.


Another approach is to use JasonP. I am not covering this topic here however it can be used to resolve Cross domain communication issues.

2)     Web Server to WCF Service:

As mentioned earlier, due to same-origin policy limitations we may encounter issues like ‘Access Denied’ exceptions while trying to communicate with external WCF service in java script.  So this is an alternate approach to overcome that issue.

The communication happens in two steps in this approach:

Office Client <-> Webserver (server side Code) <-> External WCF service

Office client (java script) calls a Web Method which is executed at ASP server side.  Then Web Service makes a call to WCF service.  Here are the steps to achieve it.

Add a service reference (using WCF data service end point) to the project.  Add an ASP .Net page to the project.  Go to the class in aspx.cs file and write following lines of code.


We are creating a context using Service reference by specifying the service end point. In this example it returns a list of accounts.   Make sure the method is decorated with WebMethod attribute so that it can be accessed from client’s JavaScript.  Using PageMethods we can call the server side method as shown below.


Writing data into Excel sheet:

Till now we have focused on WCF service communication and fetching the data from service.    Now we are going to see how we can populate the excel sheet with the data.  setSelectedDataAsync method is used for writing data into excel sheet in selected location. This is defined in Office JavaScript library.  We can write data in 3 formats such as matrix, table, and text.  I will use table data type so that we can display headers along with data.  First create table data. In below example, ‘res’ is the collection which is received from WCF service.  First we specify the headers and then push the data rows.


Now write the table data in excel sheet at current selection.  Most of the Office java script library methods are asynchronous so that it doesn’t block the Excel interaction with end user.


Tracking changes in the excel sheet:

Now we want to track changes made by user in excel sheet so that modifications can be automatically sent to WCF service for saving them in Database.  We can use databindings and datachanged event hanlder.

Office.context.document.bindings is a collection of bindings specific to the document.  Add a new binding to this collection and specify the type as table data.  On success, we can add a handler of type ‘BidningDataChanged’.  When data is changed we receive a parameter called eventArgs.   We can use eventArgs.binding.getDataAsync method to reading current data from excel.  One of the drawback with datachanged is, it doesn’t specify what is changed.  It could be an update to a cell or addition/deletion of new row/column, so we need to write custom logic to identify the change and act on it accordingly.


Please provide your valuable feedback/comments/suggestions that will help me improve my writing.