11 changed files with 546 additions and 81 deletions
@ -0,0 +1,42 @@ |
|||
/** |
|||
* 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.tabs; |
|||
|
|||
import org.openqa.selenium.WebDriver; |
|||
import org.openqa.selenium.WebElement; |
|||
import org.thingsboard.server.msa.ui.base.AbstractBasePage; |
|||
|
|||
public class AssignDeviceTabElements extends AbstractBasePage { |
|||
public AssignDeviceTabElements(WebDriver driver) { |
|||
super(driver); |
|||
} |
|||
|
|||
private static final String ASSIGN_ON_CUSTOMER_FIELD = "//input[@formcontrolname='entity']"; |
|||
private static final String CUSTOMER_FROM_DROPDOWN = "//div[@role='listbox']/mat-option//span[contains(text(),'%s')]"; |
|||
private static final String ASSIGN_BTN = "//button[@type='submit']"; |
|||
|
|||
public WebElement assignOnCustomerField() { |
|||
return waitUntilElementToBeClickable(ASSIGN_ON_CUSTOMER_FIELD); |
|||
} |
|||
|
|||
public WebElement customerFromDropDown(String entityName) { |
|||
return waitUntilVisibilityOfElementLocated(String.format(CUSTOMER_FROM_DROPDOWN, entityName)); |
|||
} |
|||
|
|||
public WebElement assignBtn() { |
|||
return waitUntilElementToBeClickable(ASSIGN_BTN); |
|||
} |
|||
} |
|||
@ -0,0 +1,30 @@ |
|||
/** |
|||
* 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.tabs; |
|||
|
|||
import org.openqa.selenium.WebDriver; |
|||
|
|||
public class AssignDeviceTabHelper extends AssignDeviceTabElements { |
|||
public AssignDeviceTabHelper(WebDriver driver) { |
|||
super(driver); |
|||
} |
|||
|
|||
public void assignOnCustomer(String customerTitle) { |
|||
assignOnCustomerField().click(); |
|||
customerFromDropDown(customerTitle).click(); |
|||
assignBtn().click(); |
|||
} |
|||
} |
|||
@ -0,0 +1,97 @@ |
|||
/** |
|||
* 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.tabs; |
|||
|
|||
import org.openqa.selenium.WebDriver; |
|||
import org.openqa.selenium.WebElement; |
|||
import org.thingsboard.server.msa.ui.base.AbstractBasePage; |
|||
|
|||
public class CreateDeviceTabElements extends AbstractBasePage { |
|||
public CreateDeviceTabElements(WebDriver driver) { |
|||
super(driver); |
|||
} |
|||
|
|||
private static final String CREATE_DEVICE_NAME_FIELD = "//tb-device-wizard//input[@formcontrolname='name']"; |
|||
private static final String CREATE_NEW_DEVICE_PROFILE_RADIO_BTN = "//span[text() = 'Create new device profile']/ancestor::mat-radio-button"; |
|||
private static final String SELECT_EXISTING_DEVICE_PROFILE_RADIO_BTN = "//span[text() = 'Select existing device profile']/ancestor::mat-radio-button"; |
|||
private static final String DEVICE_PROFILE_TITLE_FIELD = "//input[@formcontrolname='newDeviceProfileTitle']"; |
|||
private static final String ADD_BTN = "//span[text() = 'Add']"; |
|||
private static final String CLEAR_PROFILE_FIELD_BTN = "//button[@aria-label='Clear']"; |
|||
private static final String ENTITY_FROM_DROPDOWN = "//div[@role = 'listbox']//span[text() = '%s']"; |
|||
private static final String ASSIGN_ON_CUSTOMER_FIELD = "//input[@formcontrolname='entity']"; |
|||
private static final String CUSTOMER_OPTION_BNT = "//div[text() = 'Customer']/ancestor::mat-step-header"; |
|||
private static final String CUSTOMER_FROM_DROPDOWN = "//div[@role='listbox']/mat-option//span[contains(text(),'%s')]"; |
|||
private static final String DEVICE_LABEL_FIELD = "//tb-device-wizard//input[@formcontrolname='label']"; |
|||
private static final String CHECKBOX_GATEWAY = "//tb-device-wizard//mat-checkbox[@formcontrolname='gateway']//label"; |
|||
private static final String CHECKBOX_OVERWRITE_ACTIVITY_TIME = "//tb-device-wizard//mat-checkbox[@formcontrolname='overwriteActivityTime']//label"; |
|||
private static final String DESCRIPTION_FIELD = "//tb-device-wizard//textarea[@formcontrolname='description']"; |
|||
|
|||
public WebElement nameField() { |
|||
return waitUntilElementToBeClickable(CREATE_DEVICE_NAME_FIELD); |
|||
} |
|||
|
|||
public WebElement createNewDeviceProfileRadioBtn() { |
|||
return waitUntilElementToBeClickable(CREATE_NEW_DEVICE_PROFILE_RADIO_BTN); |
|||
} |
|||
|
|||
public WebElement selectExistingDeviceProfileRadioBtn() { |
|||
return waitUntilElementToBeClickable(SELECT_EXISTING_DEVICE_PROFILE_RADIO_BTN); |
|||
} |
|||
|
|||
public WebElement deviceProfileTitleField() { |
|||
return waitUntilElementToBeClickable(DEVICE_PROFILE_TITLE_FIELD); |
|||
} |
|||
|
|||
public WebElement addBtn() { |
|||
return waitUntilElementToBeClickable(ADD_BTN); |
|||
} |
|||
|
|||
public WebElement clearProfileFieldBtn() { |
|||
return waitUntilElementToBeClickable(CLEAR_PROFILE_FIELD_BTN); |
|||
} |
|||
|
|||
public WebElement entityFromDropdown(String customerTitle) { |
|||
return waitUntilElementToBeClickable(String.format(ENTITY_FROM_DROPDOWN, customerTitle)); |
|||
} |
|||
|
|||
public WebElement assignOnCustomerField() { |
|||
return waitUntilElementToBeClickable(ASSIGN_ON_CUSTOMER_FIELD); |
|||
} |
|||
|
|||
public WebElement customerOptionBtn() { |
|||
return waitUntilElementToBeClickable(CUSTOMER_OPTION_BNT); |
|||
} |
|||
|
|||
public WebElement customerFromDropDown(String entityName) { |
|||
return waitUntilVisibilityOfElementLocated(String.format(CUSTOMER_FROM_DROPDOWN, entityName)); |
|||
} |
|||
|
|||
public WebElement deviceLabelField() { |
|||
return waitUntilElementToBeClickable(DEVICE_LABEL_FIELD); |
|||
} |
|||
|
|||
public WebElement checkboxGateway() { |
|||
return waitUntilElementToBeClickable(CHECKBOX_GATEWAY); |
|||
} |
|||
|
|||
public WebElement checkboxOverwriteActivityTime() { |
|||
return waitUntilElementToBeClickable(CHECKBOX_OVERWRITE_ACTIVITY_TIME); |
|||
} |
|||
|
|||
public WebElement descriptionField() { |
|||
return waitUntilElementToBeClickable(DESCRIPTION_FIELD); |
|||
} |
|||
} |
|||
@ -0,0 +1,58 @@ |
|||
/** |
|||
* 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.tabs; |
|||
|
|||
import org.openqa.selenium.WebDriver; |
|||
|
|||
public class CreateDeviceTabHelper extends CreateDeviceTabElements { |
|||
public CreateDeviceTabHelper(WebDriver driver) { |
|||
super(driver); |
|||
} |
|||
|
|||
public void enterName(String deviceName) { |
|||
enterText(nameField(), deviceName); |
|||
} |
|||
|
|||
public void createNewDeviceProfile(String deviceProfileTitle) { |
|||
if (!createNewDeviceProfileRadioBtn().getAttribute("class").contains("checked")) { |
|||
createNewDeviceProfileRadioBtn().click(); |
|||
} |
|||
deviceProfileTitleField().sendKeys(deviceProfileTitle); |
|||
} |
|||
|
|||
public void changeDeviceProfile(String deviceProfileName) { |
|||
if (!selectExistingDeviceProfileRadioBtn().getAttribute("class").contains("checked")) { |
|||
selectExistingDeviceProfileRadioBtn().click(); |
|||
} |
|||
clearProfileFieldBtn().click(); |
|||
entityFromDropdown(deviceProfileName).click(); |
|||
} |
|||
|
|||
public void assignOnCustomer(String customerTitle) { |
|||
customerOptionBtn().click(); |
|||
assignOnCustomerField().click(); |
|||
customerFromDropDown(customerTitle).click(); |
|||
sleep(2); //waiting for the action to count
|
|||
} |
|||
|
|||
public void enterLabel(String label) { |
|||
enterText(deviceLabelField(), label); |
|||
} |
|||
|
|||
public void enterDescription(String description) { |
|||
enterText(descriptionField(), description); |
|||
} |
|||
} |
|||
@ -0,0 +1,160 @@ |
|||
/** |
|||
* 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 org.openqa.selenium.WebElement; |
|||
import org.testng.annotations.AfterClass; |
|||
import org.testng.annotations.BeforeClass; |
|||
import org.testng.annotations.BeforeMethod; |
|||
import org.testng.annotations.Test; |
|||
import org.thingsboard.server.common.data.Customer; |
|||
import org.thingsboard.server.common.data.Device; |
|||
import org.thingsboard.server.common.data.id.CustomerId; |
|||
import org.thingsboard.server.msa.ui.pages.CustomerPageHelper; |
|||
import org.thingsboard.server.msa.ui.tabs.AssignDeviceTabHelper; |
|||
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.ENTITY_NAME; |
|||
|
|||
public class AssignToCustomerTest extends AbstractDeviceTest { |
|||
|
|||
private AssignDeviceTabHelper assignDeviceTab; |
|||
private CustomerPageHelper customerPage; |
|||
private CustomerId customerId; |
|||
private Device device; |
|||
private String customerName; |
|||
|
|||
@BeforeClass |
|||
public void create() { |
|||
assignDeviceTab = new AssignDeviceTabHelper(driver); |
|||
customerPage = new CustomerPageHelper(driver); |
|||
Customer customer = testRestClient.postCustomer(EntityPrototypes.defaultCustomerPrototype(ENTITY_NAME + random())); |
|||
customerId = customer.getId(); |
|||
customerName = customer.getName(); |
|||
} |
|||
|
|||
@AfterClass |
|||
public void deleteCustomer() { |
|||
deleteCustomerById(customerId); |
|||
deleteCustomerByName("Public"); |
|||
} |
|||
|
|||
@BeforeMethod |
|||
public void createDevice() { |
|||
device = testRestClient.postDevice("", EntityPrototypes.defaultDevicePrototype(ENTITY_NAME)); |
|||
deviceName = device.getName(); |
|||
} |
|||
|
|||
@Test |
|||
public void assignToCustomerByRightSideBtn() { |
|||
sideBarMenuView.goToDevicesPage(); |
|||
devicePage.assignBtn(deviceName).click(); |
|||
assignDeviceTab.assignOnCustomer(customerName); |
|||
assertIsDisplayed(devicePage.deviceCustomerOnPage(deviceName)); |
|||
assertThat(devicePage.deviceCustomerOnPage(deviceName).getText()) |
|||
.as("Customer added correctly").isEqualTo(customerName); |
|||
|
|||
sideBarMenuView.customerBtn().click(); |
|||
customerPage.manageCustomersDevicesBtn(customerName).click(); |
|||
assertIsDisplayed(devicePage.device(deviceName)); |
|||
} |
|||
|
|||
@Test |
|||
public void assignToCustomerFromDetailsTab() { |
|||
sideBarMenuView.goToDevicesPage(); |
|||
devicePage.device(deviceName).click(); |
|||
devicePage.assignBtnDetailsTab().click(); |
|||
assignDeviceTab.assignOnCustomer(customerName); |
|||
String customerInAssignedField = devicePage.assignFieldDetailsTab().getAttribute("value"); |
|||
devicePage.closeDeviceDetailsViewBtn().click(); |
|||
assertIsDisplayed(devicePage.deviceCustomerOnPage(deviceName)); |
|||
assertThat(devicePage.deviceCustomerOnPage(deviceName).getText()) |
|||
.as("Customer added correctly").isEqualTo(customerName); |
|||
assertThat(customerInAssignedField) |
|||
.as("Customer in details tab added correctly").isEqualTo(customerName); |
|||
|
|||
sideBarMenuView.customerBtn().click(); |
|||
customerPage.manageCustomersDevicesBtn(customerName).click(); |
|||
assertIsDisplayed(devicePage.device(deviceName)); |
|||
} |
|||
|
|||
@Test |
|||
public void assignToCustomerMarkedDevice() { |
|||
sideBarMenuView.goToDevicesPage(); |
|||
devicePage.assignMarkedDevices(deviceName); |
|||
assignDeviceTab.assignOnCustomer(customerName); |
|||
assertIsDisplayed(devicePage.deviceCustomerOnPage(deviceName)); |
|||
assertThat(devicePage.deviceCustomerOnPage(deviceName).getText()) |
|||
.as("Customer added correctly").isEqualTo(customerName); |
|||
|
|||
sideBarMenuView.customerBtn().click(); |
|||
customerPage.manageCustomersDevicesBtn(customerName).click(); |
|||
assertIsDisplayed(devicePage.device(deviceName)); |
|||
} |
|||
|
|||
@Test |
|||
public void unassignedFromCustomerByRightSideBtn() { |
|||
device.setCustomerId(customerId); |
|||
testRestClient.postDevice("", device); |
|||
|
|||
sideBarMenuView.goToDevicesPage(); |
|||
WebElement element = devicePage.deviceCustomerOnPage(deviceName); |
|||
devicePage.unassignedDeviceByRightSideBtn(deviceName); |
|||
assertInvisibilityOfElement(element); |
|||
|
|||
sideBarMenuView.customerBtn().click(); |
|||
customerPage.manageCustomersDevicesBtn(customerName).click(); |
|||
devicePage.assertEntityIsNotPresent(deviceName); |
|||
} |
|||
|
|||
@Test |
|||
public void unassignedFromCustomerFromDetailsTab() { |
|||
device.setCustomerId(customerId); |
|||
testRestClient.postDevice("", device); |
|||
|
|||
sideBarMenuView.goToDevicesPage(); |
|||
WebElement customerInColumn = devicePage.deviceCustomerOnPage(deviceName); |
|||
devicePage.device(deviceName).click(); |
|||
WebElement assignFieldDetailsTab = devicePage.assignFieldDetailsTab(); |
|||
devicePage.unassignedDeviceFromDetailsTab(); |
|||
assertInvisibilityOfElement(customerInColumn); |
|||
assertInvisibilityOfElement(assignFieldDetailsTab); |
|||
|
|||
devicePage.closeDeviceDetailsViewBtn().click(); |
|||
sideBarMenuView.customerBtn().click(); |
|||
customerPage.manageCustomersDevicesBtn(customerName).click(); |
|||
devicePage.assertEntityIsNotPresent(deviceName); |
|||
} |
|||
|
|||
@Test |
|||
public void assignToSeveralCustomer() { |
|||
device.setCustomerId(customerId); |
|||
testRestClient.postDevice("", device); |
|||
sideBarMenuView.goToDevicesPage(); |
|||
|
|||
assertIsDisable(devicePage.assignBtnVisible(deviceName)); |
|||
} |
|||
|
|||
@Test |
|||
public void assignPublicDevice() { |
|||
testRestClient.setDevicePublic(device.getId()); |
|||
|
|||
sideBarMenuView.goToDevicesPage(); |
|||
assertIsDisable(devicePage.assignBtnVisible(deviceName)); |
|||
} |
|||
} |
|||
Loading…
Reference in new issue