This tutorial assumes that you are familiar with Java and you have some basic knowledge in coding in Java. Assumes that you are familiar with installations(Running setup files). In order to start setup we should get below listed tools which helps you to write and customize your automation tests.
Pre-requisites:
- Eclipse - This is Java IDE where you will be writing your automation scripts. Download Eclipse IDE for Java EE Developers based on system configuration(32-bit or 64-bit).
- Selenium Webdriver Java Client Libraries - These libraries are used to customize your automation tests. At the time of writing this post the Webdriver version is 2.39. You can update these jars as per the current versions available. I am also including most useful Jars along with Webdriver Jars. Download them from here.
- TestNG - This is a test framework similar to JUnit. We will not use JUnit anywhere in our tutorials. I will explain how to integrate TestNG with eclipse later. TestNg plugin url for eclipse is,
For Eclipse 3.3 and below, enter http://beust.com/eclipse1.
Step by step guide to install TestNG in Eclipse:
- Download Eclipse from the link provided and install
- Open Eclipse from your installed location
- Open the Install New Software from Help menu on Eclipse. It opens this dialog,
- When above dialog appears click on Add button.
- Write 'TestNg' in name field or you can name it to what ever you want and get TestNG appropriate plugin url provided above and insert in to Location field by clearing the default text on it. If your url is correct you will see TestNg installation files on the install new software dialog.
- Select all check boxes and proceed with installation.
- Choose to trust the software site and Restart Eclipse after completion.
Now you have TestNg installed on your Eclipse. Let's see how to setup Webdriver project in Eclipse.
Step by step guide to setup Webdriver project in Eclipse:
- In Eclipse go to File -> New -> and select 'Java Project' if visible if not select 'Project'. You will see this dialog,
- Enter 'java' without quotes in Wizards input box and select 'Java Project' click Next.
- Give any name to the project that we are going to create. Let's say selenium.demo and click finish. You will see selenium.demo project in the Package Explorer on Eclipse. Expand it.
- Right click on src and select New -> Package.
- Give it any name. Let's say com.selenium.webdriver. Click here to know best practice in naming the package.
- Now right click on your package created in above step and select New -> Class.
- Give it any name. Let's say WebdriverDemo. Usually the best practice is to use Upper Camel Case like WebdriverDemo. Try to use nouns because a class is normally representing something in the real world.
- Leave everything default click Finish. See here,
- Now it's time to download the Selenium Webdriver libraries(Jars). Download it from above given link. Create directory called 'selenium' in C:\ drive. Move downloaded Jars to that directory. So path to the Jars is now 'C:\selenium'
- Now right click on the project title and go to Build Path -> Configure Build Path. You will see this dialog,
- Select Libraries tab and click Add External JARs. This will open file explorer.
- Go to the directory where Jars are located and select all of them and click open. Yours Jars are associated with your project now.
- Double click on the class file created in step 7 in order to open it.
- Copy the below code and paste it in your class.
- Right click on the editor and select Run As -> TestNG Test.
- If everything is fine, above code will launch the firefox browser, loads Google search page and prints 'Web page title: Google' in the console.
That's it, you are done with your setup. Follow my forthcoming posts to learn advanced usage of Webdriver.
If you really want to learn Selenium it's better to install an open source web application on your machine because they are stable. Here is a good application to automate - Sugar CRM.
See my post to know how to install Sugar CRM application and launch it - here.
If you really want to learn Selenium it's better to install an open source web application on your machine because they are stable. Here is a good application to automate - Sugar CRM.
See my post to know how to install Sugar CRM application and launch it - here.
No comments:
Post a Comment