mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2025-12-27 15:38:43 +00:00
Added negative tests and added some assertions (#2825)
Co-authored-by: kushal <kushalshinde2512@gmail.com>
This commit is contained in:
parent
165f5bb0e9
commit
a9446e0209
@ -18,6 +18,26 @@ public class RolesPage {
|
||||
By accessValue = By.xpath("//tbody[@data-testid='table-body']/tr/td[2]/p");
|
||||
By deleteRuleButton = By.cssSelector("[data-testid='image'][title='Delete']");
|
||||
By rolesDisplayName = By.name("displayName");
|
||||
By errorMessage = By.xpath("//strong[@data-testid='error-message']");
|
||||
By addRule = By.xpath("//button[@data-testid='add-new-rule-button']");
|
||||
By operation = By.xpath("(//td[@class='tableBody-cell'])[1]");
|
||||
By access = By.xpath("(//td[@class='tableBody-cell'])[2]");
|
||||
|
||||
public By getOperation() {
|
||||
return operation;
|
||||
}
|
||||
|
||||
public By getAccess() {
|
||||
return access;
|
||||
}
|
||||
|
||||
public By getAddRuleButton() {
|
||||
return addRule;
|
||||
}
|
||||
|
||||
public By getErrorMessage() {
|
||||
return errorMessage;
|
||||
}
|
||||
|
||||
public By addRoleButton() {
|
||||
return addRoleButton;
|
||||
|
||||
@ -14,10 +14,11 @@ import org.openmetadata.catalog.selenium.events.Events;
|
||||
import org.openmetadata.catalog.selenium.objectRepository.Common;
|
||||
import org.openmetadata.catalog.selenium.objectRepository.RolesPage;
|
||||
import org.openmetadata.catalog.selenium.properties.Property;
|
||||
import org.openqa.selenium.WebDriver;
|
||||
import org.openqa.selenium.*;
|
||||
import org.openqa.selenium.chrome.ChromeDriver;
|
||||
import org.openqa.selenium.chrome.ChromeOptions;
|
||||
import org.openqa.selenium.interactions.Actions;
|
||||
import org.openqa.selenium.support.ui.ExpectedConditions;
|
||||
import org.openqa.selenium.support.ui.WebDriverWait;
|
||||
import org.testng.Assert;
|
||||
|
||||
@ -38,6 +39,9 @@ public class RolesPageTest {
|
||||
Integer waitTime = Property.getInstance().getSleepTime();
|
||||
String webDriverInstance = Property.getInstance().getWebDriver();
|
||||
String webDriverPath = Property.getInstance().getWebDriverPath();
|
||||
String xpath = "//p[@title = '" + roleDisplayName + "']";
|
||||
static String pageLoadStatus = null;
|
||||
JavascriptExecutor js;
|
||||
|
||||
@BeforeEach
|
||||
public void openMetadataWindow() {
|
||||
@ -54,6 +58,13 @@ public class RolesPageTest {
|
||||
webDriver.get(url);
|
||||
}
|
||||
|
||||
public void waitForPageLoad() {
|
||||
do {
|
||||
js = (JavascriptExecutor) webDriver;
|
||||
pageLoadStatus = (String) js.executeScript("return document.readyState");
|
||||
} while (!pageLoadStatus.equals("complete"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(1)
|
||||
public void openRolesPage() throws InterruptedException {
|
||||
@ -66,6 +77,7 @@ public class RolesPageTest {
|
||||
@Test
|
||||
@Order(2)
|
||||
public void addRole() throws InterruptedException {
|
||||
webDriver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
|
||||
openRolesPage();
|
||||
Events.click(webDriver, rolesPage.addRoleButton());
|
||||
Events.sendKeys(webDriver, common.displayName(), faker.name().firstName());
|
||||
@ -81,30 +93,50 @@ public class RolesPageTest {
|
||||
Events.click(webDriver, common.descriptionLinkButton());
|
||||
Events.sendKeys(webDriver, common.addDescriptionString(), faker.address().toString());
|
||||
Events.click(webDriver, common.descriptionSaveButton());
|
||||
webDriver.navigate().refresh();
|
||||
Thread.sleep(1000);
|
||||
WebElement role = wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath(xpath)));
|
||||
if (!role.isDisplayed()) {
|
||||
Assert.fail("Role not added");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(3)
|
||||
public void editDescription() throws InterruptedException {
|
||||
webDriver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
|
||||
String description = faker.address().toString();
|
||||
String roleName = "Data Consumer";
|
||||
openRolesPage();
|
||||
Events.click(webDriver, common.containsText(roleDisplayName));
|
||||
Events.click(webDriver, common.containsText(roleName));
|
||||
Events.click(webDriver, common.editTagCategoryDescription());
|
||||
Events.sendKeys(webDriver, common.addDescriptionString(), faker.address().toString());
|
||||
Events.sendKeys(webDriver, common.addDescriptionString(), Keys.CONTROL + "A");
|
||||
Events.sendKeys(webDriver, common.addDescriptionString(), description);
|
||||
Events.click(webDriver, common.editDescriptionSaveButton());
|
||||
Events.click(webDriver, common.containsText(roleName));
|
||||
String updatedDescription = webDriver.findElement(common.descriptionContainer()).getText();
|
||||
Assert.assertEquals(updatedDescription, description);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(4)
|
||||
public void addRules() throws InterruptedException {
|
||||
openRolesPage();
|
||||
Events.click(webDriver, common.containsText(roleDisplayName));
|
||||
Events.click(webDriver, common.noServicesAddServiceButton());
|
||||
String roleName = "Data Consumer";
|
||||
Events.click(webDriver, common.containsText(roleName));
|
||||
Events.click(webDriver, rolesPage.getAddRuleButton());
|
||||
Events.click(webDriver, rolesPage.listOperation());
|
||||
Events.click(webDriver, rolesPage.selectOperation("UpdateDescription"));
|
||||
Events.click(webDriver, rolesPage.listAccess());
|
||||
Events.click(webDriver, rolesPage.selectAccess("allow"));
|
||||
Events.click(webDriver, rolesPage.ruleToggleButton());
|
||||
Events.click(webDriver, common.descriptionSaveButton());
|
||||
Thread.sleep(1000);
|
||||
WebElement operation = webDriver.findElement(rolesPage.getOperation());
|
||||
WebElement access = webDriver.findElement(rolesPage.getAccess());
|
||||
if (!operation.isDisplayed() && !access.isDisplayed()) {
|
||||
Assert.fail("Rules not added");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -129,6 +161,88 @@ public class RolesPageTest {
|
||||
Events.click(webDriver, common.saveEditedService());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(7)
|
||||
public void checkBlankName() throws InterruptedException {
|
||||
webDriver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
|
||||
openRolesPage();
|
||||
Events.click(webDriver, rolesPage.addRoleButton());
|
||||
Events.sendKeys(webDriver, common.displayName(), "");
|
||||
Events.sendKeys(webDriver, rolesPage.rolesDisplayName(), roleDisplayName);
|
||||
Events.click(webDriver, common.descriptionBoldButton());
|
||||
Events.sendKeys(webDriver, common.addDescriptionString(), faker.address().toString());
|
||||
Events.click(webDriver, common.descriptionSaveButton());
|
||||
WebElement errorMessage = webDriver.findElement(rolesPage.getErrorMessage());
|
||||
if (errorMessage.isDisplayed()) {
|
||||
Assert.assertEquals(errorMessage.getText(), "Name is required");
|
||||
} else {
|
||||
Assert.fail("Error message not displayed");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(8)
|
||||
public void checkBlankDisplayName() throws InterruptedException {
|
||||
webDriver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
|
||||
openRolesPage();
|
||||
Events.click(webDriver, rolesPage.addRoleButton());
|
||||
Events.sendKeys(webDriver, common.displayName(), faker.name().firstName());
|
||||
Events.sendKeys(webDriver, rolesPage.rolesDisplayName(), "");
|
||||
Events.click(webDriver, common.descriptionBoldButton());
|
||||
Events.sendKeys(webDriver, common.addDescriptionString(), faker.address().toString());
|
||||
Events.click(webDriver, common.descriptionSaveButton());
|
||||
WebElement errorMessage = webDriver.findElement(rolesPage.getErrorMessage());
|
||||
if (errorMessage.isDisplayed()) {
|
||||
Assert.assertEquals(errorMessage.getText(), "Display name is required");
|
||||
} else {
|
||||
Assert.fail("Error message not displayed");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(9)
|
||||
public void checkDuplicateRoleName() throws InterruptedException {
|
||||
webDriver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
|
||||
String firstName = faker.name().firstName();
|
||||
openRolesPage();
|
||||
Events.click(webDriver, rolesPage.addRoleButton());
|
||||
Events.sendKeys(webDriver, common.displayName(), firstName);
|
||||
Events.sendKeys(webDriver, rolesPage.rolesDisplayName(), roleDisplayName);
|
||||
Events.sendKeys(webDriver, common.addDescriptionString(), faker.address().toString());
|
||||
Events.click(webDriver, common.descriptionSaveButton());
|
||||
Thread.sleep(waitTime);
|
||||
webDriver.navigate().refresh();
|
||||
Events.click(webDriver, rolesPage.addRoleButton());
|
||||
Events.sendKeys(webDriver, common.displayName(), firstName);
|
||||
Events.sendKeys(webDriver, rolesPage.rolesDisplayName(), roleDisplayName);
|
||||
Events.sendKeys(webDriver, common.addDescriptionString(), faker.address().toString());
|
||||
Events.click(webDriver, common.descriptionSaveButton());
|
||||
WebElement errorMessage = webDriver.findElement(rolesPage.getErrorMessage());
|
||||
if (errorMessage.isDisplayed()) {
|
||||
Assert.assertEquals(errorMessage.getText(), "Name already exists");
|
||||
} else {
|
||||
Assert.fail("Error message not displayed");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(10)
|
||||
public void addRuleWithoutOperation() throws InterruptedException {
|
||||
addRole();
|
||||
Events.click(webDriver, common.containsText(roleDisplayName));
|
||||
Events.click(webDriver, rolesPage.getAddRuleButton());
|
||||
Events.click(webDriver, rolesPage.listAccess());
|
||||
Events.click(webDriver, rolesPage.selectAccess("allow"));
|
||||
Events.click(webDriver, rolesPage.ruleToggleButton());
|
||||
Events.click(webDriver, common.descriptionSaveButton());
|
||||
WebElement errorMessage = webDriver.findElement(rolesPage.getErrorMessage());
|
||||
if (errorMessage.isDisplayed()) {
|
||||
Assert.assertEquals(errorMessage.getText(), "Operation is required.");
|
||||
} else {
|
||||
Assert.fail("Rule added without selecting operation");
|
||||
}
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void closeTabs() {
|
||||
ArrayList<String> tabs = new ArrayList<>(webDriver.getWindowHandles());
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user