eclipse統合selenium
1)jdk、eclipse、Firefoxの設置を確保する.
2)selenium-java-2.1.0.jarとselenium-server-standarloneをダウンロードします.
ダウンロードの住所はhttp://docs.seleniumhq.org/download/
selenium-java-2.1.0.jarのダウンロード位置は下図の通りです.
selenium-server-standowne-2.1.0.jarの具体的なダウンロード位置は以下の通りです.
3)eclipseを開いてjavaプロジェクトを新規作成し、ダウンロードしたselenium-java-2.1.0.zipを解凍してjavaプロジェクトに貼り付け、ダウンロードしたselenium-server-standowne-2.1.0.jarをjavaプロジェクトに貼り付けます.
4)JUnitを追加する
右クリック工程名>属性>Java Build Path>Libries>Add Library選択JUnit>Next>Finish
5)selenium-java-2.1.0.jarとselenium-server-standarloneを追加します.
右クリック工程名>属性>Java Build Path>Libries>Add JARsは先ほど貼り付けたselenium-java-2.1.4.jarとselenium-server-standlone-2.1.0.jarを選択します.
6)Selenium Test.javaの新規作成の具体的なコードは以下の通りです.
右クリックTestメソッド>Run as>JUnit test
2)selenium-java-2.1.0.jarとselenium-server-standarloneをダウンロードします.
ダウンロードの住所はhttp://docs.seleniumhq.org/download/
selenium-java-2.1.0.jarのダウンロード位置は下図の通りです.
selenium-server-standowne-2.1.0.jarの具体的なダウンロード位置は以下の通りです.
3)eclipseを開いてjavaプロジェクトを新規作成し、ダウンロードしたselenium-java-2.1.0.zipを解凍してjavaプロジェクトに貼り付け、ダウンロードしたselenium-server-standowne-2.1.0.jarをjavaプロジェクトに貼り付けます.
4)JUnitを追加する
右クリック工程名>属性>Java Build Path>Libries>Add Library選択JUnit>Next>Finish
5)selenium-java-2.1.0.jarとselenium-server-standarloneを追加します.
右クリック工程名>属性>Java Build Path>Libries>Add JARsは先ほど貼り付けたselenium-java-2.1.4.jarとselenium-server-standlone-2.1.0.jarを選択します.
6)Selenium Test.javaの新規作成の具体的なコードは以下の通りです.
import java.io.File;
import junit.framework.Assert;
import org.junit.Before;
import org.junit.After;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxBinary;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
public class SeleniumTest {
private WebDriver driver=null;
@Before
public void setUp() throws Exception {
System.out.println("setUp");
// firefox,
//File pathToFirefoxBinary = new File("F:/Mozilla Firefox/firefox.exe");
//FirefoxBinary firefoxbin = new FirefoxBinary(pathToFirefoxBinary);
//driver=new FirefoxDriver(firefoxbin, null);
driver=new FirefoxDriver();
driver.get("http://www.baidu.com");
}
@After
public void tearDown() throws Exception {
System.out.println("tearDown");
driver.quit();
}
@Test
public void doMyTest(){
WebElement kwElement=driver.findElement(By.id("kw1"));
kwElement.sendKeys("hyddd");
WebElement suElement=driver.findElement(By.id("su1"));
suElement.click();
WebDriverWait wait=new WebDriverWait(driver, 10);
// 。 10s , , 500ms 。
WebElement element=
wait.until(ExpectedConditions.presenceOfElementLocated(By.id("content_left")));
Assert.assertTrue(element.isDisplayed());
}
}
7)Testを実行する 右クリックTestメソッド>Run as>JUnit test