Selenium Java Quickly Setup on Eclipse
Prepare...
Hint: It's very sensitive about version!!
Hint 2: Download Type 32 bit is better...
Eclipse neon [Download & Install]
https://www.eclipse.org/downloads/download.php?file=/oomph/epp/neon/R2a/eclipse-inst-win64.exe
Java JDK [Download & Install]
http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
Chrome Driver [Download]
https://chromedriver.storage.googleapis.com/index.html?path=2.27/
Geckodriver (V 0.14) [Download]
https://github.com/mozilla/geckodriver/releases
Firefox Browser [Install]
Chrome Browser [Install]
===============================================================
To do....
1. Create Java Project
include main
2. Put every thing in your Project Path
chromedriver
geckodriver
3. Import Library of Selenium By get Code from this site
https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java/3.2.0https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-server/3.2.0
4. Insert to pom.xml in Project @ Eclipse. It's auto-update.
<dependencies><!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-server -->
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-server -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-server</artifactId>
<version>3.2.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.2.0</version>
</dependency>
</dependencies>
5. Code test here "Run on Firefox"
package testSelenium;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class test {
public static void main(String[] args) {
// TODO Auto-generated method stub
WebDriver driver = new FirefoxDriver();
// And now use this to visit Google
driver.get("http://www.google.com");
// Alternatively the same thing can be done like this
// driver.navigate().to("http://www.google.com");
// Should see: "cheese! - Google Search"
//System.out.println("Page title is: " + driver.getTitle());
//Close the browser
driver.quit();
}
}
6. Code test here "Run on Chrome"
package testSelenium;import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class test {
public static void main(String[] args) throws InterruptedException {
// TODO Auto-generated method stub
System.setProperty("webdriver.chrome.driver", "chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("http://www.google.com/xhtml");
Thread.sleep(5000); // Let the user actually see something!
WebElement searchBox = driver.findElement(By.name("q"));
searchBox.sendKeys("ChromeDriver");
searchBox.submit();
Thread.sleep(5000); // Let the user actually see something!
driver.quit();
}
}
ไม่มีความคิดเห็น:
แสดงความคิดเห็น