Friday, April 14, 2017

MSTest Tool for executing test cases using dll with only Visual Studio Agents Installed



Download and Install Visual studio agents from following location:

vs 2012:
https://www.microsoft.com/en-in/download/details.aspx?id=38186

vs 2013:
https://www.microsoft.com/en-in/download/details.aspx?id=40750


vs 2014:
https://www.microsoft.com/en-us/download/details.aspx?id=48152


After downloading extract the folder, you can find the following files:


Open TestAgent and install it.

After installing TestAgent, we can find the following folder and file.

C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\MSTest.exe



Visual studio Solution & code:

Solution Explorer

Layout of MSTest Tool:

  1. MSTestRun.cs File
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Windows.Forms;

namespace MSTestRun
{
   public partial class Form1 : Form
   {
       public Form1()
       {
           InitializeComponent();
       }

       private void SelectDLL_Click(object sender, EventArgs e)
       {           
           Stream myStream = null;
           OpenFileDialog openFileDialog = new OpenFileDialog();

           //openFileDialog.InitialDirectory = "c:\\";
           openFileDialog.InitialDirectory = @"c:\";
           openFileDialog.Filter = "DLL's (*.dll)|*.dll";
           openFileDialog.FilterIndex = 2;
           openFileDialog.RestoreDirectory = true;

           string dllLocation = "";
                                  
           if (openFileDialog.ShowDialog() == DialogResult.OK)
           {
               try
               {
                   if ((myStream = openFileDialog.OpenFile()) != null)
                   {
                       dllLocation = openFileDialog.FileName;
                       dllPath.Text = dllLocation;

                       TestListInAssembly clas = new TestListInAssembly();
                       List<string> testCases = clas.GetTests(dllLocation);

                       dataGridView1.DataSource = testCases.Select(x => new { Value = x }).ToList();
                       dataGridView1.Rows[0].Cells[0].Selected = false;
                      
                   }
               }
               catch (Exception ex)
               {
                   MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);
               }
           }
       }

       private void ExecuteTest_Click(object sender, EventArgs e)
       {
           try
           {              
               if (dataGridView1.SelectedCells.Count == 0)
               {
                   MessageBox.Show("No test selected", "Error", MessageBoxButtons.OK);
                   return;
               }
              
               string testName = dataGridView1.SelectedCells[0].Value.ToString();
               string batpath = Path.Combine(System.IO.Path.GetTempPath(), "mstestscript.bat");
               var command = Environment.GetEnvironmentVariable("ComSpec");
               command = @"" + command + @"";

               string vsVersion = VsVersionSelected();

               string VisualStudioCmdPrompt = string.Format("cd \"C:\\Program Files (x86)\\Microsoft Visual Studio {0}.0\\Common7\\IDE\"", vsVersion);

               string vsMstestPath = string.Format("C:\\Program Files (x86)\\Microsoft Visual Studio {0}.0\\Common7\\IDE\\MSTest.exe", vsVersion);

               if (!File.Exists(vsMstestPath))
               {
                   MessageBox.Show("Path Not found : " + vsMstestPath, "Path Not found", MessageBoxButtons.OK);
                   return;
               }

               CreateBatFile(batpath);

               string mstestScript = string.Format("mstest /testcontainer:\"{0}\" /test:{1}", dllPath.Text, testName);
               using (StreamWriter sw = new StreamWriter(batpath))
               {
                   sw.WriteLine(VisualStudioCmdPrompt);
                   sw.WriteLine(mstestScript);
                   sw.WriteLine("pause");
               }

               //Executing in Admin mode
               ProcessStartInfo info = new ProcessStartInfo(batpath);
               info.UseShellExecute = true;
               info.Verb = "runas";
               Process.Start(info);
               //System.Diagnostics.Process.Start(batpath);
           }
           catch (Exception ex)
           {
               MessageBox.Show("Unknown Exception, Contact Developer", "Error", MessageBoxButtons.OK);
           }
       }

       public string VsVersionSelected()
       {
           if (VS2012.Checked)
           {
              return "11";
           }
           else if (VS2013.Checked)
           {
               return "12";
           }

           else if (VS2015.Checked)
           {
               return "14";
           }
           else
           {
               return "";
           }
       }

       public void CreateBatFile(string batpath)
       {
           if (File.Exists(batpath))
           {
               File.Delete(batpath);
           }

           using (FileStream fs = File.Create(batpath))
           {
               fs.Close();
           }
       }
   }
}

2. TestListInAssembly.cs
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;

namespace MSTestRun
{
   public class TestListInAssembly
   {        
       public List<string> GetTests(string dllLocation)
       {            
           List<string> testcasesList = new List<string>();
           Assembly assembly = Assembly.LoadFile(dllLocation);

           /* This code is used to specfically check the test cases in the Particular Namespace and Class           
           string Namespace_ClassName = ConfigurationManager.AppSettings.Get("Namespace.ClassName");
           Type type = assembly.GetType("Namespace.ClassName");
           Type type = assembly.GetType("testsuite.CaligoTest");*/

           Type[] types = assembly.GetTypes();
          
           foreach (Type type in types)
           {
               MethodInfo[] mi = type.GetMethods();

               foreach (MethodInfo method in mi)
               {
                   string memeber = method.MemberType.ToString();
                   object attribute = method.GetCustomAttributes(typeof(TestMethodAttribute)).FirstOrDefault();

                   if (attribute != null)
                   {
                       testcasesList.Add(method.Name);
                   }
               }
           }
          
           return testcasesList;
       }
   }
}

















Monday, March 20, 2017

Viewing auto-generated code of Manual Test recording in Test runner



Prerequisite:
Visual studio ultimate/Premium installed.

  1. Record the actions in test runner(MTM) for a Test Case and Save & close.

    cid:image005.jpg@01D0A863.2D7F23C0


  1. Open Visual studio File New Project

  1. Select Test Coded UI Test Project


cid:image006.jpg@01D0A863.2D7F23C0

      4.
            cid:image008.jpg@01D0A863.2D7F23C0

     5.

     cid:image012.jpg@01D0A863.2D7F23C0

6. In the solution, the Auto-code generated will be populated.

cid:image013.jpg@01D0A863.2D7F23C0



Friday, March 10, 2017

Latest Open Source Tools for Web Developers

Latest Open Source Tools for Web Developers

Angular/Angular JS:
Current Version:  Angular 2
JavaScript-based open Source Web Application framework for dynamic mobile and desktop Web app development. It is mainly developed to address challenges encountered in single page web applications.
Key features: Data-Binding, extensible HTML, speed, mobile oriented, supports server side pre rendering, animation

Node.js:
It’s an open source, cross-platform JavaScript runtime environment for developing a diverse variety of tools and applications. Node.js uses an event-driven, non-blocking I/0 model.
SASS - Syntactically awesome style sheets
Helps to reduce repetitive work and maintainability challenges of traditional CSS.  It’s the most powerful CSS extension in the world.

Bootstrap:
Fast development of responsive design. It has a set of its own classes and grids, button, forms, navigation, containers, media queries and JavaScript extensions.

GitLab:
Its used by developers to create and manage code bases collaboratively.
Ex: Code review t issue tracking.

Elasticsearch:
It’s based on Lucene. It provides a distributed, multi-tenant-capable full-text search engine with an HTTP Web Interface and schema –free JSON documents.  Zit used RESTful APIs and JSON.
XAMPP
X-cross platform, Apache, MariaDB, PHP and PERL.  It’s the simplest way to set up a local Web Server.
Notepad++”
Provides tabbed editin,syntax highlighting and code folding for more than 50 programming , scripting and markup languages.

Grunt :
Grunt is a JavaScript task runner built on Node.js. When we are working on a JavaScript project, there are some task that you will do regularly, like minifying your scripts compilation, unit testing, running JSHint on your code. You can define this set of tasks in Grunt file and run a single command from a command line interface to do these tasks.

ReactJS:
JS library for building user interfaces. It allows us to create reusable UI components. 

Thursday, March 9, 2017

Creating Environment with System Center Virtual Machine / Hyper-V with Virtualized Network


Creating Environment with Virtual Machine and Virtualized Network.
After installing Operating system here it is Win10, then
1. We should remove the ISO file from the Virtual machine in SCVMM
2.  Refresh the VM in SCVMM
Right after if we try to create environment we will get the following details.

Follow the below steps:
Step1: Disable Firewall in Virtual Machine
After this we can find the following error.

Step2:  Adding Host Server Virtual Server IP address in VM host file.
 Check the TestController server is accessible from Virtual Machine by using ping command in Cmd prompt.
Check both the following options and should have reach the server and get reply.
  1. Ping xx_HostServerName_xx
  2. Ping xx_HostServerName_xx.domain      i.e, FQDN (Fully Qualified Domain Name)
Again you will find the same error as previous

Step 3: Disable Remote User Access in Virtual Machine


Now we can create the environment successfully.

Monday, March 6, 2017

Test Management Tools and Configuration



======================================================================

Best Test Management Tools Vendors


===================================================================


Automated Web Deployment and Team Build Using TFS 2013:


http://www.c-sharpcorner.com/UploadFile/raj1979/automated-web-deployment-and-team-build-using-tfs-2013/

https://blogs.msdn.microsoft.com/mvpawardprogram/2011/10/17/automated-build-deploy-test-using-tfs-2010/









JMeter Simple Controller

  Simple Controller is just a  container  for user request.