Page 1 of 1

How to read/write into Excel ?

Posted: Mon Nov 09, 2015 11:41 am
by Santhosha
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

Re: How to read/write into Excel ?

Posted: Mon Nov 09, 2015 12:30 pm
by odklizec
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

Re: How to read/write into Excel ?

Posted: Tue Nov 10, 2015 5:15 pm
by Santhosha
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

Re: How to read/write into Excel ?

Posted: Wed Nov 11, 2015 8:36 am
by odklizec
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.