Skip to content

Commit

Permalink
fixed e2e test
Browse files Browse the repository at this point in the history
  • Loading branch information
Erlkonig committed Apr 17, 2023
1 parent d832ecc commit 723483f
Show file tree
Hide file tree
Showing 4 changed files with 523 additions and 66 deletions.
19 changes: 3 additions & 16 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,11 @@
<artifactId>cucumber-java8</artifactId>
<version>7.8.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-http-jdk-client</artifactId>
<version>4.8.1</version>
<artifactId>selenium-java</artifactId>
<version>4.8.3</version>
</dependency>
</dependencies>

Expand Down Expand Up @@ -229,18 +230,4 @@

</plugins>
</build>
<reporting>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<configuration>
<formats>
<format>html</format>
<format>xml</format>
</formats>
</configuration>
</plugin>
</plugins>
</reporting>
</project>
96 changes: 50 additions & 46 deletions src/test/java/com/fluffy/universe/e2esteps/e2eStepdefs.java
Original file line number Diff line number Diff line change
@@ -1,85 +1,89 @@
package com.fluffy.universe.e2esteps;

import io.cucumber.java8.En;
import org.openqa.selenium.WebDriver;
import io.cucumber.java8.En;import org.apache.commons.io.FileUtils;
import org.junit.jupiter.api.BeforeAll;import org.junit.jupiter.api.BeforeEach;
import org.openqa.selenium.*;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.firefox.FirefoxDriver;

import java.util.HashMap;
import org.openqa.selenium.firefox.FirefoxOptions;import org.openqa.selenium.firefox.FirefoxProfile;
import java.io.File;
import java.io.IOException;import java.util.HashMap;
import java.util.Map;

import static com.codeborne.selenide.Selectors.byName;
import static com.codeborne.selenide.Selectors.byXpath;
import static com.codeborne.selenide.Selenide.$;
import static com.codeborne.selenide.Selenide.open;

import static org.junit.jupiter.api.Assertions.assertEquals;
public class e2eStepdefs implements En {

WebDriver driver = new FirefoxDriver();
Map<String,String> inputs=new HashMap<>();

@io.cucumber.java.en.Given("^I navigate to the \"([^\"]*)\" page$")
public void iNavigateToThePage(String arg0) throws Throwable {
System.setProperty("webdriver.http.factory", "jdk-http-client");
WebDriver driver;
Map<String,String> inputs=new HashMap<>();
@BeforeAll
void prepareInputs(){
//System.setProperty("webdriver.gecko.driver","E:\\erlkonig\\geckodriver\\geckodriver.exe" );
ChromeOptions options = new ChromeOptions();
//options.setProfile(new ChromeProfile());
driver = new ChromeDriver(options);
inputs.put("Registration","http://127.0.0.1:7000/sign-up");
inputs.put("FirstName","sign-up__first-name");
inputs.put("LastName","sign-up__last-name");
inputs.put("email","sign-up__email");
inputs.put("password","sign-up__password");
inputs.put("confirm password","sign-up__confirm-password");
inputs.put("Firstname","first-name");
inputs.put("Lastname","last-name");
inputs.put("email","email");
inputs.put("password","password");
inputs.put("confirm password","confirm-password");
inputs.put("Register Now","/html/body/div[1]/main/div/form/div[6]/button");
inputs.put("Home","http://127.0.0.1:7000/");
open(inputs.get(arg0));
Thread.sleep(3000);
}

}
@BeforeEach @io.cucumber.java.en.Given("^I navigate to the \"([^\"]*)\" page$")
public void iNavigateToThePage(String arg0) throws Throwable {
prepareInputs();
System.setProperty("webdriver.http.factory", "jdk-http-client");
driver.get(inputs.get(arg0));
}
@io.cucumber.java.en.When("^I fill in \"([^\"]*)\" with \"([^\"]*)\"$")
public void iFillInWith(String arg0, String arg1) throws Throwable {
$(byName(inputs.get(arg0))).setValue(arg1);
WebElement field=driver.findElement(By.name(inputs.get(arg0)));
field.sendKeys(arg1);
}

@io.cucumber.java.en.And("^I click on the \"([^\"]*)\" button$")
public void iClickOnTheButton(String arg0) throws Throwable {
$(byXpath(inputs.get(arg0))).click();
WebElement button = driver.findElement(By.xpath(inputs.get(arg0)));
button.click();
}

@io.cucumber.java.en.Then("^I should be successfully registered$")
public void iShouldBeSuccessfullyRegistered() {
public void iShouldBeSuccessfullyRegistered() throws IOException {
File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(scrFile, new File("src\\test\\resources\\screenshots\\SuccessfullyRegistered.png"));
}

@io.cucumber.java.en.And("^I should land on the \"([^\"]*)\" page$")
public void iShouldLandOnThePage(String arg0) throws Throwable {
// Write code here that turns the phrase above into concrete actions

String currentPage=driver.getCurrentUrl();
assertEquals(currentPage,inputs.get(arg0));
}

@io.cucumber.java.en.And("^I should see \"([^\"]*)\" message as \"([^\"]*)\"$")
public void iShouldSeeMessageAs(String arg0, String arg1) throws Throwable {
// Write code here that turns the phrase above into concrete actions

WebElement alert=driver.findElement(By.xpath("/html/body/div[2]/div/div[1]/h2"));
assertEquals(arg0,alert.getText());
alert=driver.findElement(By.xpath("/html/body/div[2]/div/div[2]"));
assertEquals(arg1,alert.getText());
driver.findElement(By.xpath("/html/body/div[2]/div/div[3]/button")).click();
}

@io.cucumber.java.en.And("^I should see \"([^\"]*)\" and \"([^\"]*)\" links$")
public void iShouldSeeAndLinks(String arg0, String arg1) throws Throwable {
// Write code here that turns the phrase above into concrete actions

driver.findElement(By.xpath("/html/body/header/nav/ul/li[2]")).click();
File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(scrFile, new File("src\\test\\resources\\screenshots\\See"+arg0+"and"+arg1+".png")); WebElement link1=driver.findElement(By.xpath("/html/body/header/nav/ul/li[2]/div/ul/li[2]/a"));
WebElement link2=driver.findElement(By.xpath("/html/body/header/nav/ul/li[2]/div/ul/li[3]/form/button")); assertEquals(arg0,link1.getText());
assertEquals(arg1,link2.getText());
link2.click();
driver.close();
}

@io.cucumber.java.en.Then("^I should see \"([^\"]*)\" message for \"([^\"]*)\" field on \"([^\"]*)\" page$")
public void iShouldSeeMessageForFieldOnPage(String arg0, String arg1, String arg2) throws Throwable {
// Write code here that turns the phrase above into concrete actions

}

@io.cucumber.java.en.And("^I should see \"([^\"]*)\" buttton disbaled$")
public void iShouldSeeButttonDisbaled(String arg0) throws Throwable {
// Write code here that turns the phrase above into concrete actions

}

@io.cucumber.java.en.And("^I should not be able to submit the \"([^\"]*)\" form$")
public void iShouldNotBeAbleToSubmitTheForm(String arg0) throws Throwable {
// Write code here that turns the phrase above into concrete actions

}
}
}
5 changes: 2 additions & 3 deletions src/test/resources/features/Registration.feature
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,11 @@ Feature: Registration
And I click on the "Register Now" button
Then I should be successfully registered
And I should land on the "Home" page
And I should see "success" message as "Congrats! Your registration has been successful."
And I should see "Congratulations!" message as "You have successfully signed up. Welcome to our community!"
And I should see "Dashboard" and "Logout" links
Examples:
| first-name | last-name | email | password | confirm password |
| asdf.asdf | abcd.efgh | asdf.asdf@example.com | Asdf@1234 | Asdf@1234 |

| aassdf.asdff | abcd.efgh | aassdff.asdf@example.com | Asdf@1234 | Asdf@1234 |

@DisabledRegistration
Scenario Outline: Disabled Registration when one of the required fields is left blank
Expand Down
Loading

0 comments on commit 723483f

Please sign in to comment.