How to Retrieve data from CSV File
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
How to Retrieve data from CSV File
Hi Team,
Im using CSV File to read data and pass value to Script.
CSV File as :
UserName | Password |
devarajulu.m | 123456 |
manoj.s | Password1 |
I need to pass value Username password for first iteration of data and second so on.,
how to retrieve cell value in CSV. can you provide example script.
function main()
{
var browser,page,form,Driver;
Browsers.Item(btFirefox, "", Browsers.pX64).Run("AppURL");
browser = Aliases.browser;
Driver=DDT.CSVDriver("C:/Users/Manoj.S/Desktop/Test complete forum doubts/RVData.csv");
while(!Driver.EOF())
{
page=browser.pageWelcomeToReferralvalet8;
loginClick(page,browser);
page = browser.pageWelcomeToReferralvalet7;
adminLogin(page,form,browser,Driver);
Driver.Next();
}
}
function adminLogin(page,form,browser,Driver)
{
var textbox;
var table;
var panel;
page.Wait();
form = page.formAspnetform;
textbox = form.textboxTxtusername;
textbox.Click(78, 12);
textbox.SetText(Driver.Value(1));
}
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Instead of what you have, do this:
function main() { var browser,page,form,Driver; Browsers.Item(btFirefox, "", Browsers.pX64).Run("AppURL"); browser = Aliases.browser; Driver=DDT.CSVDriver("C:/Users/Manoj.S/Desktop/Test complete forum doubts/RVData.csv"); while(!Driver.EOF()) { page=browser.pageWelcomeToReferralvalet8; loginClick(page,browser); page = browser.pageWelcomeToReferralvalet7; adminLogin(page,form,browser,Driver.Value('UserName')); Driver.Next(); } } function adminLogin(page,form,browser,userName) { var textbox; var table; var panel; page.Wait(); form = page.formAspnetform; textbox = form.textboxTxtusername; textbox.Click(78, 12); textbox.SetText(userName); }
There's no need to pass the driver object to your other function, just send in the value of the column.
Note also that I changed the call to Driver.Value to use the column header rather than the index (the index you had before was incorrect anyways since the username is column 0, not column 1).
Technically speaking, what you did before SHOULD have worked with the only problem being that you would be sending the password as the username. So, I guess the next question is... with what you had before... what was NOT working?
Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----
Why automate? I do automated testing because there's only so much a human being can do and remain healthy. Sleep is a requirement. So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.
Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have updated my script as you said.
but Error Occurs "Item cannot be found in the collection corresponding to the requested name or ordinal"
function adminLogin(page,form,browser,Driver,userName)
{
var textbox;
var table;
var panel;
page.Wait();
form = page.formAspnetform;
textbox = form.textboxTxtusername;
textbox.Click(78, 12);
textbox.SetText(userName);
}
function main()
{
var browser,page,form,Driver;
Browsers.Item(btFirefox, "", Browsers.pX64).Run("http://sysnetportal1/RVTesting_1/");
browser = Aliases.browser;
Driver=DDT.CSVDriver("C:/Users/Manoj.S/Desktop/Test complete forum doubts/RVData.csv")
while(!Driver.EOF())
{
page=browser.pageWelcomeToReferralvalet8;
loginClick(page,browser);
page = browser.pageWelcomeToReferralvalet7;
adminLogin(page,form,browser,Driver.Value('UserName'));
Driver.Next();
}
}
I have attached my CSV file for your reference:
When i tried to print column name using script :
temp=DDT.CurrentDriver.ColumnName(0);
Log.Message("Value of column is " + temp);
Message shown as "Value of column is UserName_Password ", why both column has combined
when i tried to access DDT.CurrentDriver.ColumnName(1);
Again Error occurs as "Item cannot be found in the collection corresponding to the requested name or ordinal"
Can you please on this, to retrieve my Username and password in CSV file.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The reason being is that it looks like you file is using some other delimiter than a comma to separate your columns. What delimiter are you using?
If you're using a delimiter other than a comma, you need to specify the delimiter or other necessary information in a schema.ini file stored in the directory with your CSV file. See https://support.smartbear.com/testcomplete/docs/testing-with/data-driven/csv-storages.html
Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----
Why automate? I do automated testing because there's only so much a human being can do and remain healthy. Sleep is a requirement. So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.
Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for Information. As you said, i have made Changes in CSV File using delimiter. now i can able to Read data and pass value to script
