diff --git a/SeleniumTests/src/main/java/re/turnie/seleniumtests/steps/LoginStepDefinitions.java b/SeleniumTests/src/main/java/re/turnie/seleniumtests/steps/LoginStepDefinitions.java new file mode 100644 index 0000000..afe0fb7 --- /dev/null +++ b/SeleniumTests/src/main/java/re/turnie/seleniumtests/steps/LoginStepDefinitions.java @@ -0,0 +1,91 @@ +package re.turnie.seleniumtests.steps; + +import cucumber.annotation.en.Given; +import cucumber.annotation.en.Then; +import cucumber.annotation.en.When; +import org.openqa.selenium.By; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.ui.ExpectedConditions; +import org.openqa.selenium.support.ui.WebDriverWait; +import re.turnie.seleniumtests.CucumberStepDefinition; +import re.turnie.seleniumtests.SystemConstants; + +import java.util.List; + +public class LoginStepDefinitions extends CucumberStepDefinition { + + @Given("^User navigates to Login Page$") + public void goToLogin() { + checkDriverAvailability(); + + driver.navigate().to(SystemConstants.FRONTEND_URL + "/login"); + } + + @Given("^a user is registered as \"(.*)\" with email \"(.*)\" and password \"(.*)\"$") + public void assureRegistrationOfUser(String username, String email, String password) { + checkDriverAvailability(); + + + } + + @When("^I enter email \"(.*)\"$") + public void enterEmail(String email) { + checkDriverAvailability(); + + driver.findElement(By.id("email-input")).sendKeys(email); + } + + @When("^I enter password \"(.*)\"$") + public void enterPassword(String password) { + checkDriverAvailability(); + + driver.findElement(By.id("password-input")).sendKeys(password); + } + + @When("^I click on login$") + public void clickOnLogin() { + checkDriverAvailability(); + + driver.findElement(By.id("login-button")).click(); + } + + @Then("^Login should show error messages$") + public void checkErrorMessagesShowing() { + checkDriverAvailability(); + + WebElement errorlist = new WebDriverWait(driver, 1) + .until(ExpectedConditions.presenceOfElementLocated(By.id("error-list"))); + List errortags = errorlist.findElements(By.tagName("li")); + if(errortags.isEmpty()) { + System.out.println("Test Failed"); + } else { + System.out.println("Test Passed"); + } + } + + @Then("^the user \"(.*)\" should be logged in$") + public void checkForUserBeingLoggedIn(String username) { + checkDriverAvailability(); + + WebElement usernameButton = new WebDriverWait(driver, 1) + .until(ExpectedConditions.presenceOfElementLocated(By.id("profile-button"))); + + if(usernameButton != null && usernameButton.getText().equals(username)) { + System.out.println("Test Passed"); + } else { + System.out.println("Test Failed"); + } + } + + @Then("^the user should be redirected to index$") + public void checkForRedirectionToIndex() { + checkDriverAvailability(); + + String currentURL = driver.getCurrentUrl(); + if(currentURL.equalsIgnoreCase(SystemConstants.FRONTEND_URL + "/")) { + System.out.println("Test Passed"); + } else { + System.out.println("Test Failed"); + } + } +} diff --git a/SeleniumTests/src/main/resources/login.feature b/SeleniumTests/src/main/resources/login.feature new file mode 100644 index 0000000..eedb818 --- /dev/null +++ b/SeleniumTests/src/main/resources/login.feature @@ -0,0 +1,24 @@ + + Feature: Login + Background: User is on login page + Given User navigates to Login Page + + Scenario: Logging in with wrong credentials will give error + When I enter email "unregistereduser@gmail.com" + And I enter password "asdf1234" + And I click on login + Then Login should show error messages + + Scenario: User with correct credentials will be logged in + Given a user is registered as "GherkinTestUser" with email "gherkintestuser@gmail.com" and password "asdf1234" + When I enter email "gherkintestuser@gmail.com" + And I enter password "asdf1234" + And I click on login + Then the user "GherkinTestUser" should be logged in + + Scenario: User with correct credentials will be redirected to index after login + Given a user is registered as "GherkinTestUser" with email "gherkintestuser@gmail.com" and password "asdf1234" + When I enter email "gherkintestuser@gmail.com" + And I enter password "asdf1234" + And I click on login + Then the user should be redirected to index diff --git a/js/components/Login.js b/js/components/Login.js index e2b5026..c1fb159 100644 --- a/js/components/Login.js +++ b/js/components/Login.js @@ -28,7 +28,7 @@ class LoginErrorList extends React.Component { render() { const {error, errorMessages} = this.props; if (error) { - return (