Preparation:
1. Download JDK (http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html)
2. Download Eclipse ( https://www.eclipse.org/downloads/download.php?file=/oomph/epp/mars/R2/eclipse-inst-win64.exe )
3. Download Selenium, Selenium Standalone Server and IE Driver. (http://www.seleniumhq.org/download/)
Choose your language for selenium to develop your tests(Java, C# or Python)
4. Download the Chrome driver (https://sites.google.com/a/chromium.org/chromedriver/)
5. Here are the basic files you needed.
Configuration
1. Create a new Java project in Eclipse
2. Add External JARs into the Java Build Path.
a. Add selenium-java-xxxx.jar
b. Add selenium-server-standalone-xxxx.jar
c. (Optional) Add sesenium-java-xxxx-src.jar
d. Add all the jars in the libs of Selenium folder.
Validate the configuration with the sample Test
package test; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.chrome.ChromeOptions; public class TestBaidu { public static void main(String [] args){ System.setProperty("webdriver.chrome.driver", "E:\\Java\\selenium\\driver\\chromedriver.exe"); ChromeOptions o = new ChromeOptions(); o.addArguments("disable-extensions"); o.addArguments("--start-maximized"); WebDriver driver = new ChromeDriver(); //Try the FirefoxDriver //WebDriver driver = new FirefoxDriver(); driver.get("http://www.baidu.com"); driver.findElement(By.id("kw")).sendKeys("Hello Webdriver!"); driver.findElement(By.id("su")).click(); System.out.println(driver.getTitle()); driver.quit(); } }
FAQ:
1. Sometimes you will encounter a "Firefox crash issue" while testing with FF driver, how to fix it?
Answer: Most of the time, it is becasue of the Firefox driver is not compatible with the latest version of Firefox browser.
Please check the version of your installed Firefox browser and downgrade it to the lower version (Version 36 or so).
2. How to show Chinese characters correct?
Answer: By default, in the console of eclipse, it will not show Chinese correct, so you should update the encoding in the run configuration: