This is a migrated thread and some comments may be shown as answers.

How do I verify a new user creation when a new ID is given to every new user?

8 Answers 84 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Bennett
Top achievements
Rank 1
Bennett asked on 17 Apr 2014, 04:57 PM
Using IE9 and Test Studio version 2013.2.1327.0...

I am trying to automate a tool my company uses to record business contacts. When a new contact is created, it is added to a table that includes all the contacts for that specific user. Each new user is given an ID number, and the link to view that person's details and edit their information includes that ID number (for example, the first contact recorded within the tool would be given an ID of "1" and the URL to view/edit their information would look something like "Contacts/Edit/1"). The table displays all of the information in the appropriate row by reading the ID of the created contact (pretty simple). I have included a screenshot so you can view the layout of the table I am describing.

When automating, since a new user with a new ID will be created every time I run the test, how do I get Test Studio to look for the contact I just created? Ideally, I want to automate (and verify) that information inputted when creating the contact is displayed properly in the Edit and View Details pages (so I would need to click on each of those links that contains the ID of the newest created contact).

For background, I have minimal developer experience. I think this may be solved with a coded step, but I have had very little experience writing code.

8 Answers, 1 is accepted

Sort by
0
Daniel Djambov
Telerik team
answered on 18 Apr 2014, 11:49 AM
Hi Bennett,

Unfortunately best way to perform the case you describe is using code (coded steps).

Approach1: no code
There is a way to do this without code, but it has limitations - you will have to ensure a clean state before each test. What I mean by clean state is to ensure when you open the page you have exact number of rows in it or zero rows. This way when creating new items, which will create new rows, performing actions on the new created items will be recorded to their position and will work. You can achieve this clean state depending on the specifics of your application: either resetting the database, or performing a test that goes and deletes all existing items before your main test or deleting items manually.

Approach 2: with code
In order to do this in code, it will be specific to the technology your application is built with, but basically what should be done is the following:
1. when loading the page find all rows in the table and get their count with [table].Count();
2. then when creating your new record (row with data) start working with newly created row
3. or if during creation of the table record the some unique identifier is present, in code get the value of this identifier and assign it to a variable, then find the text from this variable in the new created record and based on it find Edit/View Details links for this row
it will look something like this:

var uniquetext = [parent element].Find.ByTextContent("[unique text]");
var parent = uniquetext.Parent<[type of parent that returns the row containing all controls in it]>();
var editliknk=parent.Find.ByTextContent("Edit");
editlink.User.Click();

this will find your new record textblock, find its parent row containing all controls in it and within the proper row will look for and element that has textcontent 'Edit' and click on it.

This is very general example and code can be written in many different ways, but describes the idea how it will look like and ensure proper link clicked on the new created data record/row.

Regards,
Daniel Djambov
Telerik
 
The New Release of Telerik Test Studio Is Here! Download, install,
and send us your feedback!
0
Shashi
Top achievements
Rank 1
answered on 18 Apr 2014, 12:47 PM
Bennett,

To add to what Daniel said ...

Does your app require unique names for every user?  If not, can the app be modified to display a unique identifier as a column in the table?  If the unique identifier is displayed as a column in the grid, Approach 2 could also be implemented as recorded steps. 

NOTE:  If you are using Silverlight grid controls to implement the table, you may have issues with Approach 2 in certain scenarios - regardless of whether you use recorded or coded steps.  The issues are due to limitations of the Silverlight grid control.  There are workarounds - but they are not easy or perfect.  I do not know if these limitations exist with WPF or HTML grids. 

I am sure Daniel can help you with any of the above if you need it. 

Shashi
0
Bennett
Top achievements
Rank 1
answered on 22 Apr 2014, 05:38 PM
Hi Daniel,

Thanks for the information. I figured I would need to do this in code. (The sample code is much appreciated!)

Is there a way to use the ID as the unique identifier? More specifically, is there a way to search for the highest ID value and then have the following test steps use that found value?

Thanks,
Bennett

P.S. Thanks for the extra info, Shashi! Unique names are not required, and modifying the app isn't a possibility at this time.
0
Cody
Telerik team
answered on 25 Apr 2014, 10:22 PM
Hello Bennett,

Is there a way to use the ID as the unique identifier?

Keep in mind that hooks into the browsers DOM. It can only see and use what's present in that DOM, which generally is what is displayed in the browsers window, a bunch of text strings and images. Where would Test Studio fetch this ID? In what way would you want Test Studio to use it as a unique identifier i.e. what exactly is Test Studio supposed to do with it?

...is there a way to search for the highest ID value...

How much code are you willing to write to accomplish this search? The problem is that all "ID's" are just text strings to Test Studio. To find the "highest ID value" will require a code loop that iterates through all string's converting to an integer, and doing a comparison and then keeping and using the highest one at the end. This is doable but will require about 10 lines of code and a "for each" loop. If you're willing to attempt to write the code, we'll do our best to guide you... but we can't take the time to write it for you.

..and then have the following test steps use that found value?

Depends, use it in what way? As far as Test Studio is concerned this ID is just a test string like "New Mexico". What exactly do you want the following test steps to do with this string?

Regards,
Cody
Telerik
 
The New Release of Telerik Test Studio Is Here! Download, install,
and send us your feedback!
0
Bennett
Top achievements
Rank 1
answered on 28 Apr 2014, 12:50 PM
Hi Cody,

My issue is that the database creates the ID after submitting a contact and there is no way to know the ID beforehand. It could be possible for Test Studio to fetch this ID directly from the SQL database (I saw in the user guide that this may be an option). I would need this ID in further test steps because any URL associated with this newly created contact contains the ID number (so recording doesn't work because it records me clicking a URL with a previously created contact's ID). Does this answer your questions? If not, let me know and I will explain further where I can.

In your opinion, would it be easier to write the ten lines of code with a "for each" loop or try to grab the information directly from the SQL database? Unfortunately, I have only been using Test Studio for a few weeks, so I am still trying to familiarize myself with the intricacies of the software. Any direction would be helpful!

Thanks,
Bennett
0
Cody
Telerik team
answered on 28 Apr 2014, 09:50 PM
Hi Bennett,

...the database creates the ID after submitting a contact and there is no way to know the ID beforehand.

When an application creates a new record of that type (a work order, a sales order, etc.) the application will return something like "order 829621 created". Does your application do something like this? If so it will be easy for Test Studio to locate and extract that number and save it for later use.

Or if it adds a new record to a table along with the new ID and it's always the top row or the last row, again it will be easy for Test Studio to locate the ID and extract it. We just need some predictable location in the UI where this new ID will appear so we can go and grab it.

Look for something like this in your application then share with me a screen shot what it looks like. We'll go to the next step after that.

In the screen shot posted with your initial inquiry, I don't see an ID displayed. Do you have to click View Details to see the ID? We can write a script to do that. What's important is that the location the new ID shows up at will always be the same.

Regards,
Cody
Telerik
 
The New Release of Telerik Test Studio Is Here! Download, install,
and send us your feedback!
0
Bennett
Top achievements
Rank 1
answered on 02 May 2014, 11:57 AM
Hi Cody,

So this may go a little off course from where we were initially going... I was able to write the below script to identify the ID value from our SQL database. However, I need to extract the ID value and save it to use it in later test steps (for example, if the ID value that this script identifies is 1, I need to be able to find the "View Details" link that contains the ID value 1). All the help that I have come across for extracting values involved the Recorder and not coded steps. Is what I am asking for possible?

Thanks,
Bennett

int ForeignContactID1;
 
//Connecting to SQL database
 
SqlConnection thisConnection = new SqlConnection("Data Source=ServerName;Initial Catalog=Security;Integrated Security=true;MultipleActiveResultSets=true;");
 
thisConnection.Open();
 
//Write name of database to the log
Log.WriteLine(thisConnection.Database);
 
//Create SQL command
SqlCommand thisCommand =
thisConnection.CreateCommand();
 
//SQL command to pull highest ID value from database
thisCommand.CommandText = "SELECT max(ForeignContactId) as ForeignContactID1 FROM [Security].dbo.[ForeignContacts]";
SqlDataReader thisReader = thisCommand.ExecuteReader();
while (thisReader.Read())
{
    ForeignContactID1 = (int) thisReader["ForeignContactID1"];
    Log.WriteLine("Value of Foreign Contact ID " + ForeignContactID1);
}
thisReader.Close();
thisConnection.Close();
0
Cody
Telerik team
answered on 05 May 2014, 08:40 PM
Hello Bennett,

Yes it is possible. There are a couple of approaches you could take. The approach I recommend is to set an extracted variable in code. Use this API call to save your ForeignContactID1 variable into an extracted variable. Then you can later use it in a Data Driven Find Expression.

Regards,
Cody
Telerik
 
The New Release of Telerik Test Studio Is Here! Download, install,
and send us your feedback!
Tags
General Discussions
Asked by
Bennett
Top achievements
Rank 1
Answers by
Daniel Djambov
Telerik team
Shashi
Top achievements
Rank 1
Bennett
Top achievements
Rank 1
Cody
Telerik team
Share this question
or