From 149e3fb8ed37a28d2c8156f46890e28485892077 Mon Sep 17 00:00:00 2001 From: Seraphym-Tuhai Date: Wed, 3 May 2023 16:05:16 +0300 Subject: [PATCH] added tests on create and delete device --- .../server/msa/TestRestClient.java | 12 ++ .../msa/ui/base/AbstractDriverBaseTest.java | 14 ++ .../msa/ui/pages/DevicePageElements.java | 32 ++++- .../server/msa/ui/pages/DevicePageHelper.java | 25 ++++ .../devicessmoke/AbstractDeviceTest.java | 45 ++++++ .../tests/devicessmoke/CreateDeviceTest.java | 132 ++++++++++++++++++ .../tests/devicessmoke/DeleteDeviceTest.java | 59 ++++++++ .../server/msa/ui/utils/Const.java | 2 + .../src/test/resources/smokeDevices.xml | 35 +++++ 9 files changed, 355 insertions(+), 1 deletion(-) create mode 100644 msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/devicessmoke/AbstractDeviceTest.java create mode 100644 msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/devicessmoke/CreateDeviceTest.java create mode 100644 msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/devicessmoke/DeleteDeviceTest.java create mode 100644 msa/black-box-tests/src/test/resources/smokeDevices.xml diff --git a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/TestRestClient.java b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/TestRestClient.java index 76ce467fd9..880143b58a 100644 --- a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/TestRestClient.java +++ b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/TestRestClient.java @@ -132,6 +132,18 @@ public class TestRestClient { .as(Device.class); } + public PageData getDevices(PageLink pageLink) { + Map params = new HashMap<>(); + addPageLinkToParam(params, pageLink); + return given().spec(requestSpec).queryParams(params) + .get("/api/tenant/devices") + .then() + .statusCode(HTTP_OK) + .extract() + .as(new TypeRef>() { + }); + } + public DeviceCredentials getDeviceCredentialsByDeviceId(DeviceId deviceId) { return given().spec(requestSpec).get("/api/device/{deviceId}/credentials", deviceId.getId()) .then() diff --git a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/base/AbstractDriverBaseTest.java b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/base/AbstractDriverBaseTest.java index cd34e69239..eb6776a4e4 100644 --- a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/base/AbstractDriverBaseTest.java +++ b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/base/AbstractDriverBaseTest.java @@ -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 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()); + } + } } diff --git a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/DevicePageElements.java b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/DevicePageElements.java index b8fbda5135..9cec09c023 100644 --- a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/DevicePageElements.java +++ b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/DevicePageElements.java @@ -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); + } } diff --git a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/DevicePageHelper.java b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/DevicePageHelper.java index 19e85244cd..dd9d4113e8 100644 --- a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/DevicePageHelper.java +++ b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/pages/DevicePageHelper.java @@ -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(); + } } diff --git a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/devicessmoke/AbstractDeviceTest.java b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/devicessmoke/AbstractDeviceTest.java new file mode 100644 index 0000000000..ecacc25ba7 --- /dev/null +++ b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/devicessmoke/AbstractDeviceTest.java @@ -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; + } +} diff --git a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/devicessmoke/CreateDeviceTest.java b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/devicessmoke/CreateDeviceTest.java new file mode 100644 index 0000000000..85fc9ce79e --- /dev/null +++ b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/devicessmoke/CreateDeviceTest.java @@ -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(); + } +} diff --git a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/devicessmoke/DeleteDeviceTest.java b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/devicessmoke/DeleteDeviceTest.java new file mode 100644 index 0000000000..3d8db52652 --- /dev/null +++ b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/tests/devicessmoke/DeleteDeviceTest.java @@ -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); + } +} diff --git a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/utils/Const.java b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/utils/Const.java index 7b64eaa1b4..c63fa0382d 100644 --- a/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/utils/Const.java +++ b/msa/black-box-tests/src/test/java/org/thingsboard/server/msa/ui/utils/Const.java @@ -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."; } \ No newline at end of file diff --git a/msa/black-box-tests/src/test/resources/smokeDevices.xml b/msa/black-box-tests/src/test/resources/smokeDevices.xml new file mode 100644 index 0000000000..c255f9ed53 --- /dev/null +++ b/msa/black-box-tests/src/test/resources/smokeDevices.xml @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + + + + + + \ No newline at end of file