How to read/write into Excel ?

Ask general questions here.
Santhosha
Posts: 7
Joined: Mon Jun 29, 2015 8:57 am

How to read/write into Excel ?

Post by Santhosha » Mon Nov 09, 2015 11:41 am

Hi,
I need to achieve below steps using Data Driven approach:
1. Read inputs or data from Excel (can be achieved using Excel Connector approach).
2. Based on one 'Flag' column in Excel(read whether its Y/N), I proceed for executing the Testcase if Y.
3. If Testcase successfully executes, then I would like to write 'PASS' in 'Results' Column of the Excel file.
4. Report should be based on that 'Results' column of the Excel file.

How will I be able to achieve above steps please?

Thanks
Santhosha

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 7470
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: How to read/write into Excel ?

Post by odklizec » Mon Nov 09, 2015 12:30 pm

Hi,

At the moment, there is no built-in way to write data to excel files. Ranorex Excel data connectors can only read the data. Which means you will have to write your own Excel writing. At next, if I understand your description right, you want to write test result back to the initial data connector excel? This is not recommended approach, but there should be a way to do this. I would suggest you to start with these forum topics...
http://www.ranorex.com/forum/how-to-sto ... tml#p27425
http://www.ranorex.com/forum/updating-e ... t4820.html
http://www.ranorex.com/forum/is-it-able ... t3534.html
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

Santhosha
Posts: 7
Joined: Mon Jun 29, 2015 8:57 am

Re: How to read/write into Excel ?

Post by Santhosha » Tue Nov 10, 2015 5:15 pm

Hi
Thank you for your response as I would like to know whether it is possible to the way I need. Thanks for sharing related topics as well ..

Regards
Santhosha

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 7470
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: How to read/write into Excel ?

Post by odklizec » Wed Nov 11, 2015 8:36 am

Hi,

I see no reason why it should not be possible to achieve what you want. It would just require some custom code.

Step 1 could be done by creating a data connector.
For step 2, you would have to connect a column with flag to module variable and evaluate this variable via custom code. Ideally, the evaluation should be done before TestCase you want to perform. Then if the variable is "no", simply disable the test case. The code should be something like this:

Code: Select all

    if (flagFromDataCon == "No")  
    {  
        TestSuite.Current.GetTestCase("TestCase").Checked = false;  
    }
    else
    {
       TestSuite.Current.GetTestCase("TestCase").Checked = true;    
    }
As for steps 3 and 4, these would most probably need some heavy coding. And I'm afraid, I can't help you here. You see, I can't spend too much time developing something I will probably never use ;) But if you check the links from my previous post, these should give you some ideas how to update a data connector file. But I think it would be much easier (and recommended) to write new excel file with results. But even here, you will have to use some custom coding and/or 3rd party library, because there is no direct support in Ranorex to write Excel files.
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration