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