forked from Fluffy777/universe
-
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.
- Loading branch information
Erlkonig
committed
Apr 17, 2023
1 parent
d832ecc
commit 723483f
Showing
4 changed files
with
523 additions
and
66 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
96 changes: 50 additions & 46 deletions
96
src/test/java/com/fluffy/universe/e2esteps/e2eStepdefs.java
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 |
---|---|---|
@@ -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 | ||
|
||
} | ||
} | ||
} |
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
Oops, something went wrong.