Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Webhooks selenium tests #2911

Merged
merged 6 commits into from
Feb 24, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package org.openmetadata.catalog.selenium.objectRepository;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;

public class Webhooks {
WebDriver webDriver;

public Webhooks(WebDriver webDriver) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use lombok RequiredArgsConstructor

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated lombok @requiredargsconstructor

this.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;
}
}
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();
}
}