How to save data in application based on xls records ?

Ranorex Spy, Recorder, and Studio.
varun
Posts: 110
Joined: Mon Jul 23, 2012 5:52 am

How to save data in application based on xls records ?

Post by varun » Tue Oct 09, 2012 12:18 pm

Hi Support,

I am working on a solution in which a button click depends on the values present in the next row of excel sheet, suppose I need to save a group of data which is fetched from a excel file only if record in the next line does not correspond to the current dataset. Is there any way to check if the next record is related to the current record ?

Example: As per attached excel,
The column A and B are parent data cells, C to E are child data cells.
I am creating a parent record which will have child data records. Let say I create a parent record with A,B as name and description and then I add child records to this which are present in cells C2,D2,E2 in excel.
Now next line is also of the same parent record with different child, for which data is present in C3,D3,E3. Then I finally enter the third record under the same parent record. Now if it is seen the next record is not corresponding to the current one, so I will save the master record after I have entered all the three records.

Is there any way to check what is present in the next row of data in Excel before saving the parent dataset?

Thanks & Regards,
Varun.
Attachments
EG_Excel.png
ExcelSnapshot
EG_Excel.png (12.15 KiB) Viewed 1187 times

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: How to save data in application based on xls records ?

Post by Support Team » Wed Oct 10, 2012 4:55 pm

Hello Varun,

You can try the following code snippet to compare the values of the current row and the next row in your data source.
var dataConn = DataSources.Get("YourConnector"); 
int rowIndex = TestCase.Current.DataContext.CurrentRowIndex;

if(dataConn.Rows[rowIndex-1].Values[0].ToString() 
  != dataConn.Rows[rowIndex].Values[0].ToString())
{
	Report.Info("Save Record!");
}
Regards,
Bernhard
Ranorex Support Team
.
Image

varun
Posts: 110
Joined: Mon Jul 23, 2012 5:52 am

Re: How to save data in application based on xls records ?

Post by varun » Thu Oct 11, 2012 8:49 am

Hello Bernhard,

Thanks for your feedback.

We have changed our data source format after some internal discussions, PFA the latest data source format and suggest accordingly for the same problem.

Thanks for code snippet.

Regards,
Varun.
Attachments
EG_Excel2.png
EG_Excel2
EG_Excel2.png (11.56 KiB) Viewed 1172 times

varun
Posts: 110
Joined: Mon Jul 23, 2012 5:52 am

Re: How to save data in application based on xls records ?

Post by varun » Mon Oct 15, 2012 6:00 am

Hi Support,

Can I have your suggestions on this :?:
Please let me know if need more clarification.

Thanks & Regards,
Varun.

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: How to save data in application based on xls records ?

Post by Support Team » Mon Oct 15, 2012 12:54 pm

Hello Varun,

You can use a global parameter to save the current value of the row and check if the value of the next row is equal to the value of the global parameter.
if(dataConn.Rows[rowIndex-1].Values[0].ToString() != "")
{
	TestSuite.Current.Parameters["YourGlobalParameter"] = dataConn.Rows[rowIndex-].Values[0].ToString();
}

if(TestSuite.Current.Parameters["YourGlobalParameter"] != dataConn.Rows[rowIndex].Values[0].ToString() && dataConn.Rows[rowIndex].Values[0].ToString() != "")
{
	Report.Info("Save Record!");
}
Regards,
Bernhard
Ranorex Support Team
.
Image

varun
Posts: 110
Joined: Mon Jul 23, 2012 5:52 am

Re: How to save data in application based on xls records ?

Post by varun » Wed Oct 17, 2012 7:14 am

Hello Bernhard,

Thanks for your kind support.
I tried to apply the provided code snippet but its not working. Stuck against one error, seems we need to change our logic.
Please see attached "Script1017.cs" to get the logic I am working on and "Error1.png" for the error and the steps to execute this case.

Please go through the earlier replies of this posts to get your hands wet for scenario. Response awaited!!

Thanks & regards,
Varun.
Attachments
Error1017_1.png
Error1
Error1017_1.png (88.15 KiB) Viewed 1137 times
Code1017.cs
Script1017
(4.98 KiB) Downloaded 200 times

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: How to save data in application based on xls records ?

Post by Support Team » Thu Oct 18, 2012 8:25 am

Hi,
varun wrote: Please see attached "Script1017.cs" to get the logic I am working on and "Error1.png" for the error and the steps to execute this case.
as the error message says, implicit typed variables cannot be used as class members, they can only be used as local variables inside methods.

Regards,
Tobias
Ranorex Team
.
Image

varun
Posts: 110
Joined: Mon Jul 23, 2012 5:52 am

Re: How to save data in application based on xls records ?

Post by varun » Thu Oct 18, 2012 2:00 pm

Hi Support,

I have made a change (see ChangesMade_1018.png), after which stuck against bulk amount of errors(see Errors_1018.png). Try to handle these errors by every way but no results.
So please look into .cs file provided in previous post and snapshots of this post, and guide me for the exact solution on this.

Response awaited!!

Thanks & Regards,
Varun.
Attachments
Errors_1018.png
Errors
Errors_1018.png (48.75 KiB) Viewed 1121 times
ChangesMade_1018.png
ChangesMade
ChangesMade_1018.png (45.32 KiB) Viewed 1121 times

varun
Posts: 110
Joined: Mon Jul 23, 2012 5:52 am

Re: How to save data in application based on xls records ?

Post by varun » Fri Oct 19, 2012 11:40 am

Hi RX Support,

Please guide me on this in detail. Your response awaited.
Let me know if more description required on this problem.

Regards,
Varun.

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: How to save data in application based on xls records ?

Post by Support Team » Fri Oct 19, 2012 2:41 pm

Hi,

You are getting the errors because the variable names does not exist in the current context.
This is because C# is case sensitive and "rowindex" is not the same as "rowIndex", I suppose this is the reason for all your errors.

Regards,
Markus
Ranorex Support Team
.
Image

varun
Posts: 110
Joined: Mon Jul 23, 2012 5:52 am

Re: How to save data in application based on xls records ?

Post by varun » Mon Oct 22, 2012 1:47 pm

Hi Markus,

I made changes as per your suggestion, this reduce the count of errors but not fully resolve the problem.
So please tell what will the fix of other errors ?? See "Errors_1018.png" snapshot attached with previous reply for list of all errors.

Response awaited.

Thanks & Regards,
Varun.

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: How to save data in application based on xls records ?

Post by Support Team » Tue Oct 23, 2012 10:42 am

Hi Varun,

Then please post us a screenshot of the still existing errors and the code which throws it.

Regards,
Markus
Ranorex Support Team
.
Image

varun
Posts: 110
Joined: Mon Jul 23, 2012 5:52 am

Re: How to save data in application based on xls records ?

Post by varun » Tue Oct 23, 2012 1:08 pm

Hi Markus,

As required, PFA Code and Error snapshot. And kindly tell me what needs to be done to get the clean build.

Thanks & Regards,
Varun.
Attachments
Errors_1023.png
ErrorsList
Errors_1023.png (109.57 KiB) Viewed 1091 times
Code1023.cs
CodeSnippet
(5.03 KiB) Downloaded 212 times

varun
Posts: 110
Joined: Mon Jul 23, 2012 5:52 am

Re: How to save data in application based on xls records ?

Post by varun » Thu Oct 25, 2012 5:01 am

Hi Markus,

Your response awaited, please provide me with solution for the Issues attached in my last post.

Regards,
Varun.

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: How to save data in application based on xls records ?

Post by Support Team » Fri Oct 26, 2012 11:21 am

Hi Varun,

The error messages show why you are getting the errors, and the code which throws them is also marked (red underlined). The variable "dataConn" is still wrong because you named the variable "dataconn", I suppose it is the same for Variable "Add_EqGrpEq" and as the error message also stated the first argument of the IDictionary (TestSuite.Current.Parameters[]) must be a "string" and not an "int".
I hope this will help you to solve the issue!

Regards,
Markus
Ranorex Support Team
.
Image