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