- Excel (.xls, .xlsx)
- CSV - Comma-Separated Values (.csv)
- Pipe-Delimited Format ("|")
Here is an example of how easy it is to do for your tests.
Steps:
1) Download the AutomateIt! Test Automation framework from the open source directory at GIT: https://github.com/SWAutoTester/automateit
2) Open a command-line terminal prompt and go to the directory where you downloaded the code in Step 1.
3) type "ant example_read_input_data"
The tests will run and you should see this output on your screen:
example_read_input_data:
[testng] [TestNG] Running:
[testng] Ant suite
[testng]
[testng] log4j:WARN No such property [maxFileSize] in org.apache.log4j.DailyRollingFileAppender.
[testng] log4j:WARN No such property [maxBackupIndex] in org.apache.log4j.DailyRollingFileAppender.
[testng] 2017-10-08 09:11:24,895 [main] INFO org.automateit.example.test.DataTests - Excel data for data set id: data_set_id_1|Hello
[testng] 2017-10-08 09:11:24,895 [main] INFO org.automateit.example.test.DataTests - Excel data for data set id: data_set_id_2|Friday|Monday|Saturday
[testng] 2017-10-08 09:11:24,896 [main] INFO org.automateit.example.test.DataTests - CSV data for data set id: data_set_id_1|Hello There
[testng] 2017-10-08 09:11:24,896 [main] INFO org.automateit.example.test.DataTests - CSV data for data set id: data_set_id_2|Tuesday|Monday
[testng] 2017-10-08 09:11:24,896 [main] INFO org.automateit.example.test.DataTests - Pipe Delimited File data for data set id: data_set_id_1|Goodbye|Sayonara
[testng] 2017-10-08 09:11:24,896 [main] INFO org.automateit.example.test.DataTests - Pipe Delimited File data for data set id: data_set_id_2|Saturn|Earth|Venus|Mars
[testng]
[testng] ===============================================
[testng] Ant suite
[testng] Total tests run: 3, Failures: 0, Skips: 0
[testng] ===============================================
[testng]
BUILD SUCCESSFUL
So here are the contents of the files and then we show the little bit of java code that accomplished this task.
And here is the code:
Object declaration:
protected Utils utils = new Utils();
protected DataDrivenInput xlsInput = null;
protected DataDrivenInput csvInput = null;
protected DataDrivenInput pipeDelimitedFileInput = null;
public static final String DATA_SET_ID_1_NAME = "data_set_id_1";
public static final String DATA_SET_ID_2_NAME = "data_set_id_2";
Initialization:
xlsInput = setupDataDrivenInput("data/example.xlsx");
csvInput = setupDataDrivenInput("data/example.csv");
pipeDelimitedFileInput = setupDataDrivenInput("data/example.txt");
And data extraction:
csvInput.returnInputDataForDataIdAndColumnNumber(DATA_SET_ID_1_NAME, 1);
csvInput.returnInputDataForDataIdAndColumnNumber(DATA_SET_ID_1_NAME, 2);
That's it! That's all you need to know. Give it a try and let me know if you have any problems or have suggestions for improvement.
No comments:
Post a Comment