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:
Difficulty Level: High
Prerequisites:
- Eclipse IDE installed
- javacsv-2.0 Jar from http://mirrors.ibiblio.org/pub/mirrors/maven2/net/sourceforge/javacsv/javacsv/2.0/javacsv-2.0.jar
- Selenium 2 Library
- Driver.manage()
- Driver.get(baseUrl)
- Driver.findElement by id, linkText, cssSelector and xpath
- clear()
- sendkeys()
- click()
- random string
- Download and Install Eclipse IDE using link http://www.eclipse.org/downloads/.
- Tip: download the version suitable for your PC ( 32 bit/64bit))
- Download the Selenium2 API 'selenium-server-standalone-*.jar' library using link http://seleniumhq.org/download
- No need to get JUnit jar file in separate as it is inbuilt in 'selenium-server-standalone-*.jar'.
- Download and save the file as selenium.csv in C: drive from here
- Launch the Eclipse IDE.
- Create a new Java project and name it FirstExample. You will see a default folder 'src' inside it.
- Do right click on the created project and select Build Path >> Configuration Build Path.
- Add 'selenium-server-standalone-*.jar' under Libraries tab by clicking 'Add External Jars'.
- Add downloaded "javacsv-2.0.jar" under Libraries tab by clicking 'Add External Jars'.
- Right click on 'src' and add a package 'com.example.tests'.
- Create java classes 'DataDriven.java ' into the created package.
- Paste the below mentioned two script in corresponding java files.
- Right click 'DataDriven.java' and click 'Run as >> JUnit test'.
- During the execution you would see that created post title is read from the CSV file.