Skip to content

Instantly share code, notes, and snippets.

@ksakae1216
Last active June 14, 2016 07:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ksakae1216/21ef6d1da3121f564acd339ec2aed00e to your computer and use it in GitHub Desktop.
Save ksakae1216/21ef6d1da3121f564acd339ec2aed00e to your computer and use it in GitHub Desktop.
package webDriverSample;
import static org.junit.Assert.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
public class SeleniumWebDriverJunit {
private WebDriver driver;
@Before
public void beforeTest() {
System.setProperty("webdriver.chrome.driver", "driver/chromedriver");
driver = new ChromeDriver();
}
@After
public void afterTest() throws InterruptedException {
Thread.sleep(2000);
driver.quit();
}
// google検索画面を開いて、検索する
@Test
public void searchTest() {
driver.get("https://www.google.co.jp/");
WebElement element = driver.findElement(By.name("q"));
element.sendKeys("フリーランス チャレンジ selenium"); //検索文字をセット;
element.submit();
assertEquals("Google", driver.getTitle()); //ページタイトルが想定通りか、チェック
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment