I need to write a simple application in C# to read values from excel, which later unearths to change the value of the page using Selenium WebDriver. How to remember which line the program stopped when an error occurred so that you can continue later from where the error occurred?
1 Answer
In your iteration you can use an integer variable and i++ it whenever it reads an item of data from Excel.
In an another approach. You can find the raw by using any internal method of library you are using. It will depend on your library.
Like in Java Workbook library we have a method like
Workbook wb=WorkbookFactory.create(fis);
wb.getSheet(sheetName).getRow(rowNum).getCell(cellNum).getStringCellValue();
7 Comments
crisx
The only thing I was concerned about was that after the error occurred. The file will be read again from the beginning. How and where to save the value of the line, which will remember when the error occurred.
Shubham Jain
I believe you have any catch block and in that block you can write a operation which will get the last line. Actually it is totally depend upon your framwork. another thing if you using testng or junit then you can write an function in listeners which will run that piece of code for you
crisx
ok, but in try catch black i can write value to file or something, but how to read this value when i start test again?
Shubham Jain
You can set the value on a sheet on excel each time once a raw is executed successfully. If the code fail the catch block will extract the same value and +1 value is the line of code where you are getting error
crisx
I dont want write to excel. One thing what i need is to save one value of variable and remember it somewhere. Because when i run test again the value will be 0. int tmp = 0; for (; tmp < 200; tmp++), how save and later read tmp value?
|