Skip to content

Instantly share code, notes, and snippets.

@borodicht
Created December 3, 2024 06:49
Show Gist options
  • Save borodicht/1dcfd632fac93005129bb82f8391c0a9 to your computer and use it in GitHub Desktop.
Save borodicht/1dcfd632fac93005129bb82f8391c0a9 to your computer and use it in GitHub Desktop.
package pages;
import io.qameta.allure.Step;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
public class AccountsPage extends BasePage {
private String ACTION_BUTTON_PATTERN = "//div[@title='%s']";
public AccountsPage(WebDriver driver) {
super(driver);
}
@Override
public BasePage isPageOpened() {
return null;
}
@Override
public BasePage open() {
return null;
}
@Step("Click on {buttonName} button")
public NewAccountModal clickOnActionButton(String buttonName) {
By button = By.xpath(String.format(ACTION_BUTTON_PATTERN, buttonName));
driver.findElement(button).click();
return new NewAccountModal(driver);
}
}
package pages;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.support.ui.WebDriverWait;
import java.time.Duration;
public abstract class BasePage {
WebDriver driver;
WebDriverWait wait;
public BasePage(WebDriver driver) {
this.driver = driver;
wait = new WebDriverWait(driver, Duration.ofSeconds(10));
}
public abstract BasePage isPageOpened();
public abstract BasePage open();
}
package pages;
import io.qameta.allure.Step;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
public class ContactsPage extends BasePage{
private String ACTION_BUTTON_PATTERN =
"//lightning-button//ancestor::runtime_pipeline_inspector-actions-button-group//button[text()='%s']";
public ContactsPage(WebDriver driver) {
super(driver);
}
@Override
public BasePage isPageOpened() {
return null;
}
@Override
public BasePage open() {
return null;
}
@Step("Click on {buttonName} button")
public void clickOnActionButton(String buttonName) {
By button = By.xpath(String.format(ACTION_BUTTON_PATTERN, buttonName));
driver.findElement(button).click();
}
}
package pages;
import io.qameta.allure.Step;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
public class HomePage extends BasePage {
private final String MENU_OPTION_PATTERN = "//span[text()='%s']//ancestor::one-app-nav-bar-item-root[@role='listitem']";
public HomePage(WebDriver driver) {
super(driver);
}
@Override
public HomePage isPageOpened() {
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//img[@alt='User']//ancestor::button[@type='button']")));
return this;
}
@Step("Open Home page")
public HomePage open() {
driver.get("https://tms9-dev-ed.develop.lightning.force.com/lightning/page/home");
return this;
}
@Step("Select option {optionName} in the menu bar")
public AccountsPage selectMenuOption(String optionName) {
By setOption = By.xpath(String.format(MENU_OPTION_PATTERN, optionName));
driver.findElement(setOption).click();
return new AccountsPage(driver);
}
}
package pages;
import io.qameta.allure.Step;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
public class LoginPage extends BasePage {
private final By USERNAME_INPUT = By.id("username");
private final By PASSWORD_INPUT = By.id("password");
private final By LOGIN_BUTTON = By.id("Login");
public LoginPage(WebDriver driver) {
super(driver);
}
@Override
public LoginPage isPageOpened() {
wait.until(ExpectedConditions.visibilityOfElementLocated(LOGIN_BUTTON));
return this;
}
@Step("Open Login page")
public LoginPage open() {
driver.get("https://tms9-dev-ed.develop.my.salesforce.com/");
return this;
}
@Step("Login into app with valid data - username:{userName} password:{password}")
public HomePage login(String userName, String password) {
driver.findElement(USERNAME_INPUT).sendKeys(userName);
driver.findElement(PASSWORD_INPUT).sendKeys(password);
driver.findElement(LOGIN_BUTTON).click();
return new HomePage(driver);
}
}
package pages;
import dto.Account;
import io.qameta.allure.Step;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import wrappers.Input;
import wrappers.Picklist;
import wrappers.Textarea;
public class NewAccountModal extends BasePage {
private final String BUTTON_PATTERN =
"//button[text()='%s']//ancestor::records-form-footer//ul[@class='slds-button-group-row']";
public NewAccountModal(WebDriver driver) {
super(driver);
}
@Override
public BasePage isPageOpened() {
return null;
}
@Override
public BasePage open() {
return null;
}
@Step("Fill New Account form by valid data")
public NewAccountModal createAccount(Account account) {
//Account Information
new Input(driver, "Account Name").write(account.getAccountName());
new Picklist(driver, "Rating").select(account.getRating());
new Input(driver, "Phone").write(account.getPhone());
new Input(driver, "Fax").write(account.getFax());
return this;
}
@Step("Click on {buttonName} button")
public AccountsPage clickButton(String buttonName) {
By button = By.xpath(String.format(BUTTON_PATTERN, buttonName));
driver.findElement(button).click();
return new AccountsPage(driver);
}
}
package pages;
import io.qameta.allure.Step;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import wrappers.Input;
import wrappers.Picklist;
import wrappers.Textarea;
public class NewContactModal extends BasePage{
private final String BUTTON_PATTERN = "//lightning-button/button[text()='%s']";
public NewContactModal(WebDriver driver) {
super(driver);
}
@Override
public BasePage isPageOpened() {
return null;
}
@Override
public BasePage open() {
return null;
}
@Step("Fill New Contact form with valid data")
public void createContact(String phone, String homePhone, String salutationOption, String firstName, String lastName,
String mobile, String title, String otherPhone, String department, String fax,
String birthdate, String email, String assistant, String leadSourceOption, String asstPhone,
String mailingStreet, String mailingCity, String mailingState, String mailingZip,
String mailingCountry, String otherStreet, String otherCity, String otherState,
String otherZip, String otherCountry, String languages, String levelOption, String description){
//Contact Information
new Input(driver, "Phone").write(phone);
new Input(driver, "Home Phone").write(homePhone);
new Picklist(driver,"Salutation").select(salutationOption);
new Input(driver, "First Name").write(firstName);
new Input(driver, "Last Name").write(lastName);
new Input(driver, "Mobile").write(mobile);
new Input(driver, "Title").write(title);
new Input(driver, "Other Phone").write(otherPhone);
new Input(driver, "Department").write(department);
new Input(driver, "Fax").write(fax);
new Input(driver, "Birthdate").write(birthdate);
new Input(driver, "Email").write(email);
new Input(driver, "Assistant").write(assistant);
new Picklist(driver,"Lead Source").select(leadSourceOption);
new Input(driver, "Asst. Phone").write(asstPhone);
//Address Information
new Textarea(driver, "Mailing Street").write(mailingStreet);
new Input(driver, "Mailing City").write(mailingCity);
new Input(driver, "Mailing State/Province").write(mailingState);
new Input(driver, "Mailing Zip/Postal Code").write(mailingZip);
new Input(driver, "Mailing Country").write(mailingCountry);
new Textarea(driver, "Other Street").write(otherStreet);
new Input(driver, "Other City").write(otherCity);
new Input(driver, "Other State/Province").write(otherState);
new Input(driver, "Other Zip/Postal Code").write(otherZip);
new Input(driver, "Other Country").write(otherCountry);
//Additional Information
new Input(driver, "Languages").write(languages);
new Picklist(driver,"Level").select(levelOption);
//Description Information
new Textarea(driver, "Description").write(description);
}
@Step("Click on {buttonName} button")
public void clickButton(String buttonName) {
By button = By.xpath(String.format(BUTTON_PATTERN, buttonName));
driver.findElement(button).click();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment