github.com/siglens/siglens@v0.0.0-20240328180423-f7ce9ae441ed/selenium-tests/tests/saved-queries-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  chromeOptions.addArguments('--headless');
    24  
    25  async function testSavedQueriesPageButtons(){
    26      try{
    27          driver = await new Builder().forBrowser("chrome")
    28                                      .setChromeOptions(chromeOptions)
    29                                      .build();
    30                                      
    31          await driver.get("http://localhost:5122/saved-queries.html");
    32  
    33          let searchButton = await driver.findElement(By.id("search-query-btn"));
    34          let btnTxt = await searchButton.getText();
    35          assert.equal(btnTxt, "Search", 'button text is not "Search"');
    36  
    37          let queriesGrid = await driver.findElement(By.id("queries-grid"));  
    38          let queriesGridPresent = await queriesGrid.isDisplayed();
    39          assert.equal(queriesGridPresent, true, 'queries-grid is not displayed');
    40  
    41          const initialAgGridRows = await driver.findElements(By.css('.ag-row'));
    42          assert(initialAgGridRows.length >=0, 'No rows found in the ag-Grid');
    43  
    44          if (initialAgGridRows.length > 0)
    45          {
    46              let delQueryBtn = await driver.findElement(By.id("delbutton"));
    47              await delQueryBtn.click();
    48              let deleteQueryModal = await driver.findElement(By.id("del-sq-popup"));
    49              let deleteQueryModalPresent = await deleteQueryModal.isDisplayed();
    50              assert.equal(deleteQueryModalPresent, true, 'delete-query-modal is not displayed');
    51              let deleteSQBtn = await driver.findElement(By.id("delete-btn"));
    52              let cancelSQBtn = await driver.findElement(By.id("cancel-btn"));
    53  
    54              await cancelSQBtn.click();
    55              await driver.sleep(1000);
    56              let currentAgGridRows = await driver.findElements(By.css('.ag-row'));
    57              assert.equal(initialAgGridRows.length ,currentAgGridRows.length, 'cancel button does not work')
    58  
    59              await delQueryBtn.click();
    60  
    61              await deleteSQBtn.click();
    62              await driver.sleep(1000);
    63              currentAgGridRows = await driver.findElements(By.css('.ag-row'));
    64              assert.notEqual(initialAgGridRows.length ,currentAgGridRows.length, 'delete button does not work');
    65          }
    66          console.log("All saved queries screen tests passed");
    67  
    68      }catch (err) {
    69          console.error(err);
    70      
    71      } finally {
    72          await driver.quit();
    73      }
    74  }
    75  
    76  testSavedQueriesPageButtons();