how to get data data from properties file using TestNG in Selenium Webdriver

6,410 views
Skip to first unread message

MonikaY

unread,
Sep 7, 2012, 2:43:34 AM9/7/12
to seleniu...@googlegroups.com
Hi.

I am using Selenium Webdriver+ pageobjects + TestNG +java
In which my user name and password are saved in properties file (say file1) and url to site in another properties file (say file2).
I am able to get their data in main class when  I am using Selenium Webdriver+ pageobjeccts.....but I want recontruct my code using TestNG ...how can i get data from properties file in my @Test Method using TestNG......

Please help!!!

Thanks

Krishnan Mahadevan

unread,
Sep 7, 2012, 2:47:54 AM9/7/12
to seleniu...@googlegroups.com
http://www.exampledepot.com/egs/java.util/props.html 

Reading properties file is not selenium related and you should be easily able to find sufficient samples/tutorials on the net that teach you how to do it.


Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"




--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/HU0-xsgwh4oJ.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

sita maram

unread,
Sep 7, 2012, 2:55:24 AM9/7/12
to seleniu...@googlegroups.com
Hi,

i hope below code will work,

FileInputStream  fis=new FileInputStream(say file1 path)

Properties p=new Properties();
p.load(fis);

System.out.println(p.getProperty("UserName"));

let me know if more required.

Thanks,


On Fri, Sep 7, 2012 at 12:13 PM, MonikaY <monik...@gmail.com> wrote:

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/HU0-xsgwh4oJ.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
Thanks and Regards,
M.Sitaramireddy.

Manoj Hans

unread,
Sep 7, 2012, 3:58:15 AM9/7/12
to seleniu...@googlegroups.com
Hi Monika,

As krishnan said this is not selenium related so that post the same question in testng group.


--Manoj Hans

MonikaY

unread,
Sep 7, 2012, 5:03:05 AM9/7/12
to seleniu...@googlegroups.com
Hi ramireddy maram

testdata.properties contains:
username:abc
password:9999

logindataTest.java have:
 Properties properties = new Properties();
        properties.load(new FileReader(new File(System.getProperty("user.dir")+"\\config\\testdata.properties")));
        String str = "username:";
        String str1= "password:";
        page.login(properties.getProperty(str),properties.getProperty(str1));

When I run script.... it always prints "null" in username and password field......inspite of printing "abc" and "9999"

SantoshSarma

unread,
Sep 7, 2012, 5:10:19 AM9/7/12
to seleniu...@googlegroups.com
Hi Monica,

Try below logic.

FileInputStream in = new FileInputStream(new File(Property File Path));
Properties pro = new Properties();
pro.load(in);
pro.getProperty(key);

Regards,
SantoshSarma

Manoj Hans

unread,
Sep 7, 2012, 5:36:09 AM9/7/12
to seleniu...@googlegroups.com
remove ':' after username

--Manoj Hans

sita maram

unread,
Sep 7, 2012, 5:45:41 AM9/7/12
to seleniu...@googlegroups.com
Hi,

Please try this below code


testdata.properties contains:
                username:abc
                password:9999

                logindataTest.java have:
                 Properties properties = new Properties();
                        properties.load(new FileReader(new File(System.getProperty("user.dir")+"\\config\\testdata.properties")));
                      
                        page.login(properties.getProperty("username"),properties.getProperty("password"));



Thanks,
ram.

To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/03upVT503B8J.

For more options, visit https://groups.google.com/groups/opt_out.
 
 

Manoj Hans

unread,
Sep 7, 2012, 5:51:24 AM9/7/12
to seleniu...@googlegroups.com
ramireddy maram-- same thing i posted in my earlier post..

  String str = "username:";
        String str1= "password:"; 

these two should be like this 

  String str = "username";
        String str1= "password"; 


--Manoj Hans

MonikaY

unread,
Sep 7, 2012, 6:08:26 AM9/7/12
to seleniu...@googlegroups.com
Hi Manoj Hans

The problem was I was using ":" instead of "="
Now its fine. Thanks all...

Manoj Hans

unread,
Sep 7, 2012, 6:26:15 AM9/7/12
to seleniu...@googlegroups.com
ohok i missed the same thing but the problem with ":" as well when u was storing value's in string.


--Manoj Hans

Mike Riley

unread,
Sep 7, 2012, 4:08:12 PM9/7/12
to seleniu...@googlegroups.com
Actually, I think he was asking more how he could use it in TestNG, but that still isn't really a Selenium issue.

Try looking on the TestNG forum:
https://groups.google.com/forum/#!forum/testng-users

Mike
Reply all
Reply to author
Forward
0 new messages