Skip to content

Commit

Permalink
Added Faker API
Browse files Browse the repository at this point in the history
  • Loading branch information
qaPaloma committed Feb 15, 2024
1 parent 34ecbe6 commit c518375
Show file tree
Hide file tree
Showing 11 changed files with 125 additions and 104 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/smoke_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
sudo Xvfb -ac :99 -screen 0 1280x1024x24 > /dev/null 2>&1 & # optional
- name: Run tests
run: mvn test -Dtest=RunCucumberTest -Dbrowser=chrome-headless -Dcucumber.filter.tags="@login-success"
run: mvn test -Dtest=RunCucumberTest -Dbrowser=chrome-headless -Dcucumber.filter.tags="@signup-success"

- name: Generate reports
if: always()
Expand Down
8 changes: 8 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,14 @@
<artifactId>cluecumber-report-plugin</artifactId>
<version>${trivago.version}</version>
</dependency>

<!-- FAKER API -->
<dependency>
<groupId>com.github.javafaker</groupId>
<artifactId>javafaker</artifactId>
<version>1.0.2</version>
</dependency>

</dependencies>

<build>
Expand Down
27 changes: 11 additions & 16 deletions src/test/java/pages/CreateAccountPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@
import org.openqa.selenium.support.ui.Select;
import runner.RunBase;
import static support.Commands.*;
import static support.UserDataUtils.*;
import static pages.LoginSignupPage.*;
import static support.FakeDataAPI.*;

public class CreateAccountPage extends RunBase {

//region constants
public static final String URL = "https://automationexercise.com/login";
private final By TITLE_MR_FIELD = By.id("id_gender1");
private final By TITLE_MRS_FIELD = By.id("id_gender2");
private static final By PASSWORD_FIELD = By.id("password");
Expand All @@ -24,7 +23,6 @@ public class CreateAccountPage extends RunBase {
private final By LAST_NAME_FIELD = By.id("last_name");
private final By COMPANY_FIELD = By.id("company");
private final By ADDRESS1_FIELD = By.id("address1");
private final By ADDRESS2_FIELD = By.id("address2");
private final By COUNTRY_FIELD = By.id("country");
private final By STATE_FIELD = By.id("state");
private final By CITY_FIELD = By.id("city");
Expand All @@ -35,14 +33,17 @@ public class CreateAccountPage extends RunBase {
private final By NAME_ACTUAL = By.id("name");
private final String EMAIL_EXPECTED = storeEmail();
private final By EMAIL_ACTUAL = By.id("email");
public static final String GET_PASSWORD = getRandomPassword();
public static final String GET_PASSWORD = getPassword();
//endregion

public void pageCheck() {
checkElementIsDisplayed(CREATE_ACCOUNT_BUTTON);
}

public void checkUserName() {
System.out.println("##########################");
System.out.println("WILL VERIFY IF THE NAME IS CORRECT");
System.out.println(NAME_EXPECTED);
checkElementIsCorrect(NAME_ACTUAL, NAME_EXPECTED);
}

Expand Down Expand Up @@ -98,15 +99,11 @@ public void addLastName() {
}

public void addCompanyName() {
fillField(COMPANY_FIELD, "Test Company INC.");
fillField(COMPANY_FIELD, getCompanyName());
}

public void addAddress1() {
fillField(ADDRESS1_FIELD, "Test St. 980 NY");
}

public void addAddress2() {
fillField(ADDRESS2_FIELD, "Test neighborhood");
fillField(ADDRESS1_FIELD, getAddress());
}

public void addCountry() {
Expand All @@ -116,22 +113,21 @@ public void addCountry() {
}

public void addState() {
fillField(STATE_FIELD, "Test State");
fillField(STATE_FIELD, getState());
}

public void addCity() {
fillField(CITY_FIELD, "Testown");
fillField(CITY_FIELD, getCity());
}

public void addZipcode() {
fillField(ZIPCODE_FIELD, getRandomNumber(5));
fillField(ZIPCODE_FIELD, getZipCode());
}

public void addMobileNumber() {
fillField(MOBILE_NUMBER_FIELD, getRandomNumber(10));
fillField(MOBILE_NUMBER_FIELD, getPhoneNumber());
}


public void clickCreateButton() {
clickButton(CREATE_ACCOUNT_BUTTON);
}
Expand All @@ -148,7 +144,6 @@ public void addUserData() {
addLastName();
addCompanyName();
addAddress1();
addAddress2();
addCountry();
addState();
addCity();
Expand Down
19 changes: 12 additions & 7 deletions src/test/java/pages/HomePage.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,16 @@ public class HomePage extends RunBase {

//region constants
public static final String URL = "https://automationexercise.com/";
private static final By HOME_PAGE_BUTTON = By.xpath("//*[@id=\"header\"]/div/div/div/div[2]/div/ul/li[1]/a");
private static final By LOGIN_SIGNUP_BUTTON = By.xpath("//*[@id=\"header\"]/div/div/div/div[2]/div/ul/li[4]/a");
private static final String HOME_PAGE_TEXT_EXPECTED = "FEATURES ITEMS";
private static final By HOME_PAGE_TEXT_ACTUAL = By.xpath("/html/body/section[2]/div/div/div[2]/div[1]/h2");
public final By LOGOUT_BUTTON = By.xpath("//*[@id=\"header\"]/div/div/div/div[2]/div/ul/li[4]/a");
public static final By LOGOUT_BUTTON = By.xpath("//*[@id=\"header\"]/div/div/div/div[2]/div/ul/li[4]/a");
private static final By NAME_ACTUAL = By.xpath("//*[@id=\"header\"]/div/div/div/div[2]/div/ul/li[10]/a/b");
private static final String NAME_EXPECTED = storeFullName();
private static final By IFRAME = By.cssSelector("#aswift_1");
private static final By IFRAME_DISMISS = By.cssSelector("#dismiss-button");
private static final String ACCOUNT_CREATED_TEXT_EXPECTED = "ACCOUNT CREATED!";
private static final By ACCOUNT_CREATED_TEXT_ACTUAL = By.xpath("//*[@id=\"form\"]/div/div/div/h2/b");
private final By USER_IS_LOGGED = By.xpath("//*[@id=\"header\"]/div/div/div/div[2]/div/ul/li[10]/a");
private static final By CONTINUE_BUTTON = By.xpath("//*[@id=\"form\"]/div/div/div/div/a");
//endregion

public static void openPage() {
Expand All @@ -36,15 +34,22 @@ public static void clickSignupLoginButton() {
clickButton(LOGIN_SIGNUP_BUTTON);
}

public void clickLogoutButton() {
public static void clickLogoutButton() {
clickButton(LOGOUT_BUTTON);
}


public static void accountCreatedConfirmation() {
System.out.println("##########################");
System.out.println("WILL VERIFY THE SIGNUP");
checkElementIsCorrect(ACCOUNT_CREATED_TEXT_ACTUAL, ACCOUNT_CREATED_TEXT_EXPECTED);
clickButton(CONTINUE_BUTTON);
dismissIFrame(IFRAME, IFRAME_DISMISS);
//clickButton(CONTINUE_BUTTON);
//dismissIFrame(IFRAME, IFRAME_DISMISS);
clickButton(HOME_PAGE_BUTTON);
checkElementIsCorrect(NAME_ACTUAL, NAME_EXPECTED);
clickLogoutButton();
clickSignupLoginButton();
checkNewUserLogin();
checkElementIsCorrect(NAME_ACTUAL, NAME_EXPECTED);
}

Expand Down
24 changes: 16 additions & 8 deletions src/test/java/pages/LoginSignupPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,26 @@
import org.openqa.selenium.By;
import runner.RunBase;
import static support.Commands.*;
import static support.UserDataUtils.*;
import static support.FakeDataAPI.*;
import static pages.CreateAccountPage.*;

public class LoginSignupPage extends RunBase {

//region constants
public static final String URL = "https://automationexercise.com/login";
private final By LOGIN_EMAIL_FIELD = By.xpath("//*[@id=\"form\"]/div/div/div[1]/div/form/input[2]");
private final By PASSWORD_FIELD = By.xpath("//*[@id=\"form\"]/div/div/div[1]/div/form/input[3]");
private static final By LOGIN_EMAIL_FIELD = By.xpath("//*[@id=\"form\"]/div/div/div[1]/div/form/input[2]");
private static final By PASSWORD_FIELD = By.xpath("//*[@id=\"form\"]/div/div/div[1]/div/form/input[3]");
private static final By LOGIN_BUTTON = By.xpath("//*[@id=\"form\"]/div/div/div[1]/div/form/button");
private final By ERROR_MESSAGE = By.xpath("//*[@id=\"form\"]/div/div/div[1]/div/form/p");
private static final By NAME_FIELD = By.xpath("//*[@id=\"form\"]/div/div/div[3]/div/form/input[2]");
private static final By SIGNUP_EMAIL_FIELD = By.xpath("//*[@id=\"form\"]/div/div/div[3]/div/form/input[3]");
private static final By SIGNUP_BUTTON = By.xpath("//*[@id=\"form\"]/div/div/div[3]/div/form/button");
private static final By ERROR_ACTUAL = By.xpath("//*[@id=\"form\"]/div/div/div[3]/div/form/p");
private static final String ERROR_EXPECTED = "Email Address already exist!";
public static final String GET_FIRST_NAME = getRandomName.firstName();
public static final String GET_LAST_NAME = getRandomName.lastName();
public static final String GET_EMAIL = getRandomEmail();
public final String GET_PASSWORD = storePassword();
public static final String GET_FIRST_NAME = getFirstName();
public static final String GET_LAST_NAME = getLastName();
public static final String GET_EMAIL = getEmail();
public static final String GET_NEW_USER_PASSWORD = storePassword();
//endregion

public static void pageCheck() {
Expand Down Expand Up @@ -66,10 +66,11 @@ public static String storeLastName() {
}

public static String storeFullName() {
return storeFirstName() + storeLastName();
return storeFirstName() + " " + storeLastName();
}

public static void addName() {
System.out.println("THE NAME ADDED WAS: " + storeFullName());
fillField(NAME_FIELD, storeFullName());
}

Expand All @@ -78,6 +79,7 @@ public static String storeEmail() {
}

public static void addSignupEmail() {
System.out.println("THE EMAIL ADDED WAS: " + storeEmail());
fillField(SIGNUP_EMAIL_FIELD, storeEmail());
}

Expand All @@ -93,4 +95,10 @@ public void errorMessageSignup() {
checkElementIsCorrect(ERROR_ACTUAL, ERROR_EXPECTED);
}

public static void checkNewUserLogin (){
fillField(LOGIN_EMAIL_FIELD, storeEmail());
fillField(PASSWORD_FIELD, GET_NEW_USER_PASSWORD);
clickButton(LOGIN_BUTTON);
}

}
2 changes: 1 addition & 1 deletion src/test/java/runner/RunCucumberTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
@CucumberOptions(
plugin = {"html:target/formated-report/report.html", "json:target/formated-report/report.json"},
features = "src/test/resources/features",
//tags = "@login",
//tags = "@signup-success",
glue = {"steps"}
)

Expand Down
3 changes: 1 addition & 2 deletions src/test/java/steps/LogoutSteps.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

public class LogoutSteps extends RunCucumberTest {
LoginSignupPage loginSignupPage = new LoginSignupPage();
HomePage homePage = new HomePage();

@Given("the user is logged in to the website")
public void userLogged(){
Expand All @@ -21,7 +20,7 @@ public void userLogged(){

@When ("the user clicks on the Logout button")
public void logoutButton(){
homePage.clickLogoutButton();
HomePage.clickLogoutButton();
}

@Then("the user successfully logout from their account")
Expand Down
2 changes: 0 additions & 2 deletions src/test/java/steps/SignupSteps.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ public void signupData() {
LoginSignupPage.addSignupEmail();
}


@And("clicks the signup button")
public void signupButton() {
LoginSignupPage.clickSignupButton();
Expand All @@ -43,7 +42,6 @@ public void createAccountButton() {
createAccountPage.clickCreateButton();
}


@Then("the user sees a signup confirmation message")
public void confirmationMessage() {
HomePage.accountCreatedConfirmation();
Expand Down
25 changes: 18 additions & 7 deletions src/test/java/support/Commands.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package support;

import org.apache.commons.lang3.RandomStringUtils;
import org.junit.Assert;
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 runner.RunCucumberTest;
import java.time.Duration;
import java.util.Random;

public class Commands extends RunCucumberTest {

Expand Down Expand Up @@ -42,6 +44,7 @@ public static void fillField(By element, String value) {
System.out.println("##########################");
System.out.println("Will fill a field with a value");
try {

waitElement(element);
getDriver().findElement(element).sendKeys(value);
} catch (Exception error) {
Expand All @@ -60,46 +63,54 @@ public static void enterWebPage(String URL) {
}

/*---------*/
public static String getRandomNumber(int numberOfDigits){
return RandomStringUtils.randomNumeric(numberOfDigits);
}

public static int getRandomNumber(int minValue, int maxValue){
Random random = new Random();

return random.nextInt(maxValue - minValue) + minValue;
}

public static void selectOption(By element1, By element2){
System.out.println("##########################");
System.out.println("Will select an option");
String option = String.valueOf(UserDataUtils.getRandomNumber(1, 2));
String option = String.valueOf(getRandomNumber(1, 2));
System.out.println("Selected option " + option);
switch (option) {
case "1":
clickButton(element1);
//String selected1 = element1.toString();
break;
case "2":
clickButton(element2);
//String selected2 = element2.toString();
break;
default:
System.out.println("**** Element not found");
}
}

/*---------*/
/*
public static void dismissIFrame(By element1, By element2){
System.out.println("##########################");
System.out.println("Will try to locate and dismiss add");
try {
waitElement(element1);
waitLonger(60);
getDriver().switchTo().frame(getDriver().findElement(element1));
waitElement(element2);
waitLonger(30);
getDriver().findElement(element2).click();
getDriver().switchTo().defaultContent();
} catch (Exception error) {
System.out.println("**** Add was not displayed");
}
}
*/

/*---------*/
public static void checkElementIsCorrect(By elementActual, String valueExpected) {
try {
waitElement(elementActual);
WebElement element = getDriver().findElement(elementActual);

if (element.getAttribute("value") != null) {
// Method 1: Element with a "value" attribute. Ex.: Filled forms
String valueActual = element.getAttribute("value");
Expand Down
Loading

0 comments on commit c518375

Please sign in to comment.