-
Notifications
You must be signed in to change notification settings - Fork 876
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding Webhooks selenium tests (#2911)
* Adding Webhooks selenium tests * Adding java checkstyle * Changed assertions based on comments * Added @requiredargsconstructor * Adding java checkstyle Co-authored-by: kushal <kushalshinde2512@gmail.com>
- Loading branch information
1 parent
6a2180e
commit 9dd8598
Showing
2 changed files
with
235 additions
and
0 deletions.
There are no files selected for viewing
67 changes: 67 additions & 0 deletions
67
...etadata-ui/src/test/java/org/openmetadata/catalog/selenium/objectRepository/Webhooks.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package org.openmetadata.catalog.selenium.objectRepository; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.openqa.selenium.By; | ||
import org.openqa.selenium.WebDriver; | ||
|
||
@RequiredArgsConstructor | ||
public class Webhooks { | ||
@NotNull WebDriver webDriver; | ||
|
||
By webhookLink = By.linkText("Webhooks"); | ||
By addWebhook = By.xpath("//button[@data-testid='add-webhook-button']"); | ||
By name = By.xpath("//input[@data-testid='name']"); | ||
By descriptionBox = By.xpath("//div[@class='notranslate public-DraftEditor-content']"); | ||
By endpoint = By.xpath("//input[@data-testid='endpoint-url']"); | ||
By checkbox = By.xpath("//input[@data-testid='checkbox']"); | ||
By entityCreatedMenu = By.xpath("(//button[@id='menu-button-select entities'])[1]"); | ||
By allEntities = By.xpath("(//input[@type='checkbox'])[2]"); | ||
By saveWebhook = By.xpath("//button[@data-testid='save-webhook']"); | ||
By checkWebhook = By.xpath("//button[@data-testid='webhook-link']"); | ||
By toast = By.xpath("(//div[@data-testid='toast']/div)[2]"); | ||
|
||
public By getToast() { | ||
return toast; | ||
} | ||
|
||
public By checkWebhook() { | ||
return checkWebhook; | ||
} | ||
|
||
public By getSaveWebhook() { | ||
return saveWebhook; | ||
} | ||
|
||
public By allEntities() { | ||
return allEntities; | ||
} | ||
|
||
public By getEntityCreatedMenu() { | ||
return entityCreatedMenu; | ||
} | ||
|
||
public By checkbox() { | ||
return checkbox; | ||
} | ||
|
||
public By getEndpoint() { | ||
return endpoint; | ||
} | ||
|
||
public By getDescriptionBox() { | ||
return descriptionBox; | ||
} | ||
|
||
public By name() { | ||
return name; | ||
} | ||
|
||
public By webhookLink() { | ||
return webhookLink; | ||
} | ||
|
||
public By addWebhook() { | ||
return addWebhook; | ||
} | ||
} |
168 changes: 168 additions & 0 deletions
168
...a-ui/src/test/java/org/openmetadata/catalog/selenium/pages/Webhooks/WebhooksPageTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,168 @@ | ||
package org.openmetadata.catalog.selenium.pages.Webhooks; | ||
|
||
import com.github.javafaker.Faker; | ||
import java.time.Duration; | ||
import java.util.ArrayList; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.openmetadata.catalog.selenium.events.*; | ||
import org.openmetadata.catalog.selenium.objectRepository.*; | ||
import org.openmetadata.catalog.selenium.properties.*; | ||
import org.openqa.selenium.WebDriver; | ||
import org.openqa.selenium.WebElement; | ||
import org.openqa.selenium.chrome.ChromeDriver; | ||
import org.openqa.selenium.chrome.ChromeOptions; | ||
import org.openqa.selenium.interactions.Actions; | ||
import org.openqa.selenium.support.ui.WebDriverWait; | ||
import org.testng.Assert; | ||
|
||
public class WebhooksPageTest { | ||
|
||
static WebDriver webDriver; | ||
static Common common; | ||
static Webhooks webhooks; | ||
static String url = Property.getInstance().getURL(); | ||
static Faker faker = new Faker(); | ||
static Actions actions; | ||
static WebDriverWait wait; | ||
Integer waitTime = Property.getInstance().getSleepTime(); | ||
String webDriverInstance = Property.getInstance().getWebDriver(); | ||
String webDriverPath = Property.getInstance().getWebDriverPath(); | ||
|
||
@BeforeEach | ||
public void openMetadataWindow() { | ||
System.setProperty(webDriverInstance, webDriverPath); | ||
ChromeOptions options = new ChromeOptions(); | ||
options.addArguments("--headless"); | ||
options.addArguments("--window-size=1280,800"); | ||
webDriver = new ChromeDriver(); | ||
common = new Common(webDriver); | ||
webhooks = new Webhooks(webDriver); | ||
actions = new Actions(webDriver); | ||
wait = new WebDriverWait(webDriver, Duration.ofSeconds(30)); | ||
webDriver.manage().window().maximize(); | ||
webDriver.get(url); | ||
} | ||
|
||
@Test | ||
void openWebHookPage() { | ||
Events.click(webDriver, common.closeWhatsNew()); // Close What's new | ||
Events.click(webDriver, common.headerSettings()); // Setting | ||
Events.click(webDriver, webhooks.webhookLink()); | ||
} | ||
|
||
@Test | ||
void addWebHook() throws InterruptedException { | ||
String name = faker.name().name(); | ||
webDriver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10)); | ||
openWebHookPage(); | ||
Events.click(webDriver, webhooks.addWebhook()); | ||
Events.sendKeys(webDriver, webhooks.name(), name); | ||
Events.click(webDriver, webhooks.getDescriptionBox()); | ||
Events.sendKeys(webDriver, webhooks.getDescriptionBox(), "test"); | ||
Events.sendKeys(webDriver, webhooks.getEndpoint(), "test.com"); | ||
Events.click(webDriver, webhooks.checkbox()); | ||
Thread.sleep(waitTime); | ||
Events.click(webDriver, webhooks.getEntityCreatedMenu()); | ||
Events.click(webDriver, webhooks.allEntities()); | ||
actions.click(); | ||
actions.perform(); | ||
Events.click(webDriver, webhooks.getSaveWebhook()); | ||
WebElement checkName = webDriver.findElement(webhooks.checkWebhook()); | ||
Assert.assertTrue(checkName.isDisplayed()); | ||
Assert.assertEquals(checkName.getText(), name); | ||
} | ||
|
||
@Test | ||
void checkDuplicateWebhookName() { | ||
String name = faker.name().name(); | ||
webDriver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10)); | ||
openWebHookPage(); | ||
for (int i = 0; i < 2; i++) { | ||
Events.click(webDriver, webhooks.addWebhook()); | ||
Events.sendKeys(webDriver, webhooks.name(), name); | ||
Events.click(webDriver, webhooks.getDescriptionBox()); | ||
Events.sendKeys(webDriver, webhooks.getDescriptionBox(), "test"); | ||
Events.sendKeys(webDriver, webhooks.getEndpoint(), "test.com"); | ||
Events.click(webDriver, webhooks.checkbox()); | ||
Events.click(webDriver, webhooks.getEntityCreatedMenu()); | ||
Events.click(webDriver, webhooks.allEntities()); | ||
actions.click(); | ||
actions.perform(); | ||
Events.click(webDriver, webhooks.getSaveWebhook()); | ||
} | ||
WebElement errorMessage = webDriver.findElement(webhooks.getToast()); | ||
Assert.assertTrue(errorMessage.isDisplayed()); | ||
Assert.assertEquals(errorMessage.getText(), "Request failed with status code 409"); | ||
} | ||
|
||
@Test | ||
void checkBlankName() throws InterruptedException { | ||
webDriver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10)); | ||
openWebHookPage(); | ||
Events.click(webDriver, webhooks.addWebhook()); | ||
Events.sendKeys(webDriver, webhooks.name(), ""); | ||
Events.click(webDriver, webhooks.getDescriptionBox()); | ||
Events.sendKeys(webDriver, webhooks.getDescriptionBox(), "test"); | ||
Events.sendKeys(webDriver, webhooks.getEndpoint(), "test.com"); | ||
Events.click(webDriver, webhooks.checkbox()); | ||
Thread.sleep(waitTime); | ||
Events.click(webDriver, webhooks.getEntityCreatedMenu()); | ||
Events.click(webDriver, webhooks.allEntities()); | ||
actions.click(); | ||
actions.perform(); | ||
Events.click(webDriver, webhooks.getSaveWebhook()); | ||
WebElement errorMessage = webDriver.findElement(common.errorMessage()); | ||
Assert.assertTrue(errorMessage.isDisplayed()); | ||
Assert.assertEquals(errorMessage.getText(), "Webhook name is required."); | ||
} | ||
|
||
@Test | ||
void checkBlankEndpoint() { | ||
webDriver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10)); | ||
openWebHookPage(); | ||
Events.click(webDriver, webhooks.addWebhook()); | ||
Events.sendKeys(webDriver, webhooks.name(), "test"); | ||
Events.click(webDriver, webhooks.getDescriptionBox()); | ||
Events.sendKeys(webDriver, webhooks.getDescriptionBox(), "test"); | ||
Events.sendKeys(webDriver, webhooks.getEndpoint(), ""); | ||
Events.click(webDriver, webhooks.checkbox()); | ||
Events.click(webDriver, webhooks.getEntityCreatedMenu()); | ||
Events.click(webDriver, webhooks.allEntities()); | ||
actions.click(); | ||
actions.perform(); | ||
Events.click(webDriver, webhooks.getSaveWebhook()); | ||
WebElement errorMessage = webDriver.findElement(common.errorMessage()); | ||
Assert.assertTrue(errorMessage.isDisplayed()); | ||
Assert.assertEquals(errorMessage.getText(), "Webhook endpoint is required."); | ||
} | ||
|
||
@Test | ||
void checkBlankEntityCheckbox() { | ||
webDriver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10)); | ||
openWebHookPage(); | ||
Events.click(webDriver, webhooks.addWebhook()); | ||
Events.sendKeys(webDriver, webhooks.name(), "test"); | ||
Events.click(webDriver, webhooks.getDescriptionBox()); | ||
Events.sendKeys(webDriver, webhooks.getDescriptionBox(), "test"); | ||
Events.sendKeys(webDriver, webhooks.getEndpoint(), "test.com"); | ||
Events.click(webDriver, webhooks.getSaveWebhook()); | ||
WebElement errorMessage = webDriver.findElement(common.errorMessage()); | ||
Assert.assertTrue(errorMessage.isDisplayed()); | ||
Assert.assertEquals(errorMessage.getText(), "Webhook event filters are required."); | ||
} | ||
|
||
@AfterEach | ||
public void closeTabs() { | ||
ArrayList<String> tabs = new ArrayList<>(webDriver.getWindowHandles()); | ||
String originalHandle = webDriver.getWindowHandle(); | ||
for (String handle : webDriver.getWindowHandles()) { | ||
if (!handle.equals(originalHandle)) { | ||
webDriver.switchTo().window(handle); | ||
webDriver.close(); | ||
} | ||
} | ||
webDriver.switchTo().window(tabs.get(0)).close(); | ||
} | ||
} |