Skip to content

Commit

Permalink
all complete
Browse files Browse the repository at this point in the history
  • Loading branch information
Latif Hajiry committed Sep 4, 2024
1 parent 704b1ad commit 8af36a2
Show file tree
Hide file tree
Showing 9 changed files with 135 additions and 45 deletions.
12 changes: 10 additions & 2 deletions src/test/java/moneylion/helpers/PageHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

import java.lang.reflect.Field;
import java.time.Duration;

import static java.util.concurrent.TimeUnit.SECONDS;
Expand Down Expand Up @@ -36,6 +37,13 @@ public WebElement waitExplicitForElement(By locator, String expectedCondition, l
return element;
}

public WebElement waitExplicitForElementWithText(String text, long time) {
WebElement element;
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(time));
element = wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[contains(text(), '" + text + "')]")));
return element;
}

public boolean urlToContains (String url, long time) {
boolean isUrlOk;
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(time));
Expand Down Expand Up @@ -64,8 +72,8 @@ public boolean isElementANextoElementB(By selectorA, By selectorB, long time) {
boolean bottomBoundary = locationA.getY() <= (locationB.getY() + sizeB.getHeight());

// boolean isYWithin = locationA.getX() >= locationB.getX() && locationA.getX() <= (locationB.getX() + sizeB.getHeight());
System.out.println(locationA.getY());
System.out.println(locationB.getY());
// System.out.println(locationA.getY());
// System.out.println(locationB.getY());

boolean isYwithin = topBoundary && bottomBoundary;
return isYwithin;
Expand Down
10 changes: 10 additions & 0 deletions src/test/java/moneylion/pages/BasePage.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package moneylion.pages;

import moneylion.utils.WebDriverManager;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;

import java.lang.reflect.Field;

public class BasePage {
protected WebDriver driver;

Expand All @@ -13,4 +16,11 @@ public BasePage() {
public WebDriver getDriver() {
return driver;
}

public static By getLocatorByName(String fieldName, Object pageObject) throws NoSuchFieldException, IllegalAccessException {
Field field = pageObject.getClass().getDeclaredField(fieldName);
field.setAccessible(true);
return (By) field.get(pageObject);
}

}
28 changes: 12 additions & 16 deletions src/test/java/moneylion/pages/CareerPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import moneylion.helpers.PageHelper;
import org.junit.jupiter.api.Assertions;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;

public class CareerPage extends BasePage {
private PageHelper pageHelper;
Expand All @@ -11,34 +12,29 @@ public CareerPage() {
pageHelper = new PageHelper();
}

private By whereWeWorkContainer = By.xpath("//h2[contains(text(), 'Where we work')]//..");
private By whereWeWorkText = By.xpath("//h2[contains(text(), 'Where we work')]");
private By whereWeWorkContainerSibling = By.xpath("//h2[contains(text(), 'Where we work')]/ancestor::div[3]/following-sibling::div/descendant::figcaption[contains(text(), 'Around the globe')]");
private By viewOpenRolesButton = By.xpath("//a[contains(@href, '#OpenRoles')]");
private By cityGridContainer = By.xpath("//figcaption[contains(text(), 'New York City')]/ancestor::div[contains(@class, 'where-we-work-cities')]");
public By whereWeWorkContainer = By.xpath("//h2[contains(text(), 'Where we work')]//..");
public By whereWeWorkText = By.xpath("//h2[contains(text(), 'Where we work')]");
public By whereWeWorkSiblingElement = By.xpath("//h2[contains(text(), 'Where we work')]/../../../following-sibling::div/div[contains(@class, 'where-we-work-cities')]");
public By viewOpenRolesButton = By.xpath("//a[contains(@href, '#OpenRoles')]");
public By cityGridContainer = By.xpath("//figcaption[contains(text(), 'New York City')]/ancestor::div[contains(@class, 'where-we-work-cities')]");
public By cityGridContainerSiblingElement = By.xpath("//div[contains(@class, 'where-we-work-cities')]/../preceding-sibling::div/descendant::h2[contains(text(), 'Where we work')]");

public boolean checkCareerPageUrl() {
public boolean verifyCareerPageUrl() {
boolean isUrlOk;
isUrlOk = pageHelper.urlToContains("moneylion.com/careers", 10);

return isUrlOk;
}

public boolean isOpenRolesButtonDisplayed() {
public boolean careerPageElementDisplayed(By locator) {
boolean isElementDisplayed;
isElementDisplayed = pageHelper.isDisplayed(viewOpenRolesButton, 10);
isElementDisplayed = pageHelper.isDisplayed(locator, 10);
return isElementDisplayed;
}

public boolean isWhereWeWorkSiblingDisplayed() {
boolean isElementDisplayed;
isElementDisplayed = pageHelper.isDisplayed(whereWeWorkContainerSibling, 10);
return isElementDisplayed;
}

public boolean isNextToElement() {
public boolean isNextToElement(By element1, By element2) {
boolean isNextToElement;
isNextToElement = pageHelper.isElementANextoElementB(whereWeWorkText, cityGridContainer, 10);
isNextToElement = pageHelper.isElementANextoElementB(element1, element2, 10);
return isNextToElement;
}

Expand Down
17 changes: 16 additions & 1 deletion src/test/java/moneylion/pages/HomePage.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,26 @@ public HomePage() {
super();
pageHelper = new PageHelper();
}
private By careerTextLink = By.xpath("//a[contains(@href, '/careers')]");
public By careerTextLink = By.xpath("//a[contains(@href, '/careers')]");

public void waitAndClickCareerPage() {
WebElement element = pageHelper.waitExplicitForElement(careerTextLink, "elementtobeclickable", 10);
Actions actions = new Actions(driver);
actions.moveToElement(element).click().perform();
}

public WebElement findHomePageElementWithText(String text, long timeout) {
WebElement element = pageHelper.waitExplicitForElementWithText(text, timeout);
return element;
}

public void hoverToHomePageElement(WebElement element) {
Actions actions = new Actions(driver);
actions.moveToElement(element).perform();
}

public void clickHomePageElement(WebElement element) {
Actions actions = new Actions(driver);
actions.click(element).perform();
}
}
37 changes: 37 additions & 0 deletions src/test/java/moneylion/steps_definition/CareerPageSteps.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,44 @@
package moneylion.steps_definition;

import io.cucumber.java.en.And;
import io.cucumber.java.en.Then;
import moneylion.pages.BasePage;
import moneylion.pages.CareerPage;
import moneylion.pages.HomePage;
import moneylion.utils.ConfigManager;
import moneylion.utils.PageObjectManager;
import org.junit.jupiter.api.Assertions;
import org.openqa.selenium.By;

public class CareerPageSteps extends BasePage {
private PageObjectManager pageObjectManager;
private CareerPage careerPage;

public CareerPageSteps() {
pageObjectManager = new PageObjectManager();
careerPage = pageObjectManager.careerPage();
}

@Then("I should redirected to MoneyLion's careers page")
public void iShouldRedirectedToCareerPage() {
careerPage.verifyCareerPageUrl();
}

@And("^I should be able to see '([^\']*)' displayed next to '([^\']*)'$")
public void iShouldBeAbleToSeeElementDisplayedNextToElement(String element1, String element2) throws NoSuchFieldException, IllegalAccessException {
By firstElement = getLocatorByName(element1, careerPage);
By secondElement = getLocatorByName(element2, careerPage);

Assertions.assertTrue(careerPage.careerPageElementDisplayed(firstElement), element1 + "i s not displayed"); ;
Assertions.assertTrue(careerPage.careerPageElementDisplayed(secondElement), element2 + "i s not displayed"); ;
}

@And("^I should be able to see '([^\']*)' displayed next to '([^\']*)' according to coordinate$")
public void iShouldBeAbleToSeeElementDisplayedNextToElementUsingCoordinate(String element1, String element2) throws NoSuchFieldException, IllegalAccessException {
By firstElement = getLocatorByName(element1, careerPage);
By secondElement = getLocatorByName(element2, careerPage);

boolean isSibling = careerPage.isNextToElement(firstElement, secondElement);
Assertions.assertTrue(isSibling, element1 + "is not a sibling of element" + element2);
}
}
40 changes: 24 additions & 16 deletions src/test/java/moneylion/steps_definition/HomePageSteps.java
Original file line number Diff line number Diff line change
@@ -1,35 +1,43 @@
package moneylion.steps_definition;

import io.cucumber.java.en.And;
import io.cucumber.java.en.Given;
import io.cucumber.java.en.When;
import moneylion.pages.BasePage;
import moneylion.pages.CareerPage;
import moneylion.pages.HomePage;
import moneylion.utils.ConfigManager;
import moneylion.utils.PageObjectManager;
import org.junit.jupiter.api.Assertions;
import org.openqa.selenium.WebElement;

import static java.lang.Thread.sleep;

public class HomePageSteps extends BasePage {
private HomePage homePage = new HomePage();
private CareerPage careerPage = new CareerPage();
@Given("I visit url")
public void iVisitUrl() {
driver.get(ConfigManager.getProperty("url"));
}
private PageObjectManager pageObjectManager;
private HomePage homePage;

@When("I click a button")
public void iClickAButton() throws InterruptedException {
homePage.waitAndClickCareerPage();
// Thread.sleep(10000);
boolean isUrlOk = careerPage.checkCareerPageUrl();
Assertions.assertTrue(isUrlOk, "the url does not match");
public HomePageSteps() {
pageObjectManager = new PageObjectManager();
homePage = pageObjectManager.homePage();
}

boolean viewRolesButtonDisplayed = careerPage.isOpenRolesButtonDisplayed();
Assertions.assertTrue(viewRolesButtonDisplayed, "view open roles button is not displayed");
@Given("I am a new customer")
public void iAmANewCustomer() {
System.out.println("I am a new customer executed");
}
@And("I access the MoneyLion website")
public void iAccessWebsite() {
driver.get(ConfigManager.getProperty("url"));
}

boolean isNextToElement = careerPage.isNextToElement();
Assertions.assertTrue(isNextToElement, "The coordinate of elementA is not within elementB");
@When("^I hover on '([^\']*)' and click on '([^\']*)' at the bottom of the webpage$")
public void iHoverAndClickOnButtonAtTheBottomOfTheWebPage(String element1, String element2) {
WebElement elementToHover = homePage.findHomePageElementWithText(element1, 10);
homePage.hoverToHomePageElement(elementToHover);

WebElement elementToClick = homePage.findHomePageElementWithText(element2,10);
// homePage.hoverToHomePageElement(elementToClick);
homePage.clickHomePageElement(elementToClick);
}
}
13 changes: 12 additions & 1 deletion src/test/java/moneylion/utils/Hooks.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

import io.cucumber.java.After;
import io.cucumber.java.Before;
import io.cucumber.java.Scenario;
import moneylion.pages.BasePage;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;


Expand All @@ -14,7 +17,15 @@ public void setUp() {
WebDriver driver = WebDriverManager.getDriver();
}

@After
@After(order = 1)
public void takeScreenshot(Scenario scenario) {
System.out.println("taking screenshots");
final byte[] screenshot = ((TakesScreenshot) driver).getScreenshotAs(OutputType.BYTES);
scenario.attach(screenshot, "image/png", "Screenshot");
System.out.println("Screenshot taken for scenario: " + scenario.getName());
}

@After(order = 0)
public void tearDown() {
System.out.println("terminating driver");
WebDriverManager.quitDriver();
Expand Down
6 changes: 6 additions & 0 deletions src/test/java/moneylion/utils/PageObjectManager.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
package moneylion.utils;

import moneylion.pages.CareerPage;
import moneylion.pages.HomePage;

public class PageObjectManager {

public HomePage homePage() {return new HomePage();}
public CareerPage careerPage() {return new CareerPage();}
}
17 changes: 8 additions & 9 deletions src/test/resources/features/test.feature
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
Feature:Test
Feature: Moneylion Test

@test
Scenario: Test Feature
Given I visit url
When I click a button

@test2
Scenario: Test Feature2
Given I visit url
When I click a button
Scenario: Verify when accessing career page
Given I am a new customer
When I access the MoneyLion website
And I hover on 'About us' and click on 'Careers' at the bottom of the webpage
Then I should redirected to MoneyLion's careers page
And I should be able to see 'whereWeWorkSiblingElement' displayed next to 'cityGridContainerSiblingElement'
And I should be able to see 'whereWeWorkText' displayed next to 'cityGridContainer' according to coordinate

0 comments on commit 8af36a2

Please sign in to comment.