How to Configure Selenium Webdriver in Eclipse and execute some simple test script.
2014-03-05 13:54
603 查看
Steps to install Selenium web driver in Eclipse:
Step
1: Install Java on your computer.
Download and install the Java Software Development Kit (JDK). You download the JDK file from this location:http://www.oracle.com/technetwork/java/javase/downloads/index.html
Note: This
JDK version comes bundled with Java Runtime Environment (i.e. JRE) so we don't need to install the JRE separately.
Step
2: Install Eclipses IDE
Now download “Eclipse IDE for Java Developers”. You can download eclipses from this location: http://www.eclipse.org/downloads/
Make sure to choose correct link for downloading eclipses which corresponds to your OS i.e. for Windows 32 Bit
and 64 Bit versions.
You should be able to download a ZIP file named “eclipse-java-kepler-SR1-win32-x86_64.zip”.
Inside the ZIP file, there is an “eclipse” folder which contains all the application files. So we can extract the
“eclipse” folder anywhere in your PC. Let say we want to extract it to C drive.
Step
3 – Download the Selenium Java Client Driver
You can download the Selenium Java Client Driver from this location:http://docs.seleniumhq.org/download/
Click
on Download link which is associated with java release. Download the jar files. You will find client drivers for other languages there, but only choose the one for Java as shown above in the screenshot.
After downloading you will get a folder which should contain two jar files related to selenium, a lib folder which
also contains jar files inside it. Beside this, there is a change log file as well. Refer to the screenshot below.
Create a new folder with name say 'Selenium' in C drive and extract the jar files to 'Selenium' folder.
Step
4: Create a New project in Eclipse:
Navigate to C drive and open eclipse folder where we have extacted all the application files related to eclipse.
In Eclipse folder you would find a 'eclipse.exe' file. Now click on the .exe file
This would ask you to select a workspace, you may accept the default location or simply create a new workspace
inside C drive and confirm OK.
- Now in Eclipse create a new project and for creating click on File menu –> New –> Java Project -> Name the project
as “testproject” and click finish.
- Create a new Java class, for doing this again click on File menu –> New -> Class then name it as “testclass”
and select the checkbox for 'public static void main (String[] args) and click finish.
On clicking 'Finish' in 'Java Class' wizard, your Eclipse IDE should look like the image below.
-
Now Right-click on testproject and select Properties.
- On the Properties window, click on “Java Build Path”.
- Click on the Libraries tab, and then click “Add External JARs..”
- Navigate to C:\selenium-2.37.0\ (or any other location where you saved the extracted contents of “selenium-2.37.0.zip”
in step 3).
- Add all the JAR files inside and outside the “libs” folder. Your Properties window after adding all the jar file
should now look similar to the image below.
- Finally, click OK and we have completed importing Selenium libraries into our project.
Step
5: Time to Code!!
Now it’s time to write some code. For this, let use the wikipedia site to create a sample script for test execution.
Example
1:
Example
2:
======================================
import java.util.regex.Pattern;
import java.util.concurrent.TimeUnit;
import org.junit.*;
import static org.junit.Assert.*;
import static org.hamcrest.CoreMatchers.*;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;
public class testClass {
private WebDriver driver;
@Before
public void setUp() throws Exception {
driver = new FirefoxDriver();
}
//
Search using keyword through Google search
@Test
public void testtestclass() throws Exception {
//Open
Home Page
driver.get("http://www.google.com");
//Enter
text in search box
driver.findElement(By.name("q")).sendKeys("selenium");
Thread.sleep(1000);
//Click
Search button
driver.findElement(By.name("btnG")).click();
Thread.sleep(10000);
}
@After
public void tearDown() throws Exception {
driver.quit();
}
}
=====================================
Happy testing :)
Thanks & Regards,
Pinaki Mohapatra
Quality Assurance Engineer
Mindfire
Solutions
Step
1: Install Java on your computer.
Download and install the Java Software Development Kit (JDK). You download the JDK file from this location:http://www.oracle.com/technetwork/java/javase/downloads/index.html
Note: This
JDK version comes bundled with Java Runtime Environment (i.e. JRE) so we don't need to install the JRE separately.
Step
2: Install Eclipses IDE
Now download “Eclipse IDE for Java Developers”. You can download eclipses from this location: http://www.eclipse.org/downloads/
Make sure to choose correct link for downloading eclipses which corresponds to your OS i.e. for Windows 32 Bit
and 64 Bit versions.
You should be able to download a ZIP file named “eclipse-java-kepler-SR1-win32-x86_64.zip”.
Inside the ZIP file, there is an “eclipse” folder which contains all the application files. So we can extract the
“eclipse” folder anywhere in your PC. Let say we want to extract it to C drive.
Step
3 – Download the Selenium Java Client Driver
You can download the Selenium Java Client Driver from this location:http://docs.seleniumhq.org/download/
Click
on Download link which is associated with java release. Download the jar files. You will find client drivers for other languages there, but only choose the one for Java as shown above in the screenshot.
After downloading you will get a folder which should contain two jar files related to selenium, a lib folder which
also contains jar files inside it. Beside this, there is a change log file as well. Refer to the screenshot below.
Create a new folder with name say 'Selenium' in C drive and extract the jar files to 'Selenium' folder.
Step
4: Create a New project in Eclipse:
Navigate to C drive and open eclipse folder where we have extacted all the application files related to eclipse.
In Eclipse folder you would find a 'eclipse.exe' file. Now click on the .exe file
This would ask you to select a workspace, you may accept the default location or simply create a new workspace
inside C drive and confirm OK.
- Now in Eclipse create a new project and for creating click on File menu –> New –> Java Project -> Name the project
as “testproject” and click finish.
- Create a new Java class, for doing this again click on File menu –> New -> Class then name it as “testclass”
and select the checkbox for 'public static void main (String[] args) and click finish.
On clicking 'Finish' in 'Java Class' wizard, your Eclipse IDE should look like the image below.
-
Now Right-click on testproject and select Properties.
- On the Properties window, click on “Java Build Path”.
- Click on the Libraries tab, and then click “Add External JARs..”
- Navigate to C:\selenium-2.37.0\ (or any other location where you saved the extracted contents of “selenium-2.37.0.zip”
in step 3).
- Add all the JAR files inside and outside the “libs” folder. Your Properties window after adding all the jar file
should now look similar to the image below.
- Finally, click OK and we have completed importing Selenium libraries into our project.
Step
5: Time to Code!!
Now it’s time to write some code. For this, let use the wikipedia site to create a sample script for test execution.
Example
1:
Example
2:
======================================
import java.util.regex.Pattern;
import java.util.concurrent.TimeUnit;
import org.junit.*;
import static org.junit.Assert.*;
import static org.hamcrest.CoreMatchers.*;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;
public class testClass {
private WebDriver driver;
@Before
public void setUp() throws Exception {
driver = new FirefoxDriver();
}
//
Search using keyword through Google search
@Test
public void testtestclass() throws Exception {
//Open
Home Page
driver.get("http://www.google.com");
//Enter
text in search box
driver.findElement(By.name("q")).sendKeys("selenium");
Thread.sleep(1000);
//Click
Search button
driver.findElement(By.name("btnG")).click();
Thread.sleep(10000);
}
@After
public void tearDown() throws Exception {
driver.quit();
}
}
=====================================
Happy testing :)
Thanks & Regards,
Pinaki Mohapatra
Quality Assurance Engineer
Mindfire
Solutions
相关文章推荐
- How to get browser name, version and operating system detail in selenium 2(Web driver)
- How to create and execute JAR file in Java – Command line Eclipse Netbeans
- How to set up and test a simple OLEDB Linked Server in Microsoft® SQL Server to allow retrieval of d
- How to take partial screenshot with Selenium WebDriver in python
- How to install MySQL JDBC driver in Eclipse web project without java.lang.ClassNotFoundexception com
- How can selenium web driver get to know when the new window has opened and then resume its execution
- How to Install And Configure Apache In Ubuntu
- How to change context root of a dynamic web project in Eclipse
- How to use HttpWebRequest and HttpWebResponse in .NET
- How to compile and run a simple java file in jenkins on Windows
- How to configure and use minicom in Ubuntu 12.04 User Manual
- How to configure a C/C++ project with Eclipse and CMake
- 在64位系统下安装32位ODBC驱动问题How to install and configure a 32 bit ODBC driver on a 64 bit Operating System?
- selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH.
- How to run selenium 2.0 script in jenkins
- How to create, host, test and consume a WCF Web Service
- selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH
- How to use write and run MapReduce in eclipse on windows.
- How to Reference and Use JSTL in your Web Application
- Using NUnit to Execute Selenium WebDriver Tests