github.com/siglens/siglens@v0.0.0-20240328180423-f7ce9ae441ed/selenium-tests/tests/panelEditScreen-test.js (about) 1 /* 2 Copyright 2023. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 const {By,Key,Builder, until, WebDriverWait} = require("selenium-webdriver"); 18 const assert = require("assert"); 19 const chrome = require('selenium-webdriver/chrome'); 20 let driver; 21 const chromeOptions = new chrome.Options() 22 23 async function testEditPanelScreenOptions(){ 24 25 //To wait for browser to build and launch properly 26 driver = await new Builder().forBrowser("chrome") 27 .setChromeOptions(chromeOptions) 28 .build(); 29 30 //To fetch http://localhost/dashboards-home.html from the browser with our code. 31 await driver.get("http://localhost:5122/dashboards-home.html"); 32 33 let newDbBtn = await driver.findElement(By.id("create-db-btn")); 34 await newDbBtn.click(); 35 // check if Dashboard is created 36 let dbName = "ABC"; 37 let dbNameInput = await driver.findElement(By.id("db-name")); 38 let dbDescInput = await driver.findElement(By.id("db-description")); 39 let saveDbBtn = await driver.findElement(By.id("save-dbbtn")); 40 41 await dbNameInput.sendKeys(dbName); 42 await dbDescInput.sendKeys("This is a test description"); 43 await saveDbBtn.click(); 44 45 await driver.wait(until.urlContains('dashboard.html'), 5000); 46 let currentUrl = await driver.getCurrentUrl(); 47 assert(currentUrl.includes("dashboard.html"), `URL ${currentUrl} does not contain "dashboard.html"`); 48 await driver.sleep(1000); 49 let addPanelBtn = await driver.findElement(By.id("add-panel-btn")); 50 await addPanelBtn.click(); 51 52 let panelOptionsBtn = await driver.findElement(By.id("panel-options-btn")); 53 await panelOptionsBtn.click(); 54 55 // Loop through the items and log their text 56 let panelViewBtn = await driver.findElement(By.css(".panel-view-li")); 57 const panelViewText = await panelViewBtn.getText(); 58 assert.equal(panelViewText, "View", 'button text is not "View"'); 59 await panelViewBtn.click(); 60 viewPanelModal = await driver.findElement(By.css(".panel")); 61 let viewPanelModalPresent = await viewPanelModal.isDisplayed(); 62 assert.equal(viewPanelModalPresent, true, 'view-panel-modal is not displayed'); 63 panelOptionsBtn = await driver.findElement(By.id("panel-options-btn")); 64 await panelOptionsBtn.click(); 65 let panelEditBtn = await driver.findElement(By.css(".panel-edit-li")); 66 const panelEditText = await panelEditBtn.getText(); 67 assert.equal(panelEditText, "Edit", 'button text is not "Edit"'); 68 69 await panelEditBtn.click(); 70 let EditPanelScreenModal = await driver.findElement(By.css(".panelEditor-container")); 71 let EditPanelScreenModalPresent = await EditPanelScreenModal.isDisplayed(); 72 assert.equal(EditPanelScreenModalPresent, true, 'EditPanelScreenModal is not displayed'); 73 74 // Check all buttons and options in edit panel screen 75 let discardBtn = await driver.findElement(By.id("discard-btn")); 76 let saveBtn = await driver.findElement(By.id("save-btn")); 77 let applyBtn = await driver.findElement(By.id("apply-btn")); 78 79 assert(await discardBtn.isDisplayed(), 'discardBtn is not displayed'); 80 assert(await saveBtn.isDisplayed(), 'saveBtn is not displayed'); 81 assert(await applyBtn.isDisplayed(), 'applyBtn is not displayed'); 82 83 assert(discardBtn.isEnabled(), 'discardBtn is not enabled'); 84 assert(saveBtn.isEnabled(), 'saveBtn is not enabled'); 85 assert(applyBtn.isEnabled(), 'applyBtn is not enabled'); 86 87 assert (await discardBtn.getText() == "Discard", 'discardBtn text is not "Discard"'); 88 assert (await saveBtn.getText() == "Save", 'saveBtn text is not "Save"'); 89 assert (await applyBtn.getText() == "Apply", 'applyBtn text is not "Apply"'); 90 91 // let timePickerBtn = await driver.findElement(By.id("date-picker-btn")); 92 // assert.equal(timePickerBtn.getText(), "Time Picker", 'button text is not "Time Picker"'); 93 94 //test data source options 95 let dataSourceBtn = await driver.findElement(By.css(".dropDownTitle")); 96 await dataSourceBtn.click(); 97 await driver.sleep(1000); 98 const dataSourcelist = await driver.findElement(By.css('ul.editPanelMenu-dataSource')); 99 await driver.wait(until.elementIsVisible(dataSourcelist), 5000); 100 let dataSourceOptions = await dataSourcelist.findElements(By.tagName('li')); 101 let expectedDataSourceOptions = ["Metrics", "Logs", "Traces"]; 102 let actualDataSourceOptions = []; 103 for (const item of dataSourceOptions) { 104 const text = await item.getText(); 105 actualDataSourceOptions.push(text); 106 } 107 assert.deepEqual(actualDataSourceOptions, expectedDataSourceOptions, 'dataSourceOptions are not as expected'); 108 109 // test name and Description fields 110 let nameInput = await driver.findElement(By.id("panEdit-nameChangeInput")); 111 let descriptionInput = await driver.findElement(By.id("panEdit-descrChangeInput")); 112 assert.equal(await nameInput.getAttribute("placeholder"), "Name", 'nameInput placeholder is not "Enter Panel Name"'); 113 assert.equal(await descriptionInput.getAttribute("placeholder"), "Description (Optional)", 'descriptionInput placeholder is not "Enter Panel Description"'); 114 115 // test panel type options 116 let chartTypeBtn = await driver.findElement(By.css(".dropDown-chart")); 117 chartTypeBtn.click(); 118 await driver.sleep(1000); 119 const chartTypeList = await driver.findElement(By.css('ul.editPanelMenu-chart')); 120 await driver.wait(until.elementIsVisible(chartTypeList), 5000); 121 let chartTypeOptions = await chartTypeList.findElements(By.tagName('li')); 122 123 let expectedPanelChartTypeOptions = ["Line", "Bar", "Pie", "Log Lines", "Number"]; 124 let actualPanelChartTypeOptions = []; 125 for (const item of chartTypeOptions) { 126 const text = await item.getText(); 127 actualPanelChartTypeOptions.push(text); 128 } 129 assert.deepEqual(actualPanelChartTypeOptions, expectedPanelChartTypeOptions, 'panelTypeOptions are not as expected'); 130 131 //todo test unit options(add when all the options are added) 132 console.log("All Edit panel screen tests passed") 133 } 134 135 testEditPanelScreenOptions();