How to work with NUnit Assertion as step in Test Studio

Learn more about Test Studio here

clip_image001

After I written this post How to work with MS Unit Test Assertion as step in Test Studio , I got a question,

How can I use NUnit Test Assertion in a Test Step while automating test with Test Studio?

Answer of this questions is also lies in three steps,

Step 1:

Add reference of nunit.framework dll in Test Project

Step 2:

Create a coded step

Step 3:

Write Assertion in test

Add Reference

There are in two ways you can work on Test Studio. Either on Visual Studio plugin or on Test Studio standalone version.

Adding reference in Visual Studio is simpler. Right click on test project and from context menu select Add Reference. Browse to nunit.framework.dll library and add reference in test project.

Even though you have added reference in Visual Studio make sure that you have added reference in test project opened in standalone version else you will get exception.

To add nunit.framework.dll assembly in Test Studio standalone version you need to follow following steps,

Select Project option in top menu

image

Click on Show Settings in project tab

image

On clicking on Show Settings you will get Project Settings dialog box. In dialog box click on Script Options. To add assembly reference click on Add Reference.

image

When you clock on Add Reference Test Studio will open File Chooser dialog box. In that browse nunit.framework.dll assembly reference location in file system and select that to add as reference in current Test project.

Create a coded step

To create Coded Step in select Test and from menu

image

You will find coded step added as below,

clip_image001[6]

Write Assertion in Test

Once Coded step is added you can write any assertion. To validate I am writing a very simple assertion as below,

You can view below code in Visual Studio,


[CodedStep(@"New Coded Step")]
 public void NunitTest_CodedStep()
 {
 NUnit.Framework.Assert.AreEqual("Telerik", "Telerik");

}

In Test Studio standalone version codes step will look like as following,

clip_image002

Now go ahead and execute test. You should able to get test passed successfully as given below,

clip_image003

I hope you find this post useful. To speedup automated testing do not forget to download trail of Test Studio from here

clip_image004

How to verify number of cookies while automating a test in Test Studio

Learn more about Test Studio here

Yes these kind of questions are very simple but have a sustainable impact while automating a test. Recently I got a question that,

I want to verify number of cookies in web application while automating test. How Test Studio can help me in that

This test scenario could be very important. Test Studio surprisingly simplify these kind of requirement while automating test. So to verify number of cookies in web application,

  1. Add Coded Step
  2. Add reference of MS Unit Test
  3. Read number of cookies
  4. Assert number of cookies with expected value.

To Add Coded Step and reference of MS Unit Test follow this post

Once you have added reference of MS Unit Test and added a coded step start writing following scripts in coded step,

Read cookies of web application being in test as following. Do not forget to change URL with URL of web application you are testing.

image

Now in browserCookies all cookies are being read. You can read count of cookies as below,

image

Once you have cookies count in variable count you can verify its exact value and assert result using MS Unit Test Assert. This can be done as following

image

Where baseCountValue could be any constant value. Putting all together script of coded step would like following,

 


[CodedStep(@"New Coded Step")]

 public void WebTest_CodedStep()
 {
 int baseCountValue = 2;
 var browserCookies = ActiveBrowser.Cookies.GetCookies("URL of your App");
 var count = browserCookies.Count;
 Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AreEqual(count, baseCountValue);

}

On running you can see that below test is verifying that number of cookies associated with URI is zero.

image

In this way you can verify number of cookies in Test Studio. I hope you find this post useful. Thanks for reading.

I hope you find this post useful. To speedup automated testing do not forget to download trial of Test Studio from here

image

How to work with MS Unit Test Assertion as step in Test Studio

Learn more about Test Studio here

More you meet people more questions you get. I love this part of my job, meeting and answering people queries. I usually talk to Test Professional who are doing manual testing. So some of their questions are very basic and this is expected because they are not coming from coding or programming background.

Recently in one of seminar I came across a question

How can I use MS Unit Test Assertion in a Test Step while automating test with Test Studio?

Answer of this questions is in three steps,

Step 1:

Add reference of Microsoft.VisualStudio.QualityTools.UnitTestFramework dll in Test Project

Step 2:

Create a coded step

Step 3:

Write Assertion in test

Add Reference

There are in two ways you can work on Test Studio. Either on Visual Studio plugin or on Test Studio standalone version.

Adding reference in Visual Studio is simpler. Right click on test project and from context menu select Add Reference. Browse to Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll library and add reference in test project.

Even though you have added reference in Visual Studio make sure that you have added reference in test project opened in standalone version else you will get exception.

image

To add Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll assembly in Test Studio standalone version you need to follow following steps,

Select Project option in top menu

image

Click on Show Settings in project tab

clip_image001

On clicking on Show Settings you will get Project Settings dialog box. In dialog box click on Script Options. To add assembly reference click on Add Reference.

clip_image003

When you clock on Add Reference Test Studio will open File Chooser dialog box. In that browse Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll assembly reference location in file system and select that to add as reference in current Test project.

Create a coded step

To create Coded Step in select Test and from menu

image

You will find coded step added as below,

clip_image001[6]

Write Assertion in Test

Once Coded step is added you can write any assertion. To validate I am writing a very simple assertion as below,

You can view below code in Visual Studio,


[CodedStep(@"New Coded Step")]

 public void WebTest_CodedStep()
 {
 Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AreEqual("TestStudio", "TestStudio");

}

In Test Studio standalone version codes step will look like as following,

clip_image002

Now go ahead and execute test. You should able to get test passed successfully as given below,

clip_image003

I hope you find this post useful. To speedup automated testing do not forget to download trial of Test Studio from here

clip_image004

Testing with LINQ in Test Studio

Recently I was giving demo on Test Studio to one of  the customer. In demo one of the participants raised a question that, “How could I use LINQ (Language Integrated Query) to insert some data back to database after test execution gets completed “

I demoed to team  that how they could use LINQ in test. In this post, I will walk you through steps required to test with LINQ in Test Studio. We will insert data back to database as last step of the test.

Essentially we can achieve in these three steps

  1. Write LINQ and business logic in different library
  2. Add library as reference in test project
  3. Write script of coded step calling library functions.

To start testing with LINQ, add a coded step in your test. To add coded step select Test from menu and then Script Step from ribbon as given in below image.

image

Once Code step is added export test project to Visual Studio. To export to visual studio from menu click on Export to Visual Studio as shown in image below,

clip_image001

Creating Library to work with LINQ

Now in visual studio you need to add operations related to LINQ in different class library. Idea is that we will create separate library for LINQ operation and later we will add that library to Test Studio.

clip_image003

Assume that we have created a library with name DataLibrary. This Library got

  1. LINQ data context classes
  2. We added a static class in which operation is being performed to insert data back to database.

So DataHelper class contains following code to insert data to database using LINQ.


public static class DataHelper
 {

public static void InsertItem()
 {
 DataClasses1DataContext context = new DataClasses1DataContext();
 Product p = new Product
 {
 Discontinued = false,
 ProductID = 99,
 CategoryID = 2,
 ProductName = "Test Studio 9",
 UnitPrice = 200
 };

context.Products.InsertOnSubmit(p);
 context.SubmitChanges();

 }

}

Adding Reference in Test Project

There are in two ways you can work on Test Studio. Either on Visual Studio plugin or on Test Studio standalone version.

Adding reference in Visual Studio is simpler. Right click on test project and from context menu select Add Reference. Browse to DataHelper.dll library and add reference in test project.

Even though you have added reference in Visual Studio make sure that you have added reference in test project opened in standalone version else you will get exception.

image

To add DataHelper.dll assembly in Test Studio standalone version you need to follow following steps,

Select Project option in top menu

clip_image001[6]

Click on Show Settings in project tab

clip_image002

On clicking on Show Settings you will get Project Settings dialog box. In dialog box click on Script Options. To add assembly reference click on Add Reference.

image

When you clock on Add Reference Test Studio will open File Chooser dialog box. In that browse DataHelper.dll assembly reference location in file system and select that to add as reference in current Test project.

Writing Coded Step

Once reference of DataHelpe.dll is added in test project you need to write script for coded step. We can insert a row in database by calling static InsertItem method. So coded step will be as following


[CodedStep(@"New Coded Step")]
 public void LINQ_Test_CodedStep()
 {

DataHelper.InsertItem();

 }

In this way we can test with LINQ in Test Studio. To summarize

  1. Write LINQ and business logic in different library
  2. Add library as reference in test project
  3. Write script of coded step calling library functions.

I hope you find this post useful. To speedup automated testing do not forget to download trail of Test Studio from here

image

What is Test Oracle

Test oracle determine that whether a test executed as expected or not. Essentially you can say test oracle is a mechanism to determine whether program, software or application got executed as expected for a particular Test Case or not? A test oracle may be either manual or automated.

Let us understand test oracle with an example. You are automating test of File Download Functionality. Downloading of file may take following steps

  • User will click on a Button
  • On click of button Operating System File Download dialog will open
  • User will select download location
  • File download will start

In above test case to verify successful download of file you may want to create a test oracle which will verify size of downloaded file on the file system. Hence in this case,

image

Test Oracle is very specific to a business scenario and probably tool may not able to automate this. Test Oracle can be written as Coded Step.

We can summarize Test Oracle as parameter which verify that whether application passed a test for a particular test case or not.

What is Document Object Model?

While automating a test understating of DOM is very essential. Any tool read DOM to automate test. In this post we will try to understand what DOM is in simplest words. Tool sees whole page you are doing automation testing as DOM and searches, finds elements in DOM.

As of W3C definition: DOM stands for Document Object Model and it is a programming interface to manipulate a well formed HTML or a valid XML document. Here we will discuss DOM in context of HTML.

Technically, browsers create DOM after parsing the HTML. All browsers follow the specification given here to create the DOM. DOM created by Browsers can be accessed and manipulated by programming languages like JavaScript. Essentially, you can say that DOM connects web pages to programming languages.

image

DOM expose everything of the web page as objects to programming languages like JavaScript. Whether it is elements, events, styles etc. all are exposed as objects to JavaScript. Let us consider following HTML,

 

DOM will expose all the HTML elements as objects. These objects can be manipulated and updated by JavaScript.

image

In other words we can say that DOM is Application Programming Interface (API) which exposes HTML or XML as structured document to programming languages. This structure document can be manipulated by the languages like JavaScript. Above listed HTML can be exposed as following structured document by DOM.

image

DOM see a HTML document as tree. All elements can be seen as nodes of the tree. Attributes and value of elements can be seen as leaf of the tree.

Browsers generates DOM when it parses the HTML. For example, when you browse above HTML in browser it will parse the HTML and create DOM. You can view created DOM by pressing F12 in any mostly used browser.

image

I hope now you have descent understanding of DOM. You need understanding of DOM to automate test. I hope you find this post useful. Thanks for reading.

Why we need Coded Steps

image

Coded steps are the test steps which contain scripts or codes. In coded steps you write codes or scripts. Codes of coded steps will get executed as part of test execution. Coded steps can be very useful to automate testing of a complex unique business requirement which cannot be automated by tool. A good automated test should contain minimal numbers of coded steps.

Why we need coded steps

While automating test there may be many complex scenario which cannot be constructed using tool’s verification builder. In that scenario you may need to write codes to construct complex verification. This code will be executed with overall test as coded step. You may need to write coded steps in following scenario

  • Automating a complex verification which cannot be constructed by tool.
  • Writing Cleanup Steps. For example you may want to clean or delete all the temporary test files before or after executing test. It may be chances that tool might not able automate cleanup task. In this case you may have to write coded step for cleanup task.
  • Setting up Test Environment. You may need to set up test environment before executing test. Setting up environment may contain loading external test data, connecting to a dedicated server, loading user profile etc. It may be chances that tool might not able to set up environment for various testing scenario. In this case you may have to write coded step to set up test environment.
  • There may be complex test scenario like verifying that whether a particular file got downloaded successfully on file system or not. These types of tests are very tough to be automated by a particular tool. In this case you may have to write coded step to verify file size on file system.
  • There may be test scenario in which you need to create test data from multiple data sources. It may be chances that tool might not able to gather or mash up data from various data source. In this case you may have to write coded step to create test data.

Like above there could be many complex test scenarios which cannot be automated by tool. To automate those test scenario you will have to write codes steps.

How to automate “once login and perform many operation Test ” in Test Studio

I was talking to a customer and they wanted to test a CRM application. There test scenario more or less like below image. They wanted to execute Entry Test and Exit Test only once and Main Test any number of times. When we do manual testing of this scenario this is usual kind of test cases. However automating this test is not that simple. In this post we will take a look that how Test Studio simplify automating this type of test scenario.

image

Let us assume you need to automate a test for following scenario,

Test Step 1: Login to application

Test Step 2: Perform various operations

Test Step 3: Logout from application

Requirement is that user will Login only once, perform operations any number of times and then logout from application. Essentially step 1 and step 3 will be executed by user only once and step 2 will be executed any number of times. Iteration of step 2 depends on external data source. This may be usual automated testing scenario you always come across.

Now let us assume that you have recorded test as following,

image

In above test we are data driving step 6. We are performing usual data driven testing. Problem with this approach is that each steps will get executed number of times depending on rows in data source. So if there are 10 rows in test data then this each test steps will be executed 10 times.

Our requirement is different in above test steps we want to execute only test step 6 ten times and other test steps only once. Let us see how we can do this.

Step 1: Move test steps you want to execute many times in different test. Let us call this test as INNERTEST

Step 2: Make sure to data bind the INNERTEST

Step 3: Record OUTERTEST. In OUTERTEST record all the steps you want to execute only once.

So in above recorded test we can record step 6 as separate test. We are calling that test as INNERTEST. This test is data bind.

image

This INNERTEST will contain all the test steps we want to execute repeatedly. In this case we have test step in INNERTEST.

image

After recording INNERTEST, let us go ahead and record OUTERTEST. We need to put all test need to executed only once part of this test. So all test steps for Login and Logout will be part of OUTESTEST. You notice that we want these test steps to be executed only once.

image

Now from ribbon add a Test as step in OUTERTEST.

image

You need to choose INNERTEST as test as step to be part of OUTERTEST

image

We have added INNERTEST as test as step in OUTERTEST at step 6.

image

Now on execution of test you will find that all test steps are getting executed only once however test steps of INNERTEST will executed many times depending on number of rows of data source. So we can conclude that

image

In this way you can work with multilevel test using Test Studio. I hope you find this test useful. Thanks for reading.

How to work with Loops in Test Studio

You may come across many scenario in which you need to execute a particular test several number of times or in other words you need to execute certain number of test steps in a loop.

Let us consider following test. These are automated test steps for login functionality. Assume, you need to run step 2 to step 7 5 times with same data. In this scenario you need to execute from step 2 to step 7 in loop.

image

To automate above scenario Test Studio provides you out of box solution. You can automate above scenario with Logical Steps. In Test view you will find Logical Steps in Add section.

image

To put test steps in loop select loop Logical step from Add section and add a Logical Test Step in test. After adding logical step you can change Count. We are setting count as 5 here.

image

After setting Count drag and drop test steps you want to execute under test. Here we need to drag and drop step 2 to 7 in the loop. After dragging and dropping test steps test will look like below image. Now test step 2 to 7 will be executed 5 times.

image

In this you can execute a test in loop. Loop Logical steps should be used when you need to execute same test with same data many number of times. I hope you find this post useful. Thanks for reading.

Webinar Recap: Automated Functional Testing can be affordable with Test Studio

Ninja Enough? – Telerik India Webcasts (April – May 2013)

clip_image001

On 21st March 2013 we at Telerik India hosted webinar on Automated Functional Testing Can be affordable with Test Studio . We thank you for attending the webinar. In this webinar we tried a story way of presenting and on poll 75% audience liked that. This data was very motivating.

Find Test Studio resources at below links,

Download free trial from here

Learn more about Test Studio here

Read documentation here

In webinar, we started from scratch and did demo on

  • Recording a Test
  • Working with verification steps
  • Integrating bugs with TFS and Team Pulse
  • Data Driven Testing
  • AJAX Testing

Find below presentation from webinar,

If  you have any technical query feel free to reach me at

Dhananjay.kumar@telerik.com

And for any sales related query feel free to send a mail to

Abhishek.kant@telerik.com and sales@telerik.com

Thanks once again for attending webinar. See you in next webinar.

How to use a smaller test as Step of bigger test in Test Studio

Let us assume a scenario that we need to automate test of a complex functionality. This complex function may be constituted of other small functions. Now all small functions are tested separately. To automate test of this bigger function we have two choices

  1. Record all steps in bigger function testing
  2. Use various smaller functional tests as a step in bigger function testing.

Test Studio provides us a feature in which we can use a functional test as step of another functional test. You can get that option in Add section of ribbon.

clip_image002

Assume we need to test CRM application. We have separately created automated test for Login functionality of application as given below,

clip_image003

And steps of this test is recorded as following

clip_image004

Next we want to record test for bigger function Add Contact in CRM. To do that let us create a test as following,

clip_image005

Now we want to use Login Test as a step in Add Contact test. To do this double click on Add Contact test to open the test. After that from Add section in ribbon select Test as Step option.

clip_image006

You will get option to choose from all the tests added in the test project. In this case there is only one test other than Add Contact Test. So select Login Test to add as step in Add Contact test.

clip_image008

After adding Login Test as step right click on the test and from context menu select Run then To here option.

clip_image010

On selecting this option Test Studio will first execute all the steps of Login Test and allow you to record further steps for Add Contact test.

In this way we can add a test as step in Test Studio to use a functional test as part of another bigger functional test. I hope you find this post useful. Thanks for reading.

Working with Manual Steps in Test Studio

Recently I was talking to a customer. Customer was automating there CRM functionally test and they had to perform test steps as following,

Step 1: Navigate to portal

Step 2: Login to portal

Step 3: Browse through portal

Step 4: Logout from portal

They recorded test to automate as given in below image

clip_image002

Now they had requirement that they want to perform login steps manually. In other words they wanted to manually perform steps 2, step 3 and steps 4. They had a question that

Can we add manual steps to an automated test in Test Studio? “. Answer is “YES”.

To add manual step Add section in ribbon and select more option. In drop down you will find Manual Step option to add.

clip_image004

Select Manual Step to add a manual step in Test Steps. Give desired name of manual step and click on OK to add it.

clip_image005

After adding manual step deleted automated test steps for login. After adding manual step and removing automated test steps for login test will look like following

clip_image007

Now while running test after step 1 Test Studio will wait to perform manual step. In manual step login to CRM can be done manually.

clip_image008

After manually login further test steps will be executed automatically.

clip_image009

In this way I answered customer to work with manual steps in automated test. I hope you find this post useful. Thanks for reading.

 

How to Activate Test Studio Installation

In this post we will take a look on Activation process of Test Studio. After successful installation of Test Studio, you will be prompted to activate the installation.

clip_image002

Either you can activate the purchase license or activate as trial. To activate the purchase license select first option and click on Next to proceed further.

clip_image004

Again you have two options to activate. Either you can activate online which is recommended or offline using license key. You can find license key for Test Studio under Manage Product section of your Telerik Account. To activate online select online option and click on Next to proceed further.

clip_image006

Here you need to provide your Telerik credential. After providing Telerik Credential click on Activate to activate Test Studio.

clip_image008

After successful activation you will get above message. If you are running Test Studio as trial then you can activate it later as well. To activate it later launch Test Studio and click on the Help menu. In Help menu select View from About tab.

clip_image010

If you Test Studio installation is already activated then you will get license information as following image.

clip_image011

If you are running trial version then you will get an option to activate license.

clip_image012

In this way you can activate Test Studio. I hope you find this post useful. Thanks for reading.

From where to download Test Studio Run Time

In this post we will take a look on downloading Test Studio Run Time. To download browse to http://www.telerik.com/ . After successful login click on the Product Families and from bottom select Your Account.

clip_image002

Now choose Manage Products and select Test Studio.

clip_image004

Next click on the Download Installer and other resources

clip_image006

You will get option to download Test Studio run time as below.

clip_image007

In this way you can download Test Studio Run Time. I hope you find this post useful. Thanks for reading.

Few Queries on Test Studio : Answered

Recently I was giving demo on Test Studio. While demo there were few questions popped up . In this blog I am consolidating those questions such that it would be useful for all Test Studio users.

image

Does it work with Telerik SL CONTROLS

Yes Test Studio support SL controls. For demo, please see Telerik TV and look at the videos listed under the Silverlight tag:

http://tv.telerik.com/products/automated-testing-tools?FilterByTags=Silverlight

How would it integrate into a CI ENVIRONMENT

You can find more details about CI integration at

http://www.telerik.com/automated-testing-tools/support/documentation/user-guide/command-line-test-execution.aspx

How Test Studio works with MS LAB

We don’t have anything specific with how we integrate with the TFS/VS lab environment.

How does it run tests? Does it require agents to installed

If you want the tests run via the scheduler or remotely then you do need an agent installed. You can find more details here

http://www.telerik.com/automated-testing-tools/support/documentation/user-guide/scheduling-test-runs.aspx

Does it support SL 4 +

Yes Test Studio supports Silverlight 4+

Does it support mobile platforms like Windows Phone, Android and iPhone

Test Studio supports IOS but as a separate product. Currently Test Studio do not support Windows Phone and Android

Can Test Studio Framework API can be used from MS TEST

Yes it can be used with MS Test.  You can find more details at

http://www.telerik.com/automated-testing-tools/support/documentation/user-guide/command-line-test-execution/mstest.aspx

http://www.telerik.com/automated-testing-tools/support/documentation/user-guide/write-tests-in-code/intermediate-topics/settings-and-configuration/settings-class.aspx

I hope you find this post useful. Thanks for reading.