generated from Arquisoft/wiq_0
-
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.
Merge pull request #172 from Arquisoft/integration-tests
Some scenarios with Cucumber
- Loading branch information
Showing
28 changed files
with
569 additions
and
39 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,6 @@ | |
|
||
@Getter | ||
@Setter | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@ToString | ||
public class AnswerDto { | ||
|
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 |
---|---|---|
|
@@ -10,7 +10,6 @@ | |
|
||
@Getter | ||
@Setter | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public class CategoryDto { | ||
|
||
|
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 |
---|---|---|
|
@@ -5,7 +5,6 @@ | |
|
||
@Getter | ||
@Setter | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@ToString | ||
public class PlayerDto { | ||
|
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
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
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
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
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
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
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
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
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
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
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
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
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
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,50 @@ | ||
package com.uniovi.steps; | ||
|
||
import com.uniovi.Wiq_IntegrationTests; | ||
import com.uniovi.util.SeleniumUtils; | ||
import io.cucumber.java.en.And; | ||
import io.cucumber.java.en.Then; | ||
import io.cucumber.java.en.When; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.openqa.selenium.WebElement; | ||
|
||
import java.util.List; | ||
|
||
public class APIStep extends Wiq_IntegrationTests { | ||
|
||
@And("I go to the API key page") | ||
public void iGoToTheAPIKeyPage() { | ||
List<WebElement> elems = SeleniumUtils.waitLoadElementsBy(driver, "free", "//*[@id=\"btnUser\"]", 5); | ||
elems.get(0).click(); | ||
elems = SeleniumUtils.waitLoadElementsBy(driver, "@href", "/home/apikey", 5); | ||
elems.get(0).click(); | ||
} | ||
|
||
@Then("I should see the API key button") | ||
public void iShouldSeeTheAPIKeyButton() { | ||
List<WebElement> elems = SeleniumUtils.waitLoadElementsBy(driver, "@href", "/home/apikey/create", 5); | ||
Assertions.assertTrue(elems.size() == 1); | ||
} | ||
|
||
@When("I press the API key button") | ||
public void iPressTheAPIKeyButton() { | ||
List<WebElement> elems = SeleniumUtils.waitLoadElementsBy(driver, "@href", "/home/apikey/create", 5); | ||
elems.get(0).click(); | ||
} | ||
|
||
@Then("I should see the API key") | ||
public void iShouldSeeTheAPIKey() { | ||
List<WebElement> elems = SeleniumUtils.waitLoadElementsBy(driver, "free", "//*[@id=\"apiKeyDiv\"]/form/div/div", 5); | ||
Assertions.assertTrue(elems.size() == 1); | ||
} | ||
|
||
@And("I reenter the API key page") | ||
public void iReenterTheAPIKeyPage() { | ||
this.iGoToTheAPIKeyPage(); | ||
} | ||
|
||
@Then("I should see the API key directly") | ||
public void iShouldSeeTheAPIKeyDirectly() { | ||
iShouldSeeTheAPIKey(); | ||
} | ||
} |
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,55 @@ | ||
package com.uniovi.steps; | ||
|
||
import com.uniovi.Wiq_IntegrationTests; | ||
import com.uniovi.services.InsertSampleDataService; | ||
import com.uniovi.util.PropertiesExtractor; | ||
import com.uniovi.util.SeleniumUtils; | ||
import io.cucumber.java.en.Then; | ||
import io.cucumber.java.en.When; | ||
import org.openqa.selenium.By; | ||
import org.openqa.selenium.WebElement; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
|
||
import java.util.List; | ||
|
||
public class GameStep extends Wiq_IntegrationTests { | ||
|
||
@Autowired | ||
private InsertSampleDataService dataService; | ||
private Logger log = LoggerFactory.getLogger(GameStep.class); | ||
|
||
@When("I press Play") | ||
public void iPressPlay() { | ||
dataService.generateTestQuestions(); | ||
List<WebElement> elems = SeleniumUtils.waitLoadElementsBy(driver, "free", "//*[@href=\"/game\"]", 5); | ||
elems.get(0).click(); | ||
} | ||
|
||
@Then("I should start playing") | ||
public void iShouldStartPlaying() throws InterruptedException { | ||
boolean playing = true; | ||
String xpath = "//*[contains(text(),'" + p.getString("game.finish", PropertiesExtractor.getSPANISH()) + "')]"; | ||
int i= 0; | ||
List<WebElement> finalMessage; | ||
while(playing){ | ||
//I obtain the buttons for the answers | ||
List<WebElement> elems = SeleniumUtils.waitLoadElementsBy(driver, "text", "Test answer 0", 10); | ||
log.info("Found " + elems.size() + " buttons"); | ||
log.info("Iteration " + i + " of the game"); | ||
//I click on the first button | ||
elems.get(0).click(); | ||
|
||
try{ | ||
finalMessage= SeleniumUtils.waitLoadElementsByXpath(driver, xpath, 10); | ||
}catch(Exception e){ | ||
continue; | ||
} | ||
if(finalMessage.size()>0){ | ||
playing = false; | ||
} | ||
i++; | ||
} | ||
} | ||
} |
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,46 @@ | ||
package com.uniovi.steps; | ||
|
||
import com.uniovi.Wiq_IntegrationTests; | ||
import com.uniovi.util.SeleniumUtils; | ||
import io.cucumber.java.en.And; | ||
import io.cucumber.java.en.Given; | ||
import io.cucumber.java.en.Then; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.openqa.selenium.By; | ||
import org.openqa.selenium.WebElement; | ||
|
||
import java.util.List; | ||
|
||
public class LogInStep extends Wiq_IntegrationTests { | ||
@And("I press the login button") | ||
public void iPressTheLoginButton() { | ||
By button = By.className("btn"); | ||
driver.findElement(button).click(); | ||
} | ||
|
||
@And("I fill in the form with valid data email: {string} password: {string}") | ||
public void iFillInTheFormWithValidDataEmailPassword(String username, String pass) { | ||
WebElement mail = driver.findElement(By.name("username")); | ||
mail.click(); | ||
mail.clear(); | ||
mail.sendKeys(username); | ||
WebElement password = driver.findElement(By.name("password")); | ||
password.click(); | ||
password.clear(); | ||
password.sendKeys(pass); | ||
} | ||
|
||
@And("I access the personal ranking page") | ||
public void iAccessThePersonalRankingPage() { | ||
List<WebElement> elems = SeleniumUtils.waitLoadElementsBy(driver, "free", "//*[@id=\"navbarDropdown2\"]", 5); | ||
elems.get(0).click(); | ||
elems = SeleniumUtils.waitLoadElementsBy(driver, "free", "//*[@href=\"/ranking/playerRanking\"]", 5); | ||
elems.get(0).click(); | ||
} | ||
|
||
@Then("I should see the personal ranking page") | ||
public void iShouldSeeThePersonalRankingPage() { | ||
List<WebElement> elems = SeleniumUtils.waitLoadElementsBy(driver, "@id", "playerRankingTable", 5); | ||
Assertions.assertFalse(elems.isEmpty()); | ||
} | ||
} |
Oops, something went wrong.