diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..5ff6309b7199129c1afe4f4ec1906e640bec48c6 --- /dev/null +++ b/.gitignore @@ -0,0 +1,38 @@ +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### IntelliJ IDEA ### +.idea/modules.xml +.idea/jarRepositories.xml +.idea/compiler.xml +.idea/libraries/ +*.iws +*.iml +*.ipr + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..13566b81b018ad684f3a35fee301741b2734c8f4 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000000000000000000000000000000000000..78bf31cbb89b4b22be2881cef81ce22d6d111110 --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000000000000000000000000000000000000..4878ef2247de552705f007fe3af527604a6306c3 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,14 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/php.xml b/.idea/php.xml new file mode 100644 index 0000000000000000000000000000000000000000..8250cf43b564208c1d9cae4ff90e4559a13950c7 --- /dev/null +++ b/.idea/php.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000000000000000000000000000000000000..94a25f7f4cb416c083d265558da75d457237d671 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000000000000000000000000000000000000..0dfa564b41dec5b7d8efe02fcf1410764f19c4a7 --- /dev/null +++ b/pom.xml @@ -0,0 +1,169 @@ + + + 4.0.0 + + fr.test.formation + RobotSelenium + 1.0-SNAPSHOT + + + 25 + UTF-8 + 6.0.3 + 6.0.3 + 7.20.1 + 5.8.2 + 3.13.0 + 3.21.0 + 3.5.2 + 3.8.0 + + + + + + org.junit + junit-bom + ${junit.version} + pom + import + + + + + + + ch.qos.logback + logback-classic + 1.5.22 + + + + io.cucumber + cucumber-java + ${cucumber.version} + test + + + + io.cucumber + cucumber-junit-platform-engine + ${cucumber.version} + test + + + + io.cucumber + cucumber-picocontainer + ${cucumber.version} + test + + + + org.junit.platform + junit-platform-suite + ${junit-platform.version} + test + + + + org.junit.jupiter + junit-jupiter-engine + ${junit.version} + test + + + + org.seleniumhq.selenium + selenium-java + 4.26.0 + + + + io.github.bonigarcia + webdrivermanager + 5.9.2 + + + + + + + org.apache.maven.plugins + maven-jar-plugin + 3.4.1 + + + default-jar + + none + + + + + org.apache.maven.plugins + maven-compiler-plugin + ${maven.compiler.version} + + + org.apache.maven.plugins + maven-site-plugin + ${maven.site.version} + + + org.apache.maven.skins + maven-fluido-skin + 2.1.0 + + + + + org.apache.maven.plugins + maven-project-info-reports-plugin + ${maven.project-info.version} + + + org.apache.maven.plugins + maven-surefire-plugin + ${surefire.version} + + true + + + cucumber.junit-platform.naming-strategy=long + cucumber.plugin=json:target/cucumber-reports/cucumber.json + + + + + + + net.masterthought + maven-cucumber-reporting + ${cucumberReport.version} + + + execution + verify + + generate + + + Rapport de Tests Automatisation - RobotSelenium + ${project.reporting.outputDirectory} + ${project.build.directory}/cucumber-report + + **/*.json + + false + false + false + + + + + + + \ No newline at end of file diff --git a/src/site/site.xml b/src/site/site.xml new file mode 100644 index 0000000000000000000000000000000000000000..9a0508b370e03d7e4215fde5ef0dd63334114181 --- /dev/null +++ b/src/site/site.xml @@ -0,0 +1,19 @@ + + + + org.apache.maven.skins + maven-fluido-skin + 2.1.0 + + + + + + + + + + diff --git a/src/test/java/TestExample.java b/src/test/java/TestExample.java new file mode 100644 index 0000000000000000000000000000000000000000..6e864d6356a568fda91af9f421a4d322e65d1527 --- /dev/null +++ b/src/test/java/TestExample.java @@ -0,0 +1,56 @@ +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.openqa.selenium.By; +import org.openqa.selenium.JavascriptExecutor; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.firefox.FirefoxDriver; +import org.openqa.selenium.firefox.FirefoxOptions; +import org.openqa.selenium.support.ui.ExpectedConditions; +import org.openqa.selenium.support.ui.WebDriverWait; + +import java.time.Duration; +import java.util.Map; + +public class TestExample { + private WebDriver driver; + private Map vars; + JavascriptExecutor js; + WebDriverWait wait; + + @BeforeEach + public void setUp() { + // Pour l'anglais : "en-US", pour le français : "fr-FR" + FirefoxOptions options = new FirefoxOptions(); + options.addPreference("intl.accept_languages", "en-US"); + options.addArguments("--headless"); + driver = new FirefoxDriver(); // ajouter options au driver pour les prendre en compte + js = (JavascriptExecutor) driver; + driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(3)); + wait = new WebDriverWait(driver, Duration.ofSeconds(15)); + } + + @AfterEach + public void tearDown() { + driver.quit(); + } + + @Test + public void test1() { + driver.get("https://disc.univ-fcomte.fr/m2gl-webRobot/Accueil.php?seed=12"); + WebElement newMap = wait.until(ExpectedConditions.elementToBeClickable(By.id("newMap"))); + newMap.click(); + driver.findElement(By.id("turnLeft")).click(); + driver.findElement(By.id("forward")).click(); + driver.findElement(By.id("backward")).click(); + driver.findElement(By.id("turnLeft")).click(); + driver.findElement(By.id("backward")).click(); + driver.findElement(By.id("turnRight")).click(); + Assertions.assertEquals("-23", driver.findElement(By.id("xRobot")).getText()); + Assertions.assertEquals("-22", driver.findElement(By.id("yRobot")).getText()); + Assertions.assertEquals("2", driver.findElement(By.id("energy")).getText()); + Assertions.assertEquals( "Orientation du robot : Ouest", driver.findElement(By.cssSelector("h3:nth-child(2)")).getText()); + } +} diff --git a/src/test/java/acceptance/RobotTest.java b/src/test/java/acceptance/RobotTest.java new file mode 100644 index 0000000000000000000000000000000000000000..ecd9fb1ea00d6fbb7e1496bb2e6c75361789a925 --- /dev/null +++ b/src/test/java/acceptance/RobotTest.java @@ -0,0 +1,17 @@ +package acceptance; + +import org.junit.platform.suite.api.*; + +import static io.cucumber.junit.platform.engine.Constants.GLUE_PROPERTY_NAME; +import static io.cucumber.junit.platform.engine.Constants.PLUGIN_PROPERTY_NAME; + +@Suite +@IncludeEngines("cucumber") +@SelectPackages("acceptance") +@SelectClasspathResource(".") +@ConfigurationParameter(key = PLUGIN_PROPERTY_NAME, value = "json:target/cucumber-report/cucumber.json") +@ConfigurationParameter(key = GLUE_PROPERTY_NAME, value = "acceptance") + +public class RobotTest { + +} diff --git a/src/test/java/acceptance/robotFixture.java b/src/test/java/acceptance/robotFixture.java new file mode 100644 index 0000000000000000000000000000000000000000..50dd15a0923da5aa1be211eba23bb3561fe789f9 --- /dev/null +++ b/src/test/java/acceptance/robotFixture.java @@ -0,0 +1,74 @@ +package acceptance; + +import io.cucumber.java.After; +import io.cucumber.java.Before; +import io.cucumber.java.BeforeAll; +import io.cucumber.java.en.And; +import io.cucumber.java.en.Given; +import io.cucumber.java.en.Then; +import io.cucumber.java.en.When; +import io.github.bonigarcia.wdm.WebDriverManager; +import org.junit.jupiter.api.Assertions; +import org.openqa.selenium.By; +import org.openqa.selenium.JavascriptExecutor; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.firefox.FirefoxDriver; + +import java.time.Duration; +import java.util.HashMap; +import java.util.Map; + +public class robotFixture { + + private WebDriver driver; + private Map vars; + JavascriptExecutor js; + + @BeforeAll + public static void beforeAll() { + WebDriverManager.firefoxdriver().setup(); + } + + @Before + public void setUp() { + driver = new FirefoxDriver(); + js = (JavascriptExecutor) driver; + vars = new HashMap(); + driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(3)); + + } + @After + public void tearDown() { + driver.quit(); + } + + @Given("Le robot est en vol") + public void leRobotEstEnVol() { + + } + + + @When("Le robot atterrit sur la planète {int}") + public void leRobotAtterritSurLaPlanète(int arg0) { + driver.get("https://disc.univ-fcomte.fr/m2gl-webRobot/Accueil.php?seed="+arg0); + driver.findElement(By.id("newMap")).click(); + } + + + @Then("Les coordonnées du robot sont \\({int}, {int})") + public void lesCoordonnéesDuRobotSont(int x, int y) { + Assertions.assertEquals(""+x, driver.findElement(By.id("xRobot")).getText()); + Assertions.assertEquals(""+y, driver.findElement(By.id("yRobot")).getText()); + } + + @And("Il est orienté vers le {word}") + public void ilEstOrientéVers(String direction) { + Assertions.assertEquals("Orientation du robot : "+direction, driver.findElement(By.cssSelector("h3:nth-child(2)")).getText()); + } + + @And("Il lui reste {int} d’énergie") + public void ilLuiResteDÉnergie(int energy) { + Assertions.assertEquals(""+energy, driver.findElement(By.id("energy")).getText()); + + } +} diff --git a/src/test/resources/robot.feature b/src/test/resources/robot.feature new file mode 100644 index 0000000000000000000000000000000000000000..cee8aed0b38912ef55b7520930d1f436157453a4 --- /dev/null +++ b/src/test/resources/robot.feature @@ -0,0 +1,24 @@ +Feature: Robot description générale du robot. + l’état initial le robot est en vol, il atterrit sur une planète oriente nord + + Scenario: Atterrissage + Given Le robot est en vol + When Le robot atterrit sur la planète 112 + Then Les coordonnées du robot sont (96, 59) + And Il est orienté vers le Nord + And Il lui reste 20 d’énergie + + Scenario Outline: Consommation en fonction du terrain + Given Le robot est en vol + And Le robot atterrit sur la planète 6 + When Il fait l’action de + And Il fait rotation(s) à droite + And Il fait l’action de + Then Les coordonnées du robot sont (, ) + And Il est orienté vers le + And Il lui reste d’énergie + Examples: + | action1 | nb_rot | action2 | x-axis | y-axis | Orientation | energie | + | Avancer | 0 | Avancer | 64 | -19 | Nord | 14 | + | Avancer | 0 | Reculer | 64 | -17 | Nord | 13 | + | Avancer | 1 | Avancer | 65 | -18 | EST | 9 | \ No newline at end of file