Recently in the study of Java+selenium automated testing, online more information, their own test practice, sorting out a relatively perfect set of environmental information, because many online download practice process, found a lot of mismatch problems, what JDK and Eclipse does not match, Selenium and Fire Fox don't match.
First, the development environment:
1, JDK1.7:HTTP://PAN.BAIDU.COM/S/1O7OAQVC NYBK
2. Eclipse 32-bit: This file cannot be used because of the sharing link, only this map as its own essay record (if necessary small partners can add my friends).
3, Selenium:selenium-java-2.46.0.zip,:http://pan.baidu.com/s/1qyvgleo 4vck
4, Firefox 44.0.2: This file cannot be used because of the sharing link, only this map as a record of their own essays (if the need for a small partner can add my friends. )。
The following content is for reference only, for reference to others:
Second, decompression Selenium-java package:
This package contains four parts, such as:
Third, create a new Java Project:
1, then the above extracted files copied to the new project directory, directory structure such as:
2. Add build path, project directory right click-->build path--> Config build Path-->java build Path-->libraries-->add JARs
Add all the jar packages under the Libs folder and add selenium-java-2.39.0 and Selenium-java-2.39.0-srcs
3, add after the directory structure, such as, more referenced Libraries, here is the above step added to the jar package:
4, the source of related webdriver:
Now that the environment is ready to work, here is a simple little example to write.
Iv. Create a new test class under SRC, such as:
The code below, mainly open Baidu, and then enter Glen in the Search box, click the Search button, close the browser.
1 PackageCom.selenium.Glen;2 3 Importorg.openqa.selenium.By;4 ImportOrg.openqa.selenium.WebDriver;5 Importorg.openqa.selenium.WebElement;6 ImportOrg.openqa.selenium.firefox.FirefoxDriver;7 8 Public classTesthelloworld {9 Ten Public Static voidMain (string[] args) { One A //If Firefox is not installed by default on the C drive, you need to set its path - //system.setproperty ("Webdriver.firefox.bin", "D:/program Files (x86)/mozilla Firefox/firefox.exe"); -System.setproperty ("Webdriver.firefox.bin", "D:/firefox/firefox.exe"); theWebdriver Driver =Newfirefoxdriver (); -Driver.get ("http://www.baidu.com/"); - driver.manage (). window (). Maximize (); -Webelement txtbox = driver.findelement (By.name ("WD")); +Txtbox.sendkeys ("Glen"); - +System.out.println ("Ready to start click on" Baidu Search ""); AWebelement btn = driver.findelement (by.id ("su")); at -System.out.println ("Click to End"); - Btn.click (); - -System.out.println ("Off"); - driver.close (); in - } to}
View Code
Then Run As--java application to see the effect.
Selenium + Java Getting Started environment building