add tests on search

This commit is contained in:
Seraphym-Tuhai 2023-04-10 09:07:22 +03:00
parent f7c0be609d
commit 32c6b7385f
6 changed files with 93 additions and 10 deletions

View File

@ -3,14 +3,18 @@ package org.thingsboard.server.msa.ui.pages;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import java.util.List;
public class AlarmElements extends OtherPageElements{
public AlarmElements(WebDriver driver) {
super(driver);
}
private static final String ASSIGN_BTN = "//mat-icon[contains(text(),'keyboard_arrow_down')]/parent::button";
private static final String USER_ASSIGN_DROPDOWN = "//div[contains(@class,'tb-assignee')]//span[contains(text(),'%s')]";
private static final String ASSIGN_USER_DISPLAY_NAME = "//span[text()='%s']/ancestor::mat-row//span[@class='user-display-name']";
private static final String USER_ASSIGN_DROPDOWN = "//div[@class='user-display-name']/span[contains(text(),'%s')]";
private static final String ASSIGN_USERS_DISPLAY_NAME = "//div[@class='user-display-name']/span";
private static final String ASSIGN_USER_DISPLAY_NAME = "//span[@class='user-display-name'][contains(text(),'%s')]";
private static final String SEARCH_FIELD = "//input[@placeholder='Search users']";
public WebElement assignBtn() {
return waitUntilElementToBeClickable(ASSIGN_BTN);
@ -20,7 +24,15 @@ public class AlarmElements extends OtherPageElements{
return waitUntilElementToBeClickable(String.format(USER_ASSIGN_DROPDOWN, userEmail));
}
public WebElement assignUserDisplayName(String userEmail) {
public WebElement assignedUser(String userEmail) {
return waitUntilElementToBeClickable(String.format(ASSIGN_USER_DISPLAY_NAME, userEmail));
}
public List<WebElement> assignUsers() {
return waitUntilElementsToBeClickable(ASSIGN_USERS_DISPLAY_NAME);
}
public WebElement searchUserField() {
return waitUntilElementToBeClickable(SEARCH_FIELD);
}
}

View File

@ -1,6 +1,11 @@
package org.thingsboard.server.msa.ui.pages;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
public class AlarmHelper extends AlarmElements {
public AlarmHelper(WebDriver driver) {
@ -11,4 +16,17 @@ public class AlarmHelper extends AlarmElements {
jsClick(assignBtn());
userFromAssignDropDown(user).click();
}
private List<String> users;
public void setUsers() {
users = assignUsers()
.stream()
.map(WebElement::getText)
.collect(Collectors.toList());
}
public List<String> getUsers() {
return users;
}
}

View File

@ -9,7 +9,8 @@ public class DevicePageElements extends OtherPageElements{
}
private static final String DEVICE = "//table//span[text()='%s']";
private static final String DEVICE_DETAILS_ALARMS = "//tb-details-panel//span[text()='Alarms']";
private static final String DEVICE_DETAILS_VIEW = "//tb-details-panel";
private static final String DEVICE_DETAILS_ALARMS = DEVICE_DETAILS_VIEW + "//span[text()='Alarms']";
public WebElement device(String deviceName) {
return waitUntilElementToBeClickable(String.format(DEVICE, deviceName));
@ -18,4 +19,8 @@ public class DevicePageElements extends OtherPageElements{
public WebElement deviceDetailsAlarmsBtn() {
return waitUntilElementToBeClickable(DEVICE_DETAILS_ALARMS);
}
public WebElement deviceDetailsView() {
return waitUntilPresenceOfElementLocated(DEVICE_DETAILS_VIEW);
}
}

View File

@ -2,13 +2,15 @@ package org.thingsboard.server.msa.ui.pages;
import org.openqa.selenium.WebDriver;
public class DevicePageHelper extends DevicePageElements{
public class DevicePageHelper extends DevicePageElements {
public DevicePageHelper(WebDriver driver) {
super(driver);
}
public void openDeviceAlarms(String deviceName) {
device(deviceName).click();
if (!deviceDetailsView().isDisplayed()) {
device(deviceName).click();
}
deviceDetailsAlarmsBtn().click();
}
}

View File

@ -1,7 +1,6 @@
package org.thingsboard.server.msa.ui.tests;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
@ -17,6 +16,8 @@ import org.thingsboard.server.msa.ui.pages.SideBarMenuViewHelper;
import org.thingsboard.server.msa.ui.utils.DataProviderCredential;
import org.thingsboard.server.msa.ui.utils.EntityPrototypes;
import static org.assertj.core.api.Assertions.assertThat;
public class AssignDetailsTab extends AbstractDriverBaseTest {
AlarmId alarmId;
@ -54,12 +55,13 @@ public class AssignDetailsTab extends AbstractDriverBaseTest {
devicePage.openDeviceAlarms(deviceName);
alarmPage.assignTo(user);
Assert.assertTrue(alarmPage.assignUserDisplayName(user).isDisplayed());
Assert.assertTrue(alarmPage.assignedUser(user).isDisplayed());
}
@Test
public void reassignAlarm() {
userId = testRestClient.postUser(EntityPrototypes.defaultUser(getCustomerByName("Customer A").getId())).getId();
testRestClient.postCustomer(EntityPrototypes.defaultCustomerPrototype("TestCustomer"));
userId = testRestClient.postUser(EntityPrototypes.defaultUser(getCustomerByName("TestCustomer").getId())).getId();
deviceName = testRestClient.postDevice("", DevicePrototypes.defaultDevicePrototype("")).getName();
deviceId = testRestClient.getDeviceByName(deviceName).getId();
alarmId = testRestClient.postAlarm(EntityPrototypes.defaultAlarm(deviceId, userId)).getId();
@ -68,6 +70,41 @@ public class AssignDetailsTab extends AbstractDriverBaseTest {
devicePage.openDeviceAlarms(deviceName);
alarmPage.assignTo("customer@thingsboard.org");
Assert.assertTrue(alarmPage.assignUserDisplayName("customer@thingsboard.org").isDisplayed());
Assert.assertTrue(alarmPage.assignedUser("customer@thingsboard.org").isDisplayed());
}
@Test
public void searchByEmail() {
deviceName = testRestClient.postDevice("", DevicePrototypes.defaultDevicePrototype("")).getName();
deviceId = testRestClient.getDeviceByName(deviceName).getId();
alarmId = testRestClient.postAlarm(EntityPrototypes.defaultAlarm(deviceId)).getId();
sideBarMenuView.goToDevicesPage();
devicePage.openDeviceAlarms(deviceName);
alarmPage.assignBtn().click();
alarmPage.searchUserField().sendKeys("customer@thingsboard.org");
alarmPage.setUsers();
assertThat(alarmPage.getUsers()).contains("customer@thingsboard.org");
alarmPage.assignUsers().forEach(u -> assertThat(u.isDisplayed()).isTrue());
}
@Test
public void searchByName() {
String name = "usik";
userId = testRestClient.postUser(EntityPrototypes.defaultUser(getCustomerByName("Customer A").getId(), name)).getId();
deviceName = testRestClient.postDevice("", DevicePrototypes.defaultDevicePrototype("")).getName();
deviceId = testRestClient.getDeviceByName(deviceName).getId();
alarmId = testRestClient.postAlarm(EntityPrototypes.defaultAlarm(deviceId)).getId();
sideBarMenuView.goToDevicesPage();
devicePage.openDeviceAlarms(deviceName);
alarmPage.assignBtn().click();
alarmPage.searchUserField().sendKeys(name);
alarmPage.setUsers();
assertThat(alarmPage.getUsers()).contains(name);
alarmPage.assignUsers().forEach(u -> assertThat(u.isDisplayed()).isTrue());
}
}

View File

@ -129,4 +129,13 @@ public class EntityPrototypes {
user.setAuthority(Authority.CUSTOMER_USER);
return user;
}
public static User defaultUser(CustomerId customerId, String name) {
User user = new User();
user.setEmail("test@thingsboard.org");
user.setFirstName(name);
user.setCustomerId(customerId);
user.setAuthority(Authority.CUSTOMER_USER);
return user;
}
}