diff --git a/src/test/java/com/uniovi/steps/GameStep.java b/src/test/java/com/uniovi/steps/GameStep.java index 6b8eb0f7..ba479c8f 100644 --- a/src/test/java/com/uniovi/steps/GameStep.java +++ b/src/test/java/com/uniovi/steps/GameStep.java @@ -5,6 +5,7 @@ import com.uniovi.services.QuestionGeneratorService; import com.uniovi.util.PropertiesExtractor; 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.openqa.selenium.By; @@ -32,13 +33,13 @@ public void iPressPlay() throws IOException, InterruptedException { elems.get(0).click(); } - @Then("I should start playing") - public void iShouldStartPlaying() { + @Then("I should start playing until I see message {string}") + public void iShouldStartPlaying(String messageKey) { boolean playing = true; - String xpath = "//*[contains(text(),'" + p.getString("game.finish", PropertiesExtractor.getSPANISH()) + "')]"; + String xpath = "//*[contains(text(),'" + p.getString(messageKey, PropertiesExtractor.getSPANISH()) + "')]"; int i= 0; List finalMessage; - while(playing){ + while(playing) { //I obtain the buttons for the answers List elems = By.cssSelector(".container .row button").findElements(driver); log.info("Found " + elems.size() + " buttons"); @@ -46,15 +47,35 @@ public void iShouldStartPlaying() { //I click on the first button elems.get(0).click(); - try{ - finalMessage= SeleniumUtils.waitLoadElementsByXpath(driver, xpath, 10); - }catch(Exception e){ + try { + finalMessage = SeleniumUtils.waitLoadElementsByXpath(driver, xpath, 10); + } catch(Exception e) { continue; } - if(finalMessage.size()>0){ + + if(!finalMessage.isEmpty()) { playing = false; } i++; } } + + @When("I press Play With Friends") + public void iPressPlayWithFriends() throws IOException, InterruptedException { + questionGeneratorService.generateTestQuestions(); + List elems = SeleniumUtils.waitLoadElementsBy(driver, "id", "multiplayerBtn", 5); + elems.get(0).click(); + } + + @And("I create a code") + public void iCreateACode() { + List elems = SeleniumUtils.waitLoadElementsBy(driver, "id", "createBtn", 5); + elems.get(0).click(); + } + + @And("I press start") + public void iPressStart() { + List elems = SeleniumUtils.waitLoadElementsBy(driver, "id", "startBtn", 5); + elems.get(0).click(); + } } diff --git a/src/test/resources/features/Game.feature b/src/test/resources/features/Game.feature index b3120c41..5b6b0837 100644 --- a/src/test/resources/features/Game.feature +++ b/src/test/resources/features/Game.feature @@ -6,4 +6,4 @@ Feature: I try to play a normal game And I press the register button And I go to the home page When I press Play - Then I should start playing \ No newline at end of file + Then I should start playing until I see message "game.finish" \ No newline at end of file diff --git a/src/test/resources/features/MultiplayerGame.feature b/src/test/resources/features/MultiplayerGame.feature new file mode 100644 index 00000000..0ec53959 --- /dev/null +++ b/src/test/resources/features/MultiplayerGame.feature @@ -0,0 +1,11 @@ +Feature: I play a multiplayer game + Scenario: I start a multiplayer game alone + Given I am not registered or logged in + And I am on the register page + When I fill in the form with valid data username: "userGame" email: "userGame@gmail.com" password: "password" password_confirmation: "password" + And I press the register button + And I go to the home page + When I press Play With Friends + And I create a code + And I press start + Then I should start playing until I see message "multi.finished" \ No newline at end of file