SELENIUM2 (Java) environment to build a

Source: Internet
Author: User

SELENIUM2 (Java) Environment setup

1. Download the JDK

Http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

2. Configure the Java environment variables, relatively simple, you can Baidu to compare the full configuration environment variables of the document:

Http://jingyan.baidu.com/article/f96699bb8b38e0894e3c1bef.html

3. Download Eclipse

Https://www.eclipse.org/downloads/packages/release/luna/sr2

4. Download selenium2 related libraries, version selenium-2.48.2

Link: Http://pan.baidu.com/s/1THNoa Password: 75CN

5. Introducing the Selenium class library into eclipse

Unzip the 4 downloaded compression pack

Open Eclipse and create a new user-defined class library:

Windos---Preference to Java--Build path----User Libraries

To create a new custom class library named Selenuim

Import the Selenium class library and import selenium-2.48.2 the following jar packages and the jar packages below Libs

Click on the Ok,selenium development environment to complete the basic construction.

6. A simple example

Create a new Java Project, named Seleniumtest, to import the custom class library from 5 into the seleniumtest:

Right-click seleniumtes–-> Build path–-> Add libraries–-> User library–-> Next--Tick selenuim–-> Finish

Create a new Java class with the class name: Firstcase

The specific code is as follows:

 Packageseleniumtest;Importorg.openqa.selenium.By;ImportOrg.openqa.selenium.WebDriver;Importorg.openqa.selenium.WebElement;ImportOrg.openqa.selenium.firefox.FirefoxDriver;ImportOrg.testng.Assert; Public classFirstcase { Public Static voidMain (string[] args) {//TODO auto-generated Method Stub//declare a Firefox driver objectWebdriver Driver =NewFirefoxdriver (); //Open SougoDriver.get ("http://www.sogou.com"); //Locate the search boxWebelement searchinput = driver.findelement (by.name ("Query"));        //search box Enter keywordsSearchinput.sendkeys ("Selenium"); //Locate Search buttonWebelement SearchButton = driver.findelement (By.id ("STB")); //Click the Search buttonSearchbutton.click (); Try{Thread.Sleep (2000); } Catch(interruptedexception e) {e.printstacktrace (); }        //Assert search Results pageWebelement keywordinput = driver.findelement (By.id ("Upquery")); Assert.assertequals (Keywordinput.getattribute ("Value"), "Selenium"); //Close BrowserDriver.quit (); }}

SELENIUM2 (Java) environment to build a

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.