github.com/siglens/siglens@v0.0.0-20240328180423-f7ce9ae441ed/selenium-tests/tests/index-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} = 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 testIndexPageButtons(){ 26 try{ 27 //To wait for browser to build and launch properly 28 driver = await new Builder().forBrowser("chrome") 29 .setChromeOptions(chromeOptions) 30 .build(); 31 32 //To fetch http://localhost/index.html from the browser with our code. 33 34 await driver.get("http://localhost:5122/index.html"); 35 36 // To find search buttons on the index.html page 37 38 let indexButton = await driver.findElement(By.id("index-btn")); 39 let indexTxt = await indexButton.getText(); 40 let datePickerBtn = await driver.findElement(By.id("date-picker-btn")); 41 let datePickerTxt = await datePickerBtn.getText(); 42 // let saveQueryBtn = await driver.findElement(By.id("saveq-btn")); 43 // let saveQueryTxt = await saveQueryBtn.getText(); 44 // let availableFieldBtn = await driver.findElement(By.id("avail-fields-btn")); 45 // let availableFieldTxt = await availableFieldBtn.getText(); 46 let searchButton = await driver.findElement(By.id("run-filter-btn")); 47 let btnTxt = await searchButton.getText(); 48 49 assert.equal(btnTxt, "Search", 'button text is not "Search"'); 50 assert.equal(indexTxt, "Index", 'button text is not "Index"'); 51 assert.equal(datePickerTxt, "Last 15 Mins", 'button text is not "Date Picker"'); 52 // assert.equal(saveQueryTxt, "Save Query", 'button text is not "Save Query"'); 53 // assert.equal(availableFieldTxt, " Available Fields", 'button text is not "Available Fields"'); 54 55 // check if the dropdowns are displayed 56 let dropdownPresent; 57 await indexButton.click(); 58 dropdownPresent = await driver.findElement(By.id("available-indexes")).isDisplayed(); 59 assert.equal(dropdownPresent, true, 'available-indexes is not displayed'); 60 await indexButton.click(); 61 62 await datePickerBtn.click(); 63 dropdownPresent = await driver.findElement(By.id("daterangepicker ")).isDisplayed(); 64 assert.equal(dropdownPresent, true, 'daterangepicker is not displayed'); 65 await datePickerBtn.click(); 66 67 // await availableFieldBtn.click(); 68 // dropdownPresent = await driver.findElement(By.id("available-fields")).isDisplayed(); 69 // assert.equal(dropdownPresent, true, 'available-fields is not displayed'); 70 // await availableFieldBtn.click(); 71 console.log("All buttons tests passed") 72 }catch (err) { 73 // Handle any errors that occur during test execution 74 console.error(err); 75 76 } finally { 77 // Close the driver instance, even if an error occurred 78 // await driver.quit(); 79 } 80 } 81 82 testIndexPageButtons(); 83 84 async function testSearchInvalidQuery(){ 85 try{ 86 //To wait for browser to build and launch properly 87 driver = await new Builder().forBrowser("chrome") 88 .setChromeOptions(chromeOptions) 89 .build(); 90 91 //To fetch http://localhost/index.html from the browser with our code. 92 await driver.get("http://localhost:5122/index.html"); 93 94 // Enter text in the search box 95 let searchBox = await driver.findElement(By.id("filter-input")); 96 97 // get the placeholder text using the getAttribute method 98 let placeholderText = await searchBox.getAttribute('placeholder'); 99 100 // type the search query using the sendKeys method 101 // test invalid query 102 await searchBox.sendKeys('derf(1234'); 103 await driver.sleep(500); 104 // submit the search by pressing Enter 105 await searchBox.sendKeys(Key.RETURN); 106 let cornerText = await driver.findElement(By.id("corner-text")).getText(); 107 let closeBtn = await driver.findElement(By.id("close-btn")); 108 assert.equal(cornerText, 'Message: 1:5 (4): no match found, expected: "!=", ".", "<", "<=", "=", ">", ">=", "|", [ \\n\\t\\r], [-a-zA-Z0-9$&,?#%_@;[\\]{}+-./*:]i or EOF', "Invalid Query"); 109 110 closeBtn.click(); 111 await driver.sleep(5000); 112 // test query with no results 113 await searchBox.clear(); 114 await searchBox.sendKeys('test'); 115 await searchBox.sendKeys(Key.RETURN); 116 117 let emptyResponse = await driver.findElement(By.id("empty-response")); 118 let emptyResponseText = await emptyResponse.getText(); 119 120 assert.equal(emptyResponseText, 'Your query returned no data, adjust your query.', "No results found for your query"); 121 await driver.sleep(10000); 122 console.log("All search query test passed") 123 124 }catch (err) { 125 // Handle any errors that occur during test execution 126 console.error(err); 127 128 } finally { 129 // Close the driver instance, even if an error occurred 130 await driver.quit(); 131 } 132 } 133 134 testSearchInvalidQuery();