forked from geoffreyarthaud/oc-testing-java-cours
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fc579f5
commit fcd5924
Showing
2 changed files
with
76 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
src/test/java/com/openclassrooms/testing/calcul/e2e/StudentMultiplicationJourneyE2E.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package com.openclassrooms.testing.calcul.e2e; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.openqa.selenium.By; | ||
import org.openqa.selenium.WebDriver; | ||
import org.openqa.selenium.WebElement; | ||
import org.openqa.selenium.firefox.FirefoxDriver; | ||
import org.openqa.selenium.support.ui.ExpectedConditions; | ||
import org.openqa.selenium.support.ui.WebDriverWait; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.boot.web.server.LocalServerPort; | ||
import org.springframework.test.context.junit.jupiter.SpringExtension; | ||
|
||
import io.github.bonigarcia.wdm.WebDriverManager; | ||
|
||
@ExtendWith(SpringExtension.class) | ||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) | ||
public class StudentMultiplicationJourneyE2E { | ||
|
||
@LocalServerPort | ||
private Integer port; | ||
private WebDriver webDriver = null; | ||
private String baseUrl; | ||
|
||
@BeforeAll | ||
public static void setUpFirefoxDriver() { | ||
WebDriverManager.firefoxdriver().setup(); | ||
} | ||
|
||
@BeforeEach | ||
public void setUpWebDriver() { | ||
webDriver = new FirefoxDriver(); | ||
baseUrl = "http://localhost:" + port + "/calculator"; | ||
} | ||
|
||
@AfterEach | ||
public void quitWebDriver() { | ||
if (webDriver != null) { | ||
webDriver.quit(); | ||
} | ||
} | ||
|
||
@Test | ||
public void aStudentUsesTheCalculatorToMultiplyTwoBySixteen() { | ||
|
||
// GIVEN | ||
webDriver.get(baseUrl); | ||
final WebElement leftField = webDriver.findElement(By.id("left")); | ||
final WebElement typeDropdown = webDriver.findElement(By.id("type")); | ||
final WebElement rightField = webDriver.findElement(By.id("right")); | ||
final WebElement submitButton = webDriver.findElement(By.id("submit")); | ||
|
||
// WHEN | ||
leftField.sendKeys("2"); | ||
typeDropdown.sendKeys("x"); | ||
rightField.sendKeys("16"); | ||
submitButton.click(); | ||
|
||
// THEN | ||
final WebDriverWait waiter = new WebDriverWait(webDriver, 5); | ||
final WebElement solutionElement = waiter.until( | ||
ExpectedConditions.presenceOfElementLocated(By.id("solution"))); | ||
final String solution = solutionElement.getText(); | ||
assertThat(solution).isEqualTo("32"); // 2 x 16 | ||
} | ||
} |