Tuesday, January 26, 2016

Linking your Selenium Tests to Microsoft Test Manager (2)

Introduction


Last time we talked about a way of linking selenium Mstests to MTM. This week we will see another way of linking an automated test with a MTM test plan by using tcm import tool (so we don't need to to this manually).

TCM Import


Here you have the link to MSDN documentation https://msdn.microsoft.com/en-us/library/ff942471(v=vs.120).aspx
The purpose of this tool is to import automated tests (selenium, codedui, unit tests, etc.) to a Test plan written in MTM (Microsoft test manager). The import will be done only for MSTests methods (not NUnit). The result of the import will create an work item of type Test Case in TFS, for every existing TestMethod in your projects. The example from the last post was this.


Here we have only one method named CodedUiTestMethod1, which, in fact contains Selenium code. 
In order to create a corresponding Test Case work item I did this:
- Opened Developer Command Prompt for VS2013 that you can find it in Visual Studio Tools folder (e.g. C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\Tools\Shortcuts for VS 2013)
- In cmd navigated to the location of your .dll with tests
- Run this command
tcm testcase /import /collection:https://myonlineproject.visualstudio.com/DefaultCollection

/teamproject:myProjectName /storage:LinkMTMSelenium.dll
- Now the Work item of type Test case with the name CodedUiTestMethod1 is created
- Associate this Test Case to a Project Plan in MTM

- Set your environment in MTM like described in the previous post
- Run your test from MTM from Test tab. Run will be run on the configured environment 



- Search results will be displayed at the end and the required 


- You will be able to see the test results also in VS Online

Happy testing and... make it green, becomes a dream :).


Friday, January 15, 2016

Linking your Selenium Tests to Microsoft Test Manager

Introduction


In this article we will write about how you can link your selenium web driver tests from Visual Studio to Microsoft Test Manager.
Why should we do this? Because with CodedUI you can run your tests only on a IE browser (even there is a plugin that allows you to run coded ui tests on FF/Ch, which is unfortunately not very stable). With selenium, you'll be able to run them much easier on different browsers.

What do you need for this:

- knowledge about Visual Studio Controllers and agents

- knowledge about TFS builds

- knowledge about MTM (Microsoft Test Manager) and how to set an environment

- Have some tools installed: Visual Studio 2013 Online

- know how to work with Selenium WebDriver with C#
- MSTest (not NUnit)to run the tests


Visual Studio Test Controllers and Agent

I'm not going to give you details about this subject because this is a complex one. But, in order to explain you this post, you need to know what MTM environment is. In order to run your automated tests on a specific page, you need to set an environment, which requires a controller that controls one ore more agents. For more details visit this link: https://msdn.microsoft.com/en-us/library/hh546460(v=vs.120).aspx.
Visual studio agent and controllers can be downloaded from here: https://www.microsoft.com/en-us/download/confirmation.aspx?id=40750.
Once you set your controller, you need to add an environment in MTM. To do this open MTM as an admin --> Lab center and create a new environment.
In Type and name, leave the default standard environment and give a name to this new env
In Machines enter the name of the computer where you want to install your agent that will execute the tests and that will be connected to a controller.
In Advanced, select the controller and check Configure environment to run UI tests = Web Client



Verify and restart computer. After restart you'll see a popup with your agent



MTM Build

Another important setting is the build for your automated testing project (with selenium tests).
A build for a MSTest project can be created from Visual Studio. Having your selenium web driver solution opened, go to Team Explorer --> Builds --> New Build Definition.
In Source Settings Add the Repository name:


Build Default -> if you use Visual Studio Online, you can leave it to Hosted Build Controller
Process --> set the path to your .sln solution
Run your build

Adding Environment and Build to MTM Test Plan

Once you have add your agent and build, you need to assign these two, to your test plan in MTM.
Open it, select your test plan, go to Organize and made the settings below.

Create your Selenium Test and Associate it to a Manual Test from MTM

Now you should create your selenium tests. To be much easier, instead new MSTest, create a new CodedUI test. Why, because you'll need (in order to run it from MTM) the CodedUI attribute for a class. Inspect the code below:


This will only open google home page. You can see the DeploymentItems attributes. They are required, in order to deploy chrome and ie drivers on the agent you'll run your tests.
After you created your test, you need to associate it to a dummy MTM test (or to an existing recording in MTM - see this link for more details: http://blogs.infosupport.com/testing-your-web-application-with-selenium-and-mtm-part-2/).
To associate Mstest to MTM test in Visual Studio (with the solution opened), go to TeamExplorer --> Work Items-->made a new query that will return all manual test cases written for this project --> open your manual tc --> go to Associated Automation and select your MSTest


Now you can start running your test from MTM. While the test runs, you'll see this in Agent Popup.

Happy testing and... make it green, becomes a dream :).

Popular Posts