Skip to content

Instantly share code, notes, and snippets.

@noriyukitakei
Last active September 23, 2018 13:53
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 noriyukitakei/3f603a0ccfe034ae71425eeb0ec8a82a to your computer and use it in GitHub Desktop.
Save noriyukitakei/3f603a0ccfe034ae71425eeb0ec8a82a to your computer and use it in GitHub Desktop.
コンテナ時代のDevOps 〜Azure Web Apps for Containers + Docker + Jenkins + SeleniumでイマドキのCI/CDをやってみる [理論編]〜 E2ETest.java
package com.sios.test;
import static org.junit.Assert.*;
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;
import org.openqa.selenium.chrome.ChromeOptions;
public class E2ETest {
@Test
public void test() throws InterruptedException {
// テストを実施したいアプリケーションのURLを環境変数から取得する。
String url = System.getenv("HELLOWORLD_URL");
// ChromeDriverまでのパスを環境変数から取得する。
String webdriverPath = System.getenv("WEBDRIVER_PATH");
// ChromeDriverまでのパスを設定する
System.setProperty("webdriver.chrome.driver", webdriverPath);
// Chromeをheadlessモードで起動する。
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.addArguments("--headless");
// Chromeドライバーインスタンスを作成する。
WebDriver driver = new ChromeDriver(chromeOptions);
// テストを実施したいアプリケーションのURLを設定する。
driver.get(url);
// idがhelloという要素を取得する。
// 実際には<h1 id='hello'>Hello World!!</h1>というHTMLの
// Hello World!!という部分を取得する処理である。
WebElement searchElement = driver.findElement(By.id("hello"));
String title = searchElement.getText();
// ブラウザーを閉じる
driver.quit();
// 画面に表示されている文字列がHello World!!かどうかをチェックする。
assertEquals(title, "Hello World!!");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment