Skip to content

Commit

Permalink
Merge pull request #42 from dzmitryrak/feature/SSC-38-table
Browse files Browse the repository at this point in the history
SSC-38 added click and text actions for table
  • Loading branch information
GalchenokLvenok committed Jan 3, 2023
2 parents c04a621 + 1b61018 commit 877ce0d
Show file tree
Hide file tree
Showing 6 changed files with 154 additions and 92 deletions.
46 changes: 5 additions & 41 deletions src/main/java/io/github/dzmitryrak/pages/ListView.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,14 @@

import java.time.Duration;

import static com.codeborne.selenide.Condition.attributeMatching;
import static com.codeborne.selenide.Condition.visible;
import static com.codeborne.selenide.Condition.*;
import static com.codeborne.selenide.Selenide.$;

@Log4j2
public class ListView extends BasePage {
protected final String CASE_RECORD_LOCATOR = "(//*[contains(@class, 'slds-cell-edit slds-cell-error errorColumn cellContainer')]/parent::tr//th)[%s]";
private final By BREADCRUMB_LOCATOR = By.xpath("//*[contains(@class,'slds-breadcrumb__item')]");
private final By BREADCRUMB_LOCATOR = By.xpath("//*[contains(@class,'slds-breadcrumb__item')]");
private final By FILTER_SWITCHER_BUTTON = By.xpath("//*[contains(@class, 'slds-page-header__name-switcher')]//button");
private final String SELECT_FILTER_LOCATOR = "(//span[contains(@class, ' virtualAutocompleteOptionText') and text()='%s'])[1]";
private final String COLUMN_LOCATOR = "//*[@title='%s']//a";
private final String SORTING_COLUMN_LOCATOR = "//th[@title='%s']";

/**
* Wait until breadcrumb is displayed.
Expand All @@ -42,17 +38,9 @@ public ListView open(String listViewName) {
return this;
}

//TODO create wrapper for tableview

/**
* Open object.
*
* @param index 1-based row index
*/
@Step("Opening object from the list")
public void openObjectFromList(int index) {
log.info("Clicking on the record with the index {}", index);
$(By.xpath(String.format(CASE_RECORD_LOCATOR, index))).click();
public Table table() {
waitForPageLoaded();
return new Table();
}

/**
Expand Down Expand Up @@ -80,30 +68,6 @@ public ListView selectFilter(String filterValue) {
return this;
}

/**
* Sort table column.
*
* @param column column to sort
* @param ascDesc sorting type
* @return current instance of ListView
*/
@Step("Check sorting of the column titled {column} with order {ascDesc}")
public ListView sortBy(String column, SortOrder ascDesc) {
log.info("Sorting the column titled {} in order", column, ascDesc);
try {
$(By.xpath(String.format(SORTING_COLUMN_LOCATOR, column))).shouldHave(attributeMatching("class", ".*ending.*"), Duration.ofSeconds(5)).exists();
} catch (Throwable exception) {
$(By.xpath(String.format(COLUMN_LOCATOR, column))).click();
}
String actualSortingValue = $(By.xpath(String.format(SORTING_COLUMN_LOCATOR, column))).getAttribute("class");
log.debug("Actual sorting value is {}", actualSortingValue);
if (!actualSortingValue.contains(ascDesc.getText())) {
$(By.xpath(String.format(COLUMN_LOCATOR, column))).click();
log.info("Click on the column titled {} to sort it", column);
}
return this;
}

public ListAction actions() {
return new ListAction();
}
Expand Down
120 changes: 120 additions & 0 deletions src/main/java/io/github/dzmitryrak/pages/Table.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
package io.github.dzmitryrak.pages;

import com.codeborne.selenide.ElementsCollection;
import com.codeborne.selenide.SelenideElement;
import io.github.dzmitryrak.enums.SortOrder;
import io.github.dzmitryrak.utils.SalesforceElementNotFoundException;
import io.qameta.allure.Step;
import lombok.extern.log4j.Log4j2;
import org.openqa.selenium.By;

import java.time.Duration;
import java.util.Map;

import static com.codeborne.selenide.Condition.attributeMatching;
import static com.codeborne.selenide.Condition.visible;
import static com.codeborne.selenide.Selenide.*;

@Log4j2
public class Table extends BasePage {
private final String COLUMN_LOCATOR = "//*[@title='%s']//a";
private final String SORTING_COLUMN_LOCATOR = "//th[@title='%s']";
private ElementsCollection headers;
private final By HEADER_LOCATOR = By.xpath(ACTIVE_TAB_LOCATOR + "//thead//th");

public Table() {
waitTillOpened();
waitForPageLoaded();
headers = $$(HEADER_LOCATOR);
StringBuilder builder = new StringBuilder();
for (int i = 0; i < headers.size(); i++) {
builder.append(headers.get(0).attr("title"));
builder.append("|");
}
log.debug("Loaded table with headers: {}", builder.toString());
}

private void waitTillOpened() {
$(HEADER_LOCATOR).shouldBe(visible, Duration.ofSeconds(10));
}

public String getTextFromCell(String columnName, int rowIndex) {
return findCell(columnName, rowIndex).text();
}

//TODO
public Map<String, String> getRecordData(int index) {
return null;
}

//TODO
public Map<String, String> getRecordData(String columnName, String columnValue) {
return null;
}

public Table clickCell(String columnName, int rowIndex) {
findCell(columnName, rowIndex).find("a").click();
return this;
}

private SelenideElement findCell(String columnName, int rowIndex) {
log.debug("Looking for column by title '{}' inside row number '{}'", columnName, rowIndex);
int columnIndex = getColumnIndex(columnName);
return findCell(columnIndex, rowIndex);
}

private SelenideElement findCell(int columnIndex, int rowIndex) {
ElementsCollection allCells = $$x(String.format(
ACTIVE_TAB_LOCATOR + "//tbody//tr[%s]//td|" +
ACTIVE_TAB_LOCATOR + "//tbody//tr[%s]//th", rowIndex, rowIndex));
return allCells.get(columnIndex - 1);
}

private int getColumnIndex(String columnName) {
if(headers.size() == 0) {
throw new SalesforceElementNotFoundException(
String.format("Cannot find column '%s'. List View was not loaded or column doesn't exist", columnName)
);
}
int columnIndex = 0;
StringBuilder builder = new StringBuilder();
for (int i = 0; i < headers.size(); i++) {
//TODO what if null
//TODO what to pass for action/number and checkbox
String columnTitle = headers.get(i).attr("title");
builder.append(columnTitle).append(";");
if (columnTitle.equals(columnName)) {
columnIndex = i+1; //Used +1 here because XPATH index starts from 1 instead of 0
break;
}
}
log.debug("Identified that column '{}' has index '{}'. Checked columns: {}", columnName, columnIndex, builder.toString());

return columnIndex;
}

/**
* Sort table column.
*
* @param column column to sort
* @param ascDesc sorting type
* @return current instance of ListView
*/
@Step("Check sorting of the column titled {column} with order {ascDesc}")
public Table sortBy(String column, SortOrder ascDesc) {
log.info("Sorting the column titled {} in order", column, ascDesc);
try {
$(By.xpath(String.format(SORTING_COLUMN_LOCATOR, column))).shouldHave(attributeMatching("class", ".*ending.*"), Duration.ofSeconds(5)).exists();
} catch (Throwable exception) {
$(By.xpath(String.format(COLUMN_LOCATOR, column))).click();
}
String actualSortingValue = $(By.xpath(String.format(SORTING_COLUMN_LOCATOR, column))).getAttribute("class");
log.debug("Actual sorting value is {}", actualSortingValue);
if (!actualSortingValue.contains(ascDesc.getText())) {
$(By.xpath(String.format(COLUMN_LOCATOR, column))).click();
log.info("Click on the column titled {} to sort it", column);
}
return this;
}

}
4 changes: 2 additions & 2 deletions src/main/resources/log4j2-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ Configuration:
AppenderRef:
ref: consoleAppender
- name: fileLogger
level: INFO
level: DEBUG
additivity: false
AppenderRef:
ref: fileAppender
Root:
level: INFO
level: DEBUG
AppenderRef:
- ref: consoleAppender
level: INFO
Expand Down
27 changes: 27 additions & 0 deletions src/test/java/io/github/dzmitryrak/tests/CaseTest.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package io.github.dzmitryrak.tests;

import io.github.dzmitryrak.enums.SortOrder;
import io.github.dzmitryrak.tests.base.BaseTest;
import org.testng.annotations.Test;

import static com.codeborne.selenide.Selenide.open;
import static org.testng.Assert.assertEquals;

public class CaseTest extends BaseTest {

Expand All @@ -27,7 +29,32 @@ public void panelValidation() {
.validate("Status", "New")
.validate("Priority", "Low")
.validate("Description", "");
}

@Test(description = "Check that values of cells could be interacted")
public void tableValidation() {
loginPage.open().login(USERNAME, PASSWORD);
listView
.open("Case")
.table()
.clickCell("Case Number", 1);
detailsPage.waitTillOpened();
String subject =
listView
.open("Case")
.table()
.sortBy("Case Number", SortOrder.ASC)
.getTextFromCell("Subject", 1);
assertEquals(subject, "Starting generator after electrical failure");
}

@Test(description = "Check that listview sorting exists and works")
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);
}
}
19 changes: 0 additions & 19 deletions src/test/java/io/github/dzmitryrak/tests/ListViewTest.java

This file was deleted.

30 changes: 0 additions & 30 deletions src/test/java/io/github/dzmitryrak/tests/base/Retry.java

This file was deleted.

0 comments on commit 877ce0d

Please sign in to comment.