Skip to content

Commit

Permalink
Merge pull request #71 from dzmitryrak/feature/SSC-71-updateDetailsPa…
Browse files Browse the repository at this point in the history
…geAndElementHelper

1. Updated DetailsPage: added clickButton and selectRadioButton methods
  • Loading branch information
dzmitryrak committed Apr 20, 2023
2 parents be7dc01 + de74cf2 commit 66832ad
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 12 deletions.
28 changes: 24 additions & 4 deletions src/main/java/io/github/dzmitryrak/pages/DetailsPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@

@Log4j2
public class DetailsPage extends BasePage {
private final String COMMON_TAB = ACTIVE_TAB_LOCATOR + "//a[@data-label='%s']";
private final String COMMON_TAB = ACTIVE_TAB_LOCATOR + "//a[@data-label='%s' or @title='%s']";
private final String COMMON_BUTTON = ACTIVE_TAB_LOCATOR + "//*[@title='%s' or text()='%s']";
private final String COMMON_RADIOBUTTON = ACTIVE_TAB_LOCATOR + "//span[text()='%s']/ancestor::span[@class='slds-radio']//span[@class='slds-radio_faux']";

/**
* Wait until Details tab is displayed.
Expand All @@ -31,11 +33,24 @@ public DetailsPage waitTillOpened() {
@Step("Open '{tabName}' tab")
public DetailsPage clickTab(String tabName) {
log.info("Opening {} tab", tabName);

By tabLocator = By.xpath(String.format(COMMON_TAB, tabName));
By tabLocator = By.xpath(String.format(COMMON_TAB, tabName, tabName));
$(tabLocator).shouldBe(visible, timeout);
clickJS(tabLocator);
$(tabLocator).shouldBe(visible, timeout);
return this;
}

/**
* Click any button on detail page
*
* @param buttonName
* @return current instance of DetailsPage
*/
@Step("Click '{buttonName}' button")
public DetailsPage clickButton(String buttonName) {
log.info("Click {} button", buttonName);
By buttonLocator = By.xpath(String.format(COMMON_BUTTON, buttonName, buttonName));
$(buttonLocator).shouldBe(visible, timeout);
clickJS(buttonLocator);
return this;
}

Expand Down Expand Up @@ -87,4 +102,9 @@ public Panel panels() {
public Table table(String tableName) {
return new Table(tableName);
}

public DetailsPage selectRadioButton(String radioButtonName) {
sfHelper.selectRadioButton(radioButtonName);
return this;
}
}
19 changes: 18 additions & 1 deletion src/main/java/io/github/dzmitryrak/utils/ElementHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import com.codeborne.selenide.Configuration;
import com.codeborne.selenide.Selenide;
import com.codeborne.selenide.SelenideElement;
import io.github.dzmitryrak.pages.DetailsPage;
import io.github.dzmitryrak.pages.NewObjectModal;
import io.qameta.allure.Step;
import lombok.extern.log4j.Log4j2;
import org.apache.commons.lang3.StringUtils;
import org.openqa.selenium.By;
Expand All @@ -23,13 +25,16 @@
@Log4j2
public class ElementHelper {
public static final String BASE_DETAIL_PANEL = "//records-lwc-detail-panel";
public static final String ACTIVE_TAB_LOCATOR = "//*[contains(@class,'windowViewMode') and contains(@class,'active')]";
String pickList = BASE_DETAIL_PANEL + "//*[text()='%s']/ancestor::lightning-picklist";
String pickListButton = pickList + "//button[@lightning-basecombobox_basecombobox]";
String textInput = BASE_DETAIL_PANEL + "//*[text()='%s']/ancestor::lightning-input//input[@type='text']";
String lookUpField = BASE_DETAIL_PANEL + "//*[text()='%s']/ancestor::lightning-lookup//input";
String clearLookUpField = BASE_DETAIL_PANEL + "//*[text()='%s']/ancestor::lightning-lookup//button";
String textArea = BASE_DETAIL_PANEL + "//*[text()='%s']/ancestor::lightning-textarea//textarea";
String checkbox = BASE_DETAIL_PANEL + "//*[text()='%s']/ancestor::lightning-input//input[@type='checkbox']";
String radioButton = ACTIVE_TAB_LOCATOR + "//span[text()='%s']/ancestor::span[@class='slds-radio']//span[@class='slds-radio_faux']";
//"//span[@class='slds-radio_faux']";

/**
* Fill any Salesforce element.
Expand Down Expand Up @@ -194,10 +199,11 @@ public void validate(String panel, String label, String expectedText) {
}
} else {
//TODO throw custom exception with simple text
SelenideElement input = $(By.xpath(String.format(genericLocator, label)));
if (StringUtils.isNotEmpty(expectedText)) {
SelenideElement input = $$(By.xpath(String.format(genericLocator + "//text()/parent::*", label))).first();
input.shouldHave(text(expectedText));
} else {
SelenideElement input = $(By.xpath(String.format(genericLocator, label)));
input.shouldHave(exactTextCaseSensitive(expectedText));
}
}
Expand Down Expand Up @@ -245,6 +251,17 @@ public void createNewRecordThroughLookup(String elementLabel, Map<String, String
.waitTillModalClosed();
}

/**
* Select any radioButton
*
* @param radioButtonName
*/
@Step("Select '{radioButtonName}'")
public void selectRadioButton(String radioButtonName) {
log.info("Select {}", radioButtonName);
jsClick($(By.xpath(String.format(radioButton, radioButtonName))));
}

private void jsClick(WebElement el) {
Selenide.executeJavaScript("arguments[0].click();", el);
}
Expand Down
7 changes: 7 additions & 0 deletions src/test/java/io/github/dzmitryrak/tests/AccountCRUDTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,13 @@ public void editAccount() {
.save()
.waitTillModalClosed()
.waitTillOpened();
detailsPage
.actions()
.moreActions()
.action("UI Tests");
detailsPage
.selectRadioButton("yes")
.clickButton("Finish");

updatedAccount.remove("Description");
updatedAccount.remove("Billing Street");
Expand Down
29 changes: 22 additions & 7 deletions src/test/java/io/github/dzmitryrak/tests/CaseTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ public void tableValidation() {
detailsPage.waitTillOpened();
String subject =
listView
.open("Case")
.table()
.sortBy("Case Number", SortOrder.ASC)
.getTextFromCell("Subject", 1);
.open("Case")
.table()
.sortBy("Case Number", SortOrder.ASC)
.getTextFromCell("Subject", 1);
assertEquals(subject, "Starting generator after electrical failure");
}

Expand All @@ -55,19 +55,34 @@ public void tableSortingValidation() {
.open("Case")
.table()
.sortBy("Case Number", SortOrder.DESC)
.getTextFromCell("Case Number",1);
.getTextFromCell("Case Number", 1);
listView.table().clickCell("Case Number", 1);
detailsPage.waitTillOpened();
detailsPage.panels().panel("Case Details").validate("Case Number",subject);
detailsPage.panels().panel("Case Details").validate("Case Number", subject);
}

@Test(description = "Check that listview sorting exists and works")
public void sortingListView(){
public void sortingListView() {
loginPage.open().login(USERNAME, PASSWORD);
listView.open("Case");
listView.clickSwitcher();
listView.selectFilter("My Cases");
listView.table().sortBy("Case Number", SortOrder.DESC);
listView.table().clickCell("Case Number", 1);
}

@Test(description = "Check that we can click on any button on case detail page")
public void clickButtonOnDetailPage() {
loginPage.open().login(USERNAME, PASSWORD);
listView.open("Case");
listView.clickSwitcher();
listView.selectFilter("My Cases");
listView.table().sortBy("Case Number", SortOrder.DESC);
listView.table().clickCell("Case Number", 1);
detailsPage.clickTab("Feed")
.clickTab("Poll")
.clickButton("Add new choice")
.clickButton("Edit");

}
}

0 comments on commit 66832ad

Please sign in to comment.