0

In my application, there are lot of files that contain financial data and those are sent to different parties. So, I have to automate verification of content of all these files. Now, each file has a different format and structure....those are not .txt files but have custom extenstions like File1.DATA etc..

For Example, this is a file where each record length is say 80 chars, but any record can be 92 or 84 also, depends. So, i read the fileinput stream and then say in line 2, subString(5,19) is 99294329, i will store in a string and verify with pre-defined string.

Now, my automation framework is in Cucumber BDD, Java, Selenium etc..It needs lot of coding like regex validation, then comparing of each line of file, string etc.. Can there be some better approach to read each file and each line, verify contents for quick scripting.

03,Record#1,,992,4328392,234,,040243,352241483,234,2,045,943824677,,/
04,Record#2,,992,4328392,234,,040243,352241483,234,2,045,943824677,,/
16,Record#3,,992,4328392,234,,040243,352241483,234,2,045,943824677,,/
48,Record#4,,992,4328392,234,,040243,352241483,234,2,045,943824677,,/

1 Answer 1

0

For starters, Selenium doesn't have anything to do here. Selenium is a browser interaction library.

Now, what you can do here is to do Domain Modeling.

You can have objects that will validate each field. And one object that will represent the problems you have in the file.

E.g.

class Row {

   fun validate(String text) {
       val errors = Errors()
       for each row:
          if(!row.isIdValid()) errors.add(new IDInvalidError(row.number))
          if(!row.isRecordValid()) errors.add(new RecordInvalidError(row.number))
          ....
   }
}

In the end, the object errors can report what fields in what rows are not valid.

The isIdValid/isRecordValid/... functions will simply fetch the n-th field in that particular row.

If runtime performance is important, you can refactor some of these functions to optimize the file reading operations, which will be bottleneck.

Not the answer you're looking for? Browse other questions tagged or ask your own question.