Testing SOAP APIs with Telerik Test Studio

The legacy SOAP based web services/ APIs are still in use at a lot of organisations. While Telerik Test Studio has direct support for REST based APIs, testing SOAP web services requires a few additional steps.

In the short video below, we share how we can test SOAP based APIs in Test Studio:

The three things needed include:

  1. A Test Oracle to encapsulate web services call: Built easily with Visual Studio
  2. Coded Steps in Test Studio
  3. Data Driven tests for testing various inputs

The transcript of the video is as follows:

Can Test studio test APIs? And i think most of you know the answer that it does support testing REST APIs. Recently one of the customers asked me if Telerik Test Studio can be used for automation of SOAP-based web services and the answer to that is it can be done in telerik test studio using coded tests.

In this video we will see how we can test SOAP based web services using Test Studio. The soap web service that i am using for testing is a publicly available service that converts digits to numbers. So in this web service i’m going to use the number and what it allows me to do is enter a number so let’s enter 789 and by invoking this i get the the words or the digits converted into words as seven eighty nine. So this is the web service that i’m going to test back in the test studio.

I have authored a test that will feed in various digits and verify if the web service returns the correct words for those digits. For the same i have put in some local data with digits in one column and in words in the second column. So this is going to be a data driven test. Let’s test this with our script. I’m just starting the test with the headless chrome as execution engine because web services don’t have a UI. The test has started and you can see that i’ve got the debugger going and already the test has finished.

Now there were four iterations of this test, this being a data driven test and if you want to see the logs for each of the iterations that’s visible here as well. In iteration number one you will notice the overall result is pass. In fact here it shows we’re using chrome headless version and our test was successful in iteration number two where we had put in two three eight nine the result is fail and the failure information is also mentioned here. Well we were expecting the web service to return two hundred and eighty nine but the web service actually returned two thousand three hundred and eight nine not eighty nine. So this actually indicates a failure on the assertion. Well the test continued because we have marked this step as continue on failure. Iteration number three has result as pass wherein we passed in a single digit 4 and we also got back the same value which is four. Iteration or the last iteration here is checking for digits 10 and inwords it should also be ten and once again the overall result is pass. So here you can see its result is pass but your overall result is a fail because one of the iterations here did actually fail.

So in the next few minutes we will see how we had created this SOAP test in telerik test studio. So to work the magic of a soap api test and it’s actually quite painless in telerik test studio. You need three things:

1. the first is a test oracle number

2. two is the coded step in test studio and

3. number three is data driving the verification

Okay let’s start with the test oracle. The test oracle is an external assembly that you are going to use within test studio inside your script but this assembly is going to be created by someone else. So what i had gotten done was to call the SOAP API using a visual studio function of adding web service reference and created that project as an assembly. Now the next step would be to add that assembly in test studio so if you go to your project and go to settings you will have a section that says script. Now within this section you will notice some assemblies that are automatically referenced here. Now if you notice this reference, this is something that has been added as a custom reference and this is where my test oracle has been created. So this assembly uses a simple function to invoke the SOAP API and provides a simple programmatic interface to invoke this soap service. So if you want to add more test oracles or external assemblies you can click on add reference and that’s what allows you to refer any .NET based assembly. So that takes care of the first step which is of getting a test article in place.

The second step is to add a coded step in my test script so you can add a coded step in test studio by using the step builder. Here where i’ve selected the common and within it there is a coded step and i can click on add step button. And this will add a coded step so that’s already done here. As you can see the coded step i am using is titled sample soap underscore coded step. In fact the code for this is available in the cs file located here. I just opened up the cs file the first thing that i need to do is to add a reference or to soap call namespace now in my function which is called as sample code underscore coded step. I am creating an instance of the object and within this i am passing in the specific digits. And finally i’m asserting if the digit that i have passed is the same as the one it should be in words.

Now the syntax here is slightly different. The syntax looks different because we are actually doing the third step in this demo which is data driving the verification. To data drive the verification as well as input values you’ve got to use the data and the specific column that you have created. So that’s what i’m using, so data and digits. And since the function towords requires me to give in an integer value i’m passing that in to the towords function of the test oracle. So conversion service and the function towords are actually coming from the test oracle. Finally i’m adding an assertion to see if the value that has been returned which is the nword value here and then the value that is there in my data driven column which is called inwords is also mentioned here. So both of them need to match up for this test to succeed. To quickly check where we had put in this data driven values we can go back to the test script and down below next to the test steps you will find the local data tab. And that’s where we can manually add these values.

This demonstration has showed you that Test Studio can be easily used to data drive SOAP based APIs automation

Enjoy watching the video and share your questions in the comments section below.

Webinar July-September’16

auto

Why Automation? Really you are still wondering on this…. Yes this saves a lot of time…

With this we also have these new webinars for you. Come and join us in these interesting session and have an experience of our latest updates

Date Time (IST) Session Title and Registration
Thursday, July 21 ’16 12:00 – 1:00 PM Build Rapid MVC Based Web Applications using Sitefinity Digital Platform
Thursday, July 28 ’16 12:00 – 1:00 PM Even Quicker Development with Xamarin Forms using Telerik UI for Xamarin
 Thursday, Aug 25’16   12:00 – 1:00 PM Building Bots that work across social apps with Microsoft Bot Framework      
Thursday, Sept 1 ’16 (updated) 12:00 – 1:00 PM Building Versatile Reporting Dashboards with Telerik Reporting Server
 Thursday, Sep 22’16    12:00-1:00PM Now Build Web Apps and API with Node.js
 Thursday, Sep 29’16 (updated)    12:00-1:00 PM API Testing with Telerik Test Studio

The audio will be streamed via GoToMeeting. Use of a headset is recommended

Resources for “3 Things You Didn’t Know Telerik Test Studio Can Do”

tst-cloud

Some interesting questions from the webinar:

Q: is there any keywords for handling captcha in Telerik test studio framework?

A: There are no specific constructs for handling captcha in Test Studio. You can author custom script in Test Studio to test for captcha.

Q: can we perform testing the application built on Iframes using test studio..?

A: Test Studio has extensive frames support including iFrames. More details can be found here: http://docs.telerik.com/teststudio/testing-framework/write-tests-in-code/advanced-topics-wtc/frames-support

Q: How does Telerik handles dynamically rendered application products like Pega?

A: Telerik has constructs like SimulateRealClick/ SimulateRealTyping that allow automation execution against the UI (as compared to DOM). Coupled that with Wait construct, one is able to achieve a lot of automation for dynamically rendered applications.

Q: How to search in every row of radgrid?

A: One strategy for finding rows using InnerText property was showcased during the webinar. Another one could be to retrieve the entire Table and iterate over each row in a scripted step.

Q: Hi, let me know whether we can have these automation scripts available into TFS and get executed ?

A: You can store the scripts in any repository. Test Studio has more integration points with TFS. An upcoming webinar covers more on this: http://www.telerik.com/webinars/teststudio/building-an-automation-framework-that-scales

The Slides for the session are as follows:

Video for the webinar is avaialble below:

Comparison of Automated Testing Tools: Throwing in Telerik Test Studio

ComparisonI was reading this excellent article by Gouri Sohoni comparing various automated testing tools. The article is an excellent introduction to automation in testing and the various tools available to do the same. She compares the following tools: Selenium, QTP (Quality Test Professional) and Coded UI Test (CUIT) with Visual Studio 2012. I am taking this opportunity to extend the article and include Telerik Test Studio in the mix.

The following is written in the same format followed by the linked article:

Ease of Use

– Recording and Playback Functionality

Test Studio supports recording on various browsers i.e. IR, Chrome & Firefox. All the scripts can be played back on different browsers too.

– IDE and tools with which the tester can write the scripts

Test Studio comes with its own IDE and also integrates with Visual Studio. You can use Test Studio as a standalone IDE for recording and writing scripts or from within Visual Studio.

– Ease of Test Case execution

Test Studio test cases can be run from within Test Studio or using the Test Studio scheduler. The scheduler can be used to run all test suites or selected test cases at pre-defined schedule. Integration with CI tools is also supported via a command line test runner.

Platform Support

-Language Support

Test Studio doesn’t require you to write code in a lot of scenarios. However, if you do need to it supports C# and VB.NET.

– Support for various application types

Test Studio comes with testing for web applications, Silverlight applications, web services, mobile devices and WPF applications.

– Support for various browsers

Test Studio supports recording and playback in almost all browsers – IE, Chrome, Firefox and Safari.

– Support for Data Driven Testing

Test Studio supports Excel, XML, CSV and Databases (MS SQL Server, Oracle, MySQL and any QLEDB or ODBC supported DB) for data driven testing.

– Exception Handling

You can configure Test Studio to ignore all errors that happen during a test execution. If unexpected situations are expected to occur in a test suite you can convert them to Coded Steps and then use try and catch blocks for exception handling.

– Validations or Assertions

Test Studio supports Verify and Wait without need for writing any code. Any assert can also be included as needed using coded steps.

– Support for Objects

Test Studio has a unique Object Finder UI called DOM explorer that helps you locate elements on the application being tested easily. You can also customize the names and the locator logic that is used to identify the object.

Integration with Application Lifecycle Management and going beyond

– ALM Integration

Test Studio integrates with Telerik TeamPulse, HPs Quality Center and Microsoft TFS. Integration with TeamPulse allows for bug submission and linking test cases to its automation script. All the features of TFS are also available if you utilize the TFS as the ALM tool.

Additionally, submission of bugs is also supported for JIRA.

– Going beyond

Test Studio can easily automate JavaScript based applications. Special constructs like “Simulate RealTimeClick” and “Simulate RealTimeTyping” makes this possible. Test Studio provides you the capability to convert your functional tests to load tests. It also has the capability to take the workload from Fiddler traces and run it in Test Studio for performance test.

The RoI for the tool is enhanced as it is also available in the pay per use model. The minimum time that you need to buy Test Studio for is 1 month.

 

Summarizing the Comparison

Category Selenium QTP Coded UI Test Studio
Record & Playback Completely Supported Completely Supported Completely Supported Completely Supported
Ease of IDE & Features with tool Not Par Not Par Completely Supported Completely Supported
Ease of Execution Completely Supported Completely Supported Completely Supported Completely Supported
Languages Support C#, Java, Perl, PHP, Python or Ruby VB Script C# & VB.NET C# & VB.NET
Support for Objects Not Supported Not Supported Completely Supported Completely Supported
Browser Support Allmost All IE & Firefox Some IE Versions Allmost all
Support to various applications Only Web Almost All Almost All Almost all
Integration with ALM Partially Supported Partially Supported Completely Supported Partially Supported

How to Verify Dynamic Links pointing to Live URLs in an Application – MSN

Recently I was browsing MSN India when I encountered a dead link by clicking on a story. How embarrassing!

That set me thinking that there should be a way to automate checking the URLs that are displayed on this content aggregation portal. I think the same is true for all portals that rely on external content for their functionality.

Below, I propose a mechanism to automate testing of such requirement. Some peculiarities of this web portal:

  1. The news article displayed is changed frequently (maybe every few hours)
  2. Alongwith the news article text, the URL of the article will change
  3. We need to verify that the URL is a live URL

We will be using Telerik Test Studio v 2014.1 to do this test. We can start by creating a new project in Telerik Test Studio:

Click on OK.

Right Click on the project name and create a new test of type Web Test. Call this Sports_Section_MainStory_Verification Test.

Double Click on this test to start recording this test. You should be in the “Test” section of the Ribbon. Click on Record button located at the top.

 

Select the browser you want to record the test in (I am using Internet Explorer):

This will launch a new IE window with automation enabled (notice the small toolbar on the top of the screen). Now type in the MSN URL: http://www.msn.com and press enter.

Click on “Enable/Disable Hover Highlighting” icon on the Test Studio toolbar. Hover over the Sport Section Main Story Headline (shown in the screenshot below):

Clicking on the blue bubble exposes the “Element Menu” from where you should select “Add to Project Elements”:

Name the element appropriately and click on Add Element:

Now close the browser. We will be working with this element in coded steps. The first step is to correct the identification logic of this element. Go back to Test Studio and highlight the element in the “Element Explorer” of Test Studio:

Right Click and select “Edit Element”. Click on “Find in Live Version” -> New Browser -> Browse and Navigate”:

This will open a new automated window in a browser. We are interested in the “Find Element” window:

Notice the suggestions pane in the left of the screen. We are going to be using HtmlPath this time. Click on HTMLPath to add it to the right section of the screen. By clicking on the one logic present in the right section, you will be able to delete the same. The screen should now look like:

Click on Save to return to the Test Studio. Now add a coded step in Test Studio using the Add menu -> Script Step:

We are going to use C# to author our scripts. Please select C# in the next window. In the bottom pane of Test Studio, you will be able to write your script. A single line of code will do:

SetExtractedValue(“MainSportsLink”, Pages.MSNIndiaNewsCricket.Sports_Section_Main_Headline.HRef);

 

 

Next we will need to add Reference to System.Net namespace. To do that go to Project menu ribbon and click on settings:

Click on Add Reference and select the System.Net.dll located here: C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\v3.5

Then Click on Open, followed by OK in the Project Settings Window. Next, click on the below shown icon to view the entire code behind file in the “Code Viewer” section.

Scroll to the top of the code file, and add:

using System.Net;

Next add a new coded step and copy the following code there:

string urlloc = (string)GetExtractedValue(“MainSportsLink”);

System.Net.HttpWebRequest browurl = (System.Net.HttpWebRequest) WebRequest.Create(urlloc);

using (WebResponse response = browurl.GetResponse())

{

Assert.AreEqual<string>(“OK”, ((HttpWebResponse)response).StatusDescription);

}

Save the test and Run the test by using the Start button. The test would pass!

Congratulations, you have now automated verification of dynamic content with its associated URL using Test Studio. One can similarly author different tests for each section of the webpage and accordingly verify of the links are active.

If you want to take the next step, think about data driving the find expression of each of the elements. Interesting??

Telerik Test Professionals Conference 2014

 mastheadTelerik India hosted the second Telerik Test Professionals Conference(TTPC)  for QA professionals in Chennai on 4th March 2014. A quick report on the TTPC 2013 edition can be found here. A pre-conference was also organised in Bangalore on Feb 28th. The event was aimed at sharing the best practices in automation testing with the test professionals. The attendees learnt to solve common automation testing problems during the event.

Telerik understands the value of class room teaching and in person conversation with experts to solve real life test automation problems. The presenters included Jim Holmes and Dhananjay Kumar. Jim Holmes is well known expert on Test Automation and he travelled from USA to India to conduct these workshops. Dhananjay Kumar is Developer Advocate with Telerik India.

The theme of the event was “Testing for New Age Applications”. True to the theme, strategies to enable testing for AJAX, web services and mobile applications were discussed in detail during the event.

The event saw a tremendous response from testers in Chennai with over 80 attendees from various organizations like HCL, CTS, Hexaware etc. This event covered complex testing automation problems and was conducted in the format of open discussions. Attendees discussed various automation testing issue from their projects and the presenters did a great job answering them by demonstrations.


On 28th February we conducted the pre-conference workshop in Bangalore for six hours. Workshop was hosted in Manipal centre at MG road. There were 20 seats for the workshop and it was occupied by representative from well-known organizations like ITC InfoTech, Philips, PWG etc.

Bangalore workshop was aimed at manual testers and a step by step approach was followed to bring them upto speed on automated testing. The attendees appreciated the workshop and left the day equipped with the knowledge to confidently take up automated testing.

Some topics covered during the conference included:

  • Where UI Automation fits in
  • UI Automation basics
  • Getting Started With Telerik Test Studio
  • Creating hierarchy of tests
  • Test Design
  • Working with tables
  • Working with AJAX
  • Tests and Code
  • Data driving tests
  • Load & Performance Testing
  • Performance overview
  • Load Testing
  • Mobile Testing

In both events attendees learnt to solve common automation testing problems (some of them listed above) by working on the problems in the lab.

Some feedback about the event:

Telerik Session went very well. I have learned and Knew about test suite modules.” – T Satish KumarRoy, Steria

Good followup and event went on as per the agenda mentioned. ” – Ganesh Jayaraman, DuPont

the event was well organized and informative” – Vardhini, SelfServIT

Both workshops were well received by audience and there were many practical problems discussed and solved collaboratively. Curious attendees continued to engage with the presenters even after the day was over. All attendees were presented with a certificate of participation at the conclusion of the event.

We loved the experience of being able to converse with the quality professionals in person and hope to continue meeting them in various conferences and community events.

Dynamic Values passing between test steps in Test Studio

Recently I was talking to a customer. He discussed a simple but important problem with me on test automation using Test Studio. He had a requirement to use values of variables from one test step in another test step.

To understand this problem in better way, consider below web application which is inserting data in database.

clip_image001

Let us try to understand this problem bit further. Suppose you have 6 test steps in test. In step2 user is typing UserName to be inserted.

clip_image003

To verify successful insertion of UserName in database, you need to do follow steps,

  • Read UserName inserted by user from step 2
  • Reading of username is done in step 4. So here you are reading value from step 2 in step4.
  • Use read value of step 4 to verify insertion in database.

In this post we are going to see how we can read variables value from one step in another step. In this case from step 2 to step 4 and then in step 6.

To use variable from one step in another you need Coded step. To add coded step select Test from menu and then Script Step from ribbon. In Visual Studio extension Coded Step can be added by clicking Add then selecting Coded Step.

clip_image001[6]

If you notice test steps in we have taken in example there are two test steps (step 4 and step 6) are coded steps. In step 4 we are reading user inserted value as below and assigning that to a public global variable.

clip_image003[6]

In step 4 (coded step) we read value from step 2 or in other words value from DOM element in which value got assigned in step 2. Now we need to read global variable value in step 6.

clip_image005

In this way very easily you can read variable values from one step in another step in a test project. I hope this post will help you. Thanks for reading.

How to Automate Test for Image verification using Test Studio

Learn more about Test Studio here

Telerik Test Studio got out of box feature to automate test for image verification. You can verify, whether image has been changed or distorted in application without writing any script. In this post we will take a look on, “How can image verification test can be automated in Test Studio

Let us consider that there is web application with an image as below,

clip_image001

To do verification around this image, start recording the test. Once application is launched for recording, select Enable or Disable over hover option from Test Studio control panel docked in recording browser window,

clip_image002

This will allow you to select image on DOM. Put mouse for some time and you will get a blue bubble.

clip_image004

On clicking of blue bubble you will get option to Image Verification.

clip_image005

Next you need to click on Image Verification. On clicking you will get Image Verification dialog box.

clip_image007

In dialog box you can configure various options like,

  • Verify entire image
  • Verify certain area of image

To do exact match you need to put Total Difference as 0. Recommended is to put in between 1 to 5 %. If you want to verify certain area of image then uncheck Verify Entire Image checkbox and configure X axis, Y axis, Width and Height value.

I have recorded a very simple test for image verification with two steps as below. You can see that error tolerance has been set to 2%.

clip_image002

Assume if test fails in image verification step then you will get information as below that Images are not the same.

clip_image004[6]

We just learnt that Test Studio allows us to perform automation of image verification without writing any script. I hope you find this post useful. Thanks for reading.

clip_image006

Error Solved: Binding Excel file as Data Source in Test Studio

Download free 30 days trial of TestStudio from here

Find more about Test Studio here

Okay, so have you come across this error while binding an Excel File as DataSource to a Test in Test Studio? You may get this error when you are working with fie saved in Excel 2013 format.

image

Now how to solve this error? Very easily you can solve this error by saving Excel file in Excel97-2003 Workbook format.

clip_image002

If you do not want and can save your file in Excel97-2003 format then probably you may want to check application log. To check application log follow these two steps,

  1. Navigate to Help Menu
  2. Click on Enable log to enable log in Test Studio.

image

In Log if you see something like Microsoft.ACE.OLEDB.12.0 is not registered on local machine then, you need to install Access Database Engine. You can download and install it from below link,

http://www.microsoft.com/en-us/download/details.aspx?id=23734

After installing it you should able to work with Excel file regardless of it format is Data Source in Test Studio.

I hope this post useful. Thanks for reading.

Download free 30 days trial of TestStudio from here

Find more about Test Studio here

Recap of webinar Journey from Manual to Automated Tester

image

On 12th December 2013, we conducted webinar on Journey from Manual to Automated Tester in 1 Hrs. We had great time teaching Automated Testing over web to audience of more than 150.

Download free 30 days trial of TestStudio from here

Find more about Test Studio here

In webinar we covered following topics,

  • Why to automate a Test
  • Advantage of Test Automation
  • Getting started with Test Studio
  • Record and Play a Test
  • Cross Browser Testing
  • Data Driven Testing
  • Test Lists and Scheduling

If you missed webinar then you can view recorded webinar below,

 

Some of the Questions and Answers from webinar are below,

Which all technologies that can be automated by Test Studio?

TestStudio can automate functional Testing of

  • Web Applications
  • Desktop Apps created using WPF
  • Load Testing
  • Load Testing of Web Services
  • Load Testing of Mobile Apps

Can we perform Load testing for more than 100 virtual users?

Yes Load Testing can be performed with more than 100 Virtual Users. Learn more about Load Testing here,

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

Can we do automation testing for excel application?

What I understand from this question that you want to automate testing of

  • Reading Excel file
  • Verifying whether data being written to Excel file.

Yes you can do it using CODED STEPS. You need to write C# Code using File System API and Excel API to achieve automation .Learn more about Coded Steps here

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

What programming languages does it support?

Test Studio supports below programming languages,

  • C#
  • VB.Net

Can test studio access Linux System?

No Test Studio does not work on Linux system. As of now Test Studio supports only Windows.

Can you please show how we parameterise the user name and password?

As shown in demo you can do it using Data Driven Testing. Learn more about Data Driven Testing here,

http://www.telerik.com/automated-testing-tools/support/documentation/user-guide/data-driven-testing.aspx

When you choose any Browser for test recording

Learn more about recording here,

http://www.telerik.com/automated-testing-tools/support/documentation/user-guide/recording-tests.aspx

How this tool is handled browser pop-up?

Learn more about handling popup here,

http://www.telerik.com/automated-testing-tools/support/documentation/user-guide/dialogs-and-popups/dialogs.aspx

Is there any option for automating silver light application?

Yes Test Studio supports automation testing of Silverlight application. Learn more about that here,

http://www.telerik.com/automated-testing-tools/support/documentation/user-guide/write-tests-in-code/silverlight-test-automation/introduction.aspx

Does it support flex?

Unfortunately Test Studio does not support Flex application testing.

Can we do testing for Kendo UI applications?

Test Studio supports out of box testing of Kendo UI Widgets. See Kendo UI Grid testing video here,

http://tv.telerik.com/watch/automated-testing-tools/testing-kendoui-grid-with-test-studio

Webinar was highly demo oriented and PPT had very less role to play. However if PPT interests you then find it below,

Download free 30 days trial of TestStudio from here

Find more about Test Studio here

clip_image002

Telerik TestStudio: Subscription based Automation Testing Tool

image

Telerik TestStudio is now subscription based. Now as user you have three options to choose from.

Learn more about Purchasing Options

image

You have now monthly and yearly subscription option. You can choose among three bundles as per your requirement.

There are many added and imprived features with this release. Some of them are as follows,

  • Load Testing Traffic from Mobile Devices
  • Load Testing of Web Services
  • Extended Support for HTML5 Controls
  • Improved Browser Calibration
  • TeamPulse Integration Improvement. Etc.

Learn what is new in TestStudio

I hope you will find new subscription based model along with new features exiting. Test Studio rocks.

How to change default waiting time to find Element for a step in Test Studio

Learn more about Test Studio here

While talking to customers I come across one common question that, “How can we change default waiting time to find element for a particular Test Step? “

Let me start with explaining this question little bit more. So when you record a test, TestStudio saves information about elements in Element Repository. While executing test, TestStudio try to identify element in Element Repository on basis of Identification Logic saved. TestStudio waits for 30ms to find element.

Now there could be scenario when 30ms is not enough and you want to change this default wait on step value. Let us learn how can we change this?

To change default wait to find element in a step, click on edit steps. You will get an option of UseStepWaitOnElements. You need to check the check box as given below.

image

Once you check this check box, next go to step property. There you will find WaitOnElement property field editable. Here you need to put desired wait time to find an element for a particular step.

clip_image001

This is what all you need to do to change default wait time for elements. I hope you find this post useful. Thanks for reading.

Handle Dynamic Id with ease in Test Studio

Learn more about Test Studio here

Download 30 days Free Trial Here

Okay, so I will start this post saying there is not a single golden rule to handle dynamic id while automating Test. It depends, I repeat it depends. In this post I will focus on various ways you can handle dynamic id in Test Studio.

clip_image002

In this post we will learn to deal with dynamic id in three different ways,

  1. Handling with changing setting at Test Project level
  2. Handling with changing setting at Element level
  3. Handling with Coded Step

Scenario # 1 : Test Project Level

Let us say you are sure that id is going to be dynamic throughout the application. And you cannot rely on id to identify element. In this scenario Test Studio allows you to configure Identification Logic at the Test Project level. You can change that in Project Settings.

By default Test Studio finds and element on following identification logic. It search on the id AND tagname. This is set for the Test Project level.

clip_image002

Now we know that id for application in test is going to be dynamic and we want to change the FindLogic to some other tag. In other words we want to change default Find Logic for whole Test Project. To do this navigate to Project Settings.

You can browse to FindLogic setting of Test project by clicking on

Project -> Show Setting

clip_image004

In Project Setting dialog box click on identification logic. Here you can find identification logic and change it as per requirement to your project.

clip_image006

As you can clearly see that by default Test Studio find an element on its Id. If you consider that Name of the elements are not expected to change frequently then you can consider to change project setting to find an element on its Name attribute.

To change FindLogic select any attribute then click on up/down arrow to change its position. For example Name is at second from top. To make it first attribute on which Test Studio will find element select Name and then click on up arrow button to bring it at the top in the list.

clip_image008

In this way you can configure FindLogic. You may notice that if required you can add new Tag to list as well. After reconfiguring Identification Logic you can find that now FindLogic for whole Test project (recording which will happen after changing logic) has been set to name and tagname.

clip_image010

Scenario # 2 : Element Level

Second scenario could be you need to change identification logic only for a particular element. You do not want to change identification logic for whole Test project rather for a particular element. Test Studio allows you to do that as well. To do this select element from Element Repository and right click. From context menu select Edit Element.

clip_image001

When click on Edit Element, next you will get various options to Find Element.

clip_image003

Let us Find Element in Live Version. To find element in Live Version make sure that application is already open in browser. Since already application is opened here so select open Current Page and select application from drop down.

clip_image005

After navigating to application you will find Elements current FindLogic.

clip_image007

To delete current logic move mouse and you get option like below to delete current filter.

clip_image009

After deleting both filter let us use XPath to find element.

clip_image011

This is what all you need to change FindLogic for a particular element. You can see in Element Repository that FindLogic has been changed to XPath.

clip_image013

Scenario # 3 : Code Step

So far in above two scenario we saw that if Id is dynamic we can change it to some other attribute of element like Name, XPath etc. Now there could be scenario that you cannot rely on any attributes.

XPath gives you positional based FindLogic. Consider scenario of a Grid. In Grid you need to automate test to find an Employee ‘e2’. Say e2 is second employee in database and is listed in the second rows of Grid. You can put verification step as below,

clip_image001[6]

Now above test will fail if order of elements in Grid is changed. So in this kind of scenario you cannot rely on either id or XPath of element.

There could be many ways you can fix and automate test to find whether employee e2 exists in db or not. Test Studio allows you to write your custom logic using Coded Step. So we can write a coded step as below.

clip_image002[6]

In above coded step, we are finding reference of Grid then searching Employee ‘e2’ in whole grid and then asserting if count is equal to 1 to verify existence of Employee e2.

So in this scenario we are not finding element on any of the attribute and writing our own logic in script to find element.

Conclusion

We learnt in this post that there are various ways to deal with dynamic id. Again there is not a single bullet proof method to deal with dynamic id. It depends on the scenario that how dynamic id cane be handled while automating test.

Learn more about Test Studio here

Download 30 days Free Trial Here