github.com/siglens/siglens@v0.0.0-20240328180423-f7ce9ae441ed/selenium-tests/tests/all-alerts-test.js (about) 1 const { By, Key, Builder, until } = require("selenium-webdriver"); 2 const assert = require("assert"); 3 const fs =require("fs"); 4 const chrome = require("selenium-webdriver/chrome"); 5 let driver; 6 const chromeOptions = new chrome.Options(); 7 8 chromeOptions.addArguments("--headless"); 9 10 async function testAllAlertsPage() { 11 try { 12 driver = await new Builder() 13 .forBrowser("chrome") 14 .setChromeOptions(chromeOptions) 15 .build(); 16 17 await driver.get("http://localhost:5122/all-alerts.html"); 18 19 // Test presence and click of "Add Alert Rule" button 20 let addAlertRuleButton = await driver.findElement(By.id("new-alert-rule")); 21 await addAlertRuleButton.click(); 22 23 // Wait for form to appear 24 await driver.wait(until.elementLocated(By.id("alert-form")), 5000); 25 26 // Interact with form elements 27 28 // Fill in the Rule Name 29 let ruleNameInput = await driver.findElement(By.id("alert-rule-name")); 30 await ruleNameInput.sendKeys("Test Alert Rule"); 31 32 // Select from dropdown (example with data source dropdown) 33 let dataSourceDropdown = await driver.findElement(By.id("alert-data-source")); 34 await dataSourceDropdown.click(); 35 let logsOption = await driver.findElement(By.id("option-1")); 36 await logsOption.click(); 37 38 // Fill in the Query 39 let queryInput = await driver.findElement(By.id("query")); 40 await queryInput.sendKeys("city=Boston | stats count"); 41 42 // Select condition from dropdown 43 let conditionDropdown = await driver.findElement(By.id("alert-condition")); 44 await conditionDropdown.click(); 45 let conditionOption = await driver.findElement(By.id("option-0")); 46 await conditionOption.click(); 47 48 // Fill in threshold value 49 let thresholdInput = await driver.findElement(By.id("threshold-value")); 50 await thresholdInput.sendKeys("100"); 51 52 // Fill in evaluation interval 53 let evaluationInput = await driver.findElement(By.id("evaluate-every")); 54 await evaluationInput.sendKeys("5"); 55 56 // Fill in notification message 57 let messageInput = await driver.findElement(By.id("notification-msg")); 58 await messageInput.sendKeys("Alert triggered!"); 59 60 // Click on Save button 61 let saveButton = await driver.findElement(By.id("save-alert-btn")); 62 await saveButton.click(); 63 64 await driver.get("http://localhost:5122/all-alerts.html"); 65 66 await driver.sleep(10000); // 5000 milliseconds = 5 seconds 67 68 69 70 let newAlertRule = await driver.findElement(By.xpath("//span[contains(@class, 'ag-cell-value')]")) 71 72 let isAlertRuleAdded = await newAlertRule.isDisplayed(); 73 assert.equal(isAlertRuleAdded, true, "New alert rule was not added to the table"); 74 75 console.log("All alerts page tests passed"); 76 } catch (err) { 77 console.error(err); 78 } finally { 79 await driver.quit(); 80 } 81 } 82 83 testAllAlertsPage();