github.com/siglens/siglens@v0.0.0-20240328180423-f7ce9ae441ed/selenium-tests/tests/contacts-test.js (about) 1 const { By, Key, Builder, until } = require("selenium-webdriver"); 2 const assert = require("assert"); 3 const chrome = require("selenium-webdriver/chrome"); 4 let driver; 5 const chromeOptions = new chrome.Options(); 6 7 chromeOptions.addArguments("--headless"); 8 9 async function testContactsPage() { 10 try { 11 driver = await new Builder() 12 .forBrowser("chrome") 13 .setChromeOptions(chromeOptions) 14 .build(); 15 16 await driver.get("http://localhost:5122/contacts.html"); 17 18 let alertingHeader = await driver.findElement(By.css(".myOrg-heading")).getText(); 19 assert.equal(alertingHeader, "Alerting", "Alerting header text is not correct"); 20 21 let addContactButton = await driver.findElement(By.id("new-contact-point")); 22 await addContactButton.click(); 23 24 let contactFormDisplayed = await driver.findElement(By.id("contact-form-container")).isDisplayed(); 25 assert.equal(contactFormDisplayed, true, 'Contact form container is not displayed after clicking "Add Contact Point"'); 26 27 // Additional Tests for the Contact Form 28 let contactNameInput = await driver.findElement(By.id("contact-name")); 29 await contactNameInput.sendKeys("Test Contact Name"); 30 let contactNameValue = await contactNameInput.getAttribute('value'); 31 assert.equal(contactNameValue, "Test Contact Name", "Contact name input value is not correct"); 32 33 // Test Dropdown for Contact Types 34 let contactTypeDropdown = await driver.findElement(By.id("contact-types")); 35 await contactTypeDropdown.click(); 36 let slackOption = await driver.findElement(By.id("option-0")); 37 await slackOption.click(); 38 39 // Test Slack Channel ID Input 40 let slackChannelInput = await driver.findElement(By.id("slack-channel-id")); 41 await slackChannelInput.sendKeys("123456"); 42 let slackChannelValue = await slackChannelInput.getAttribute('value'); 43 assert.equal(slackChannelValue, "123456", "Slack channel ID input value is not correct"); 44 45 // Test Slack Token Input 46 let slackTokenInput = await driver.findElement(By.id("slack-token")); 47 await slackTokenInput.sendKeys("Token123"); 48 let slackTokenValue = await slackTokenInput.getAttribute('value'); 49 assert.equal(slackTokenValue, "Token123", "Slack token input value is not correct"); 50 51 // Test Save Button Functionality 52 let saveContactButton = await driver.findElement(By.id("save-contact-btn")); 53 await saveContactButton.click(); 54 55 await driver.get("http://localhost:5122/contacts.html"); 56 57 await driver.sleep(10000); // 5000 milliseconds = 5 seconds 58 59 60 let addedContact = await driver.findElement(By.xpath("//span[contains(@class, 'ag-cell-value')]")); 61 let isContactAdded = await addedContact.isDisplayed(); 62 assert.equal(isContactAdded, true, "New contact was not added to the table"); 63 64 console.log("All contacts page tests passed"); 65 } catch (err) { 66 console.error(err); 67 } finally { 68 await driver.quit(); 69 } 70 } 71 72 testContactsPage();