Selenium Data Driven using Properties files

We need to get value from a data source for different purpose here listed some of the basics.
  • GUI Components
  • Test Data
  • URLs
GUI Components:
If we have mapped the GUI components with a value we can change the value in a single place rather changing in whole script where ever we used.
Test Data:
We can pre designed test data with all available or maximum possible combination of  user input.
URLs:

We should test our same script in different environment like test, Production etc. For that we could have get the urls from a variable instead of making a whole script customization or copy.
Similarly we could have different purpose and tweaks for data driven. even we can connect the data source using spread sheets, data connectors etc. Here we have one more option for small data handling.

Steps to configure Properties files:
1.Create a Java project in Eclipse.
2.Right click on the source folder . Select File --> New --> File.
3.Give a file name with extension as .properties and click Finish.
4.Now the file will be listed in your package Explorer.
5.Open the properties file.














6. Enter the below line.


 Search=Firefox,InternetExplorer,GoogleChrome.as shown in figure.

Copy and Paste the Below and Run!!!
import java.util.ResourceBundle;
import java.util.StringTokenizer;
import org.openqa.selenium.server.SeleniumServer;
import com.thoughtworks.selenium.DefaultSelenium;
import com.thoughtworks.selenium.Selenium;

public class DataDrivenTests {

    static SeleniumServer server;
    static Selenium selenium;
   
    public static void main (String[] args) throws Exception {
        server = new SeleniumServer();
        server.start();
       
        selenium = new DefaultSelenium("localhost", 4444, "*iehta","http://www.google.co.in");
        selenium.start();
        selenium.open("");
        ResourceBundle bundle = ResourceBundle.getBundle("datasuite");
        String Channel = bundle.getString("Search");
        StringTokenizer st = new StringTokenizer (Channel,",");
        while(st.hasMoreTokens()){
            String value = st.nextToken();
            selenium.type("name=q",value);
            Thread.sleep(1000);
        }
        selenium.close();
        selenium.stop();
        server.stop();
        }
    }

9 comments:

  1. Thanks for sharing great information in your blog. Got to learn new things from your Blog . It was very nice blog to learn about Selenium

    ReplyDelete
  2. Thanks for sharing great information in your blog. Got to learn new things from your Blog . It was very nice blog to learn about Selenium.
    Selenium

    ReplyDelete
  3. Advanced Selenium Framework Training in Chennai by Vishwa

    Hi, Reach Mr.Vishwa for Best Selenium and Coded UI Training in Chennai with real time project assistance. This people will teach everything from the basics up to advanced level scenarios from frameworks.

    I learned from Mr.Vishwa and Raj they are very good automation people for Selenium Frameworks. After joined with them I learned many things and now I am writing automation scripts in own project. Vishwa 9003085882
    selenium training in chennai

    ReplyDelete
  4. Join them for the best selenium training in Chennai and placements.
    Call them at 8122241286.
    www.thecreatingexperts.com
    selenium training in chennai

    ReplyDelete
  5. This comment has been removed by the author.

    ReplyDelete
  6. The Creating Experts provides training in SELENIUM

    They provide hands on training with real time scenarios

    http://thecreatingexperts.com/selenium-training-in-chennai/

    contact +91-08122241286

    ReplyDelete
  7. nice blog...Selenium training is offered by THE CREATING EXPERTS in Chennai

    http://thecreatingexperts.com/selenium-training-in-chennai/

    contact 8122241286

    ReplyDelete
  8. Very Nice...Contains A to Z concepts...Thanks a lot.. and looking for the best selenium training in Chennai with certification from us. we have experienced selenium experts offer selenium course training with industry exposure. Check Here https://goo.gl/VRNEXv

    ReplyDelete
  9. The most popular destination for Hadoop Training in

    Noida
    in NOIDA is CIITNOIDA in Sector-2

    You can Master the various components of Hadoop ecosystem like Hadoop, MapReduce Architecture, Pig, Hive, HBase, Sqoop, Flume by their Senior Experts

    from Industry with good Industrial experience of handling big projects.

    You can even Get hands-on practice with live projects and ORACLE certification at CIITNOIDA.

    This Big Data Hadoop Training in Noida is best

    suited for CS & IT Engineering Students, professionals looking to gain expertise in Big Data and work for Fortune 500 Software Companies.

    Hadoop Training in Noida
    Big Data Hadoop Training in Noida

    ReplyDelete