added tests on create and delete device

This commit is contained in:
Seraphym-Tuhai 2023-05-03 16:05:16 +03:00
parent c8d28ed672
commit 149e3fb8ed
9 changed files with 355 additions and 1 deletions

View File

@ -132,6 +132,18 @@ public class TestRestClient {
.as(Device.class);
}
public PageData<Device> getDevices(PageLink pageLink) {
Map<String, String> params = new HashMap<>();
addPageLinkToParam(params, pageLink);
return given().spec(requestSpec).queryParams(params)
.get("/api/tenant/devices")
.then()
.statusCode(HTTP_OK)
.extract()
.as(new TypeRef<PageData<Device>>() {
});
}
public DeviceCredentials getDeviceCredentialsByDeviceId(DeviceId deviceId) {
return given().spec(requestSpec).get("/api/device/{deviceId}/credentials", deviceId.getId())
.then()

View File

@ -37,6 +37,7 @@ import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.thingsboard.server.common.data.Customer;
import org.thingsboard.server.common.data.Device;
import org.thingsboard.server.common.data.DeviceProfile;
import org.thingsboard.server.common.data.asset.AssetProfile;
import org.thingsboard.server.common.data.id.AlarmId;
@ -150,6 +151,12 @@ abstract public class AbstractDriverBaseTest extends AbstractContainerTest {
.findFirst().orElse(null);
}
public Device getDeviceByName(String name) {
return testRestClient.getDevices(pageLink).getData().stream()
.filter(s -> s.getName().equals(name))
.findFirst().orElse(null);
}
public List<RuleChain> getRuleChainsByName(String name) {
return testRestClient.getRuleChains(pageLink).getData().stream()
.filter(s -> s.getName().equals(name))
@ -269,4 +276,11 @@ abstract public class AbstractDriverBaseTest extends AbstractContainerTest {
testRestClient.deleteDashboard(dashboardId);
}
}
public void deleteDeviceByName(String deviceName) {
Device device = getDeviceByName(deviceName);
if (device != null) {
testRestClient.deleteDevice(device.getId());
}
}
}

View File

@ -18,7 +18,7 @@ package org.thingsboard.server.msa.ui.pages;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
public class DevicePageElements extends OtherPageElements {
public class DevicePageElements extends OtherPageElementsHelper {
public DevicePageElements(WebDriver driver) {
super(driver);
}
@ -32,6 +32,12 @@ public class DevicePageElements extends OtherPageElements {
private static final String CUSTOMER_FROM_ASSIGN_DROPDOWN = "//div[@role = 'listbox']//span[text() = '%s']";
private static final String CLOSE_DEVICE_DETAILS_VIEW = "//header//mat-icon[contains(text(),'close')]/parent::button";
private static final String SUBMIT_ASSIGN_TO_CUSTOMER_BTN = "//button[@type='submit']";
private static final String ADD_DEVICE_BTN = "//mat-icon[text() = 'insert_drive_file']/parent::button";
private static final String CREATE_DEVICE_NAME_FIELD = "//tb-device-wizard//input[@formcontrolname='name']";
private static final String HEADER_NAME_VIEW = "//header//div[@class='tb-details-title']/span";
private static final String DESCRIPTION_FIELD_CREATE_VIEW = "//tb-device-wizard//textarea[@formcontrolname='description']";
private static final String ADD_DEVICE_VIEW = "//tb-device-wizard";
private static final String DELETE_BTN_DETAILS_TAB = "//span[contains(text(),'Delete device')]/parent::button";
public WebElement device(String deviceName) {
return waitUntilElementToBeClickable(String.format(DEVICE, deviceName));
@ -64,4 +70,28 @@ public class DevicePageElements extends OtherPageElements {
public WebElement submitAssignToCustomerBtn() {
return waitUntilElementToBeClickable(SUBMIT_ASSIGN_TO_CUSTOMER_BTN);
}
public WebElement addDeviceBtn() {
return waitUntilElementToBeClickable(ADD_DEVICE_BTN);
}
public WebElement nameField() {
return waitUntilElementToBeClickable(CREATE_DEVICE_NAME_FIELD);
}
public WebElement headerNameView() {
return waitUntilVisibilityOfElementLocated(HEADER_NAME_VIEW);
}
public WebElement descriptionFieldCreateField() {
return waitUntilElementToBeClickable(DESCRIPTION_FIELD_CREATE_VIEW);
}
public WebElement addDeviceView() {
return waitUntilPresenceOfElementLocated(ADD_DEVICE_VIEW);
}
public WebElement deleteBtnDetailsTab() {
return waitUntilElementToBeClickable(DELETE_BTN_DETAILS_TAB);
}
}

View File

@ -34,4 +34,29 @@ public class DevicePageHelper extends DevicePageElements {
customerFromAssignDropdown(customerTitle).click();
submitAssignToCustomerBtn().click();
}
public void openCreateDeviceView() {
plusBtn().click();
addDeviceBtn().click();
}
public void enterName(String deviceName) {
nameField().click();
nameField().sendKeys(deviceName);
}
public void enterDescription(String description) {
descriptionFieldCreateField().click();
descriptionFieldCreateField().sendKeys(description);
}
public void deleteDeviceByRightSideBtn(String deviceName) {
deleteBtn(deviceName).click();
warningPopUpYesBtn().click();
}
public void deleteDeviceFromDetailsTab() {
deleteBtnDetailsTab().click();
warningPopUpYesBtn().click();
}
}

View File

@ -0,0 +1,45 @@
/**
* Copyright © 2016-2023 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thingsboard.server.msa.ui.tests.devicessmoke;
import io.qameta.allure.Epic;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeClass;
import org.thingsboard.server.msa.ui.base.AbstractDriverBaseTest;
import org.thingsboard.server.msa.ui.pages.DevicePageHelper;
import org.thingsboard.server.msa.ui.pages.LoginPageHelper;
import org.thingsboard.server.msa.ui.pages.SideBarMenuViewElements;
@Epic("Device smoke tests")
abstract public class AbstractDeviceTest extends AbstractDriverBaseTest {
protected SideBarMenuViewElements sideBarMenuView;
protected DevicePageHelper devicePage;
protected String deviceName;
@BeforeClass
public void login() {
new LoginPageHelper(driver).authorizationTenant();
sideBarMenuView = new SideBarMenuViewElements(driver);
devicePage = new DevicePageHelper(driver);
}
@AfterMethod
public void delete() {
deleteDeviceByName(deviceName);
deviceName = null;
}
}

View File

@ -0,0 +1,132 @@
/**
* Copyright © 2016-2023 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thingsboard.server.msa.ui.tests.devicessmoke;
import io.qameta.allure.Description;
import io.qameta.allure.Feature;
import org.testng.annotations.Test;
import org.thingsboard.server.common.data.Device;
import org.thingsboard.server.msa.ui.utils.EntityPrototypes;
import static org.assertj.core.api.Assertions.assertThat;
import static org.thingsboard.server.msa.ui.base.AbstractBasePage.random;
import static org.thingsboard.server.msa.ui.utils.Const.EMPTY_DEVICE_MESSAGE;
import static org.thingsboard.server.msa.ui.utils.Const.ENTITY_NAME;
import static org.thingsboard.server.msa.ui.utils.Const.NAME_IS_REQUIRED_MESSAGE;
import static org.thingsboard.server.msa.ui.utils.Const.SAME_NAME_WARNING_DEVICE_MESSAGE;
@Feature("Create device")
public class CreateDeviceTest extends AbstractDeviceTest {
@Test(groups = "smoke")
@Description("Add device after specifying the name (text/numbers /special characters)")
public void createDevice() {
deviceName = ENTITY_NAME + random();
sideBarMenuView.devicesBtn().click();
devicePage.openCreateDeviceView();
devicePage.enterName(deviceName);
devicePage.addBtnC().click();
devicePage.refreshBtn().click();
assertIsDisplayed(devicePage.entity(deviceName));
}
@Test(groups = "smoke")
@Description("Add device after specifying the name and description (text/numbers /special characters)")
public void createDeviceWithDescription() {
deviceName = ENTITY_NAME + random();
sideBarMenuView.devicesBtn().click();
devicePage.openCreateDeviceView();
devicePage.enterName(deviceName);
devicePage.enterDescription(deviceName);
devicePage.addBtnC().click();
devicePage.refreshBtn().click();
devicePage.entity(deviceName).click();
devicePage.setHeaderName();
assertThat(devicePage.getHeaderName()).as("Header of device details tab").isEqualTo(deviceName);
assertThat(devicePage.descriptionEntityView().getAttribute("value"))
.as("Description in device details tab").isEqualTo(deviceName);
}
@Test(groups = "smoke")
@Description("Add device without the name")
public void createDeviceWithoutName() {
sideBarMenuView.devicesBtn().click();
devicePage.openCreateDeviceView();
devicePage.nameField().click();
devicePage.addBtnC().click();
assertIsDisplayed(devicePage.addDeviceView());
assertThat(devicePage.errorMessage().getText()).as("Text of warning message").isEqualTo(NAME_IS_REQUIRED_MESSAGE);
}
@Test(groups = "smoke")
@Description("Create device only with spase in name")
public void createDeviceWithOnlySpace() {
sideBarMenuView.devicesBtn().click();
devicePage.openCreateDeviceView();
devicePage.enterName(" ");
devicePage.addBtnC().click();
assertIsDisplayed(devicePage.warningMessage());
assertThat(devicePage.warningMessage().getText()).as("Text of warning message").isEqualTo(EMPTY_DEVICE_MESSAGE);
assertIsDisplayed(devicePage.addDeviceView());
}
@Test(priority = 20, groups = "smoke")
@Description("Create a device with the same name")
public void createRuleChainWithSameName() {
Device device = testRestClient.postDevice("", EntityPrototypes.defaultDevicePrototype(ENTITY_NAME));
deviceName = device.getName();
sideBarMenuView.devicesBtn().click();
devicePage.openCreateDeviceView();
devicePage.enterName(deviceName);
devicePage.addBtnC().click();
assertIsDisplayed(devicePage.warningMessage());
assertThat(devicePage.warningMessage().getText()).as("Text of warning message").isEqualTo(SAME_NAME_WARNING_DEVICE_MESSAGE);
assertIsDisplayed(devicePage.addDeviceView());
}
@Test(priority = 30, groups = "smoke")
@Description("Add device after specifying the name (text/numbers /special characters) without refresh")
public void createDeviceWithoutRefresh() {
deviceName = ENTITY_NAME + random();
sideBarMenuView.devicesBtn().click();
devicePage.openCreateDeviceView();
devicePage.enterName(deviceName);
devicePage.addBtnC().click();
assertIsDisplayed(devicePage.entity(deviceName));
}
@Test(priority = 40, groups = "smoke")
@Description("Go to devices documentation page")
public void documentation() {
String urlPath = "docs/user-guide/ui/devices/";
sideBarMenuView.devicesBtn().click();
devicePage.entity("Thermostat T1").click();
devicePage.goToHelpPage();
assertThat(urlContains(urlPath)).as("Redirected URL contains " + urlPath).isTrue();
}
}

View File

@ -0,0 +1,59 @@
/**
* Copyright © 2016-2023 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thingsboard.server.msa.ui.tests.devicessmoke;
import io.qameta.allure.Feature;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import org.thingsboard.server.common.data.Device;
import org.thingsboard.server.msa.ui.utils.EntityPrototypes;
import static org.thingsboard.server.msa.ui.utils.Const.ENTITY_NAME;
@Feature("Delete device")
public class DeleteDeviceTest extends AbstractDeviceTest {
@BeforeMethod
public void createDevice() {
Device device = testRestClient.postDevice("", EntityPrototypes.defaultDevicePrototype(ENTITY_NAME));
deviceName = device.getName();
}
@Test(groups = "smoke")
public void deleteDeviceByRightSideBtn() {
sideBarMenuView.devicesBtn().click();
devicePage.deleteDeviceByRightSideBtn(deviceName);
devicePage.assertEntityIsNotPresent(deviceName);
}
@Test(groups = "smoke")
public void deleteSelectedDevice() {
sideBarMenuView.devicesBtn().click();
devicePage.deleteSelected(deviceName);
devicePage.assertEntityIsNotPresent(deviceName);
}
@Test(groups = "smoke")
public void deleteDeviceFromDetailsTab() {
sideBarMenuView.devicesBtn().click();
devicePage.entity(deviceName).click();
devicePage.deleteDeviceFromDetailsTab();
devicePage.assertEntityIsNotPresent(deviceName);
}
}

View File

@ -36,10 +36,12 @@ public class Const {
public static final String EMPTY_CUSTOMER_MESSAGE = "Customer title should be specified!";
public static final String EMPTY_DEVICE_PROFILE_MESSAGE = "Device profile name should be specified!";
public static final String EMPTY_ASSET_PROFILE_MESSAGE = "Asset profile name should be specified!";
public static final String EMPTY_DEVICE_MESSAGE = "Device name should be specified!";
public static final String DELETE_RULE_CHAIN_WITH_PROFILE_MESSAGE = "The rule chain referenced by the device profiles cannot be deleted!";
public static final String SAME_NAME_WARNING_CUSTOMER_MESSAGE = "Customer with such title already exists!";
public static final String SAME_NAME_WARNING_DEVICE_PROFILE_MESSAGE = "Device profile with such name already exists!";
public static final String SAME_NAME_WARNING_ASSET_PROFILE_MESSAGE = "Asset profile with such name already exists!";
public static final String SAME_NAME_WARNING_DEVICE_MESSAGE = "Device with such name already exists!";
public static final String PHONE_NUMBER_ERROR_MESSAGE = "Phone number is invalid or not possible";
public static final String NAME_IS_REQUIRED_MESSAGE = "Name is required.";
}

View File

@ -0,0 +1,35 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
Copyright © 2016-2023 The Thingsboard Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="Devices Smoke Tests">
<listeners>
<listener class-name="org.thingsboard.server.msa.ui.listeners.RetryTestListener"/>
</listeners>
<test name="Devices ui smoke tests">
<groups>
<run>
<exclude name="broken"/>
</run>
</groups>
<packages>
<package name="org.thingsboard.server.msa.ui.tests.devicessmoke"/>
</packages>
</test>
</suite>