Showing posts with label 7. Show all posts
Showing posts with label 7. Show all posts

Friday, 21 October 2011

Example - Data driven test using a csv text file

Aim:Data driven example using CSV ( Comma Separated Variable) file and Selenium 2. The example demonstrates adding new posts to the wordpress test site via the csv file. Test data data can be added to the csv file.


Difficulty Level: High

Prerequisites:
Commands used in example:
  • Driver.manage()
  • Driver.get(baseUrl)
  • Driver.findElement by id, linkText, cssSelector and xpath
  • clear()
  • sendkeys()
  • click()
  • random string
Steps in implementation:
  1. Download and Install Eclipse IDE using link http://www.eclipse.org/downloads/.     
  2. Tip: download the version suitable for your PC ( 32 bit/64bit))
  3. Download the Selenium2 API 'selenium-server-standalone-*.jar' library using link http://seleniumhq.org/download
  4. No need to get JUnit jar file in separate as it is inbuilt in  'selenium-server-standalone-*.jar'.
  5. Download and save the file as selenium.csv in C: drive from here
  6. Launch the Eclipse IDE.
  7. Create a new Java project and name it FirstExample. You will see a default folder 'src' inside it.
  8. Do right click on the created project and select Build Path >> Configuration Build Path.
  9. Add 'selenium-server-standalone-*.jar' under Libraries tab by clicking 'Add External Jars'.
  10. Add downloaded "javacsv-2.0.jar"  under Libraries tab by clicking 'Add External Jars'.
  11. Right click on 'src' and add a package 'com.example.tests'.
  12. Create  java classes  'DataDriven.java ' into the created package.
  13. Paste the below mentioned two script in corresponding java files.
  14. Right click 'DataDriven.java' and click 'Run as >> JUnit test'.
  15. During the execution you would see that created post title is read from the CSV file.