|
| 1 | +const { By, Key, Builder, WebElement } = 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 | +chromeOptions.addArguments('--headless'); |
| 7 | + |
| 8 | +async function checkIncrementor(Component){ |
| 9 | + const initialValue = await Component.getAttribute('value'); |
| 10 | + // Attempt to increment the value |
| 11 | + await Component.sendKeys(Key.ARROW_UP); |
| 12 | + // Get the value after incrementing |
| 13 | + const incrementedValue = await Component.getAttribute('value'); |
| 14 | + // Assert that the value has been incremented |
| 15 | + assert.notStrictEqual(incrementedValue, initialValue, 'Failed to increment the number input.'); |
| 16 | + // Attempt to decrement the value |
| 17 | + await Component.sendKeys(Key.ARROW_DOWN); |
| 18 | + // Get the value after decrementing |
| 19 | + const decrementedValue = await Component.getAttribute('value'); |
| 20 | + assert.notStrictEqual(decrementedValue, incrementedValue, 'Failed to decrement the number input.'); |
| 21 | + |
| 22 | +} |
| 23 | +async function testAlertPagesButtons() { |
| 24 | + try{ |
| 25 | + driver = await new Builder().forBrowser("chrome") |
| 26 | + .setChromeOptions(chromeOptions) |
| 27 | + .build(); |
| 28 | + |
| 29 | + //To fetch http://localhost/alert.html from the browser with our code. |
| 30 | + |
| 31 | + await driver.get("http://localhost/alert.html"); |
| 32 | + let cancelBtn = driver.findElement(By.id("cancel-alert-btn")); |
| 33 | + let cancelTxt = await cancelBtn.getText(); |
| 34 | + let saveBtn = driver.findElement(By.id("save-alert-btn")); |
| 35 | + let saveTxt = await saveBtn.getText(); |
| 36 | + |
| 37 | + // Checks for cancel and save button existance |
| 38 | + assert.equal(cancelTxt, "Cancel", 'button text is not "Cancel"'); |
| 39 | + assert.equal(saveTxt, "Save", 'button text is not "Save"'); |
| 40 | + |
| 41 | + // checks if Alert Rule Text is editable |
| 42 | + let alertRuleInputTextBox = await driver.findElement(By.id("alert-rule-name")); |
| 43 | + const checkAlertRuleEditable = await alertRuleInputTextBox.isEnabled(); |
| 44 | + assert.strictEqual(checkAlertRuleEditable, true, 'alert rule input text box is not editable'); |
| 45 | + |
| 46 | + let logsBtn = await driver.findElement(By.id("alert-data-source")); |
| 47 | + await logsBtn.click(); |
| 48 | + let logsDrpDownPresent= await driver.findElement(By.id("data-source-options")).isDisplayed(); |
| 49 | + assert.strictEqual(logsDrpDownPresent, true, 'logs dropdown is not displayed'); |
| 50 | + await logsBtn.click(); |
| 51 | + |
| 52 | + let logsLanguageBtn = await driver.findElement(By.id('logs-language-btn')); |
| 53 | + await logsLanguageBtn.click(); |
| 54 | + let logsLanguageDrpDownPresent= await driver.findElement(By.id("logs-language-options")).isDisplayed(); |
| 55 | + assert.strictEqual(logsLanguageDrpDownPresent, true, 'logs language dropdown is not displayed'); |
| 56 | + await logsLanguageBtn.click(); |
| 57 | + |
| 58 | + let datePickerBtn = await driver.findElement(By.id('date-picker-btn')); |
| 59 | + await datePickerBtn.click(); |
| 60 | + let datePickerDrpDownPresent= await driver.findElement(By.id("daterangepicker ")).isDisplayed(); |
| 61 | + assert.strictEqual(datePickerDrpDownPresent, true, 'date picker dropdown is not displayed'); |
| 62 | + await datePickerBtn.click(); |
| 63 | + |
| 64 | + let queryTextBox = await driver.findElement(By.id('query')); |
| 65 | + const checkQueryEditable = await queryTextBox.isEnabled(); |
| 66 | + assert.strictEqual(checkQueryEditable, true, 'query text box is not editable'); |
| 67 | + |
| 68 | + let alertThresholdTextBox = await driver.findElement(By.id('alert-condition')); |
| 69 | + await alertThresholdTextBox.click(); |
| 70 | + let alertThresholdDrpDownPresent= await driver.findElement(By.className("dropdown-menu box-shadow alert-condition-options show")).isDisplayed(); |
| 71 | + assert.strictEqual(alertThresholdDrpDownPresent, true, 'alert threshold dropdown is not displayed'); |
| 72 | + await alertThresholdTextBox.click(); |
| 73 | + |
| 74 | + let alertThresholdInputTextBox = await driver.findElement(By.id('threshold-value')); |
| 75 | + const checkAlertThresholdEditable = await alertThresholdInputTextBox.isEnabled(); |
| 76 | + assert.strictEqual(checkAlertThresholdEditable, true, 'alert threshold input text box is not editable'); |
| 77 | + await checkIncrementor(alertThresholdInputTextBox); |
| 78 | + |
| 79 | + let evaluateEveryTextBox = await driver.findElement(By.id('evaluate-every')); |
| 80 | + const checkEvaluateEveryEditable = await evaluateEveryTextBox.isEnabled(); |
| 81 | + assert.strictEqual(checkEvaluateEveryEditable, true, 'evaluate every input text box is not editable'); |
| 82 | + await checkIncrementor(evaluateEveryTextBox); |
| 83 | + |
| 84 | + let evaluteForTextBox = await driver.findElement(By.id('evaluate-for')); |
| 85 | + |
| 86 | + const checkAlertForEditable = await evaluteForTextBox.isEnabled(); |
| 87 | + assert.strictEqual(checkAlertForEditable, true, 'alert for input text box is not editable'); |
| 88 | + await checkIncrementor(evaluteForTextBox); |
| 89 | + |
| 90 | + |
| 91 | + let contactsPtsBtn = await driver.findElement(By.id('contact-points-dropdown')); |
| 92 | + await contactsPtsBtn.click(); |
| 93 | + let contactPtsDrpDownPresent= await driver.findElement(By.className("dropdown-menu box-shadow contact-points-options show")).isDisplayed(); |
| 94 | + assert.strictEqual(contactPtsDrpDownPresent, true, 'contact points dropdown is not displayed'); |
| 95 | + let contactPtsDrpDown=await driver.findElement(By.className("dropdown-menu box-shadow contact-points-options show")) |
| 96 | + let addNewBtnForContact = await contactPtsDrpDown.findElement(By.id('option-0')); |
| 97 | + assert.strictEqual(await addNewBtnForContact.getText(), 'Add New', 'Add new button is not present'); |
| 98 | + await addNewBtnForContact.click(); |
| 99 | + |
| 100 | + let cancelBtnForContact = await driver.findElement(By.id('cancel-contact-btn')); |
| 101 | + let cancelBtnTxt = await cancelBtnForContact.getText(); |
| 102 | + assert.strictEqual(cancelBtnTxt, 'Cancel', 'Cancel button is not present'); |
| 103 | + |
| 104 | + let saveBtnForContact = await driver.findElement(By.id('save-contact-btn')); |
| 105 | + let saveBtnTxt = await saveBtnForContact.getText(); |
| 106 | + |
| 107 | + assert.strictEqual(saveBtnTxt, 'Save', 'Save button is not present'); |
| 108 | + let contactNameInputTextBox = await driver.findElement(By.id('contact-name')); |
| 109 | + |
| 110 | + const checkContactNameEditable = await contactNameInputTextBox.isEnabled(); |
| 111 | + assert.strictEqual(checkContactNameEditable, true, 'contact name input text box is not editable'); |
| 112 | + |
| 113 | + let contactTypeDrpDown = await driver.findElement(By.id('contact-types')); |
| 114 | + await contactTypeDrpDown.click(); |
| 115 | + let contactTypeDrpDownPresent= await driver.findElement(By.className("dropdown-menu box-shadow contact-options show")); |
| 116 | + |
| 117 | + assert.strictEqual(await contactTypeDrpDownPresent.isDisplayed(), true, 'contact type dropdown is not displayed'); |
| 118 | + |
| 119 | + let slackOptionElement = await contactTypeDrpDownPresent.findElement(By.id('option-0')); |
| 120 | + await slackOptionElement.click(); |
| 121 | + let slackChannelInputTextBox = await driver.findElement(By.id('slack-channel-id')); |
| 122 | + const checkSlackChannelEditable = await slackChannelInputTextBox.isEnabled(); |
| 123 | + assert.strictEqual(checkSlackChannelEditable, true, 'slack channel input text box is not editable'); |
| 124 | + let slackTokenInputTextBox = await driver.findElement(By.id('slack-token')); |
| 125 | + const checkSlackTokenEditable = await slackTokenInputTextBox.isEnabled(); |
| 126 | + assert.strictEqual(checkSlackTokenEditable, true, 'slack token input text box is not editable'); |
| 127 | + |
| 128 | + contactTypeDrpDown.click(); |
| 129 | + |
| 130 | + let webHookOptionElement = await contactTypeDrpDownPresent.findElement(By.id('option-1')); |
| 131 | + await webHookOptionElement.click(); |
| 132 | + let webHookInputTextBox = await driver.findElement(By.id('webhook-id')); |
| 133 | + const checkWebHookEditable = await webHookInputTextBox.isEnabled(); |
| 134 | + assert.strictEqual(checkWebHookEditable, true, 'webhook input text box is not editable'); |
| 135 | + |
| 136 | + let addNewButton = await driver.findElement(By.className('add-new-contact-type btn')); |
| 137 | + assert.strictEqual(await addNewButton.getText(), 'Add new contact type', 'Add new button is not present'); |
| 138 | + |
| 139 | + cancelBtnForContact.click(); |
| 140 | + |
| 141 | + let notificationMessageInputTextBox = await driver.findElement(By.id('notification-msg')); |
| 142 | + const checkMessageEditable = await notificationMessageInputTextBox.isEnabled(); |
| 143 | + assert.strictEqual(checkMessageEditable, true, 'notification message input text box is not editable'); |
| 144 | + |
| 145 | + let labelKeyInputTextBox = await driver.findElement(By.id('label-key')); |
| 146 | + const checkLabelKeyEditable = await labelKeyInputTextBox.isEnabled(); |
| 147 | + assert.strictEqual(checkLabelKeyEditable, true, 'label key input text box is not editable'); |
| 148 | + labelKeyInputTextBox.getAttribute('value').then(function (value) { |
| 149 | + assert.strictEqual(value, 'alerting', 'label key input text box is not editable'); |
| 150 | + }); |
| 151 | + |
| 152 | + let labelValueInputTextBox = await driver.findElement(By.id('label-value')); |
| 153 | + const checkLabelValueEditable = await labelValueInputTextBox.isEnabled(); |
| 154 | + assert.strictEqual(checkLabelValueEditable, true, 'label value input text box is not editable'); |
| 155 | + labelValueInputTextBox.getAttribute('value').then(function (value) { |
| 156 | + assert.strictEqual(value, 'true', 'label value input text box is not editable'); |
| 157 | + }); |
| 158 | + |
| 159 | + let addNewLabelButton = await driver.findElement(By.className('add-label-container btn')); |
| 160 | + assert.strictEqual(await addNewLabelButton.getText(), 'Add Label', 'Add new label button is not present'); |
| 161 | + |
| 162 | + } |
| 163 | + catch (err) { |
| 164 | + // Handle any errors that occur during test execution |
| 165 | + console.error(err); |
| 166 | + } |
| 167 | + finally { |
| 168 | + // Close the browser |
| 169 | + await driver.quit(); |
| 170 | + |
| 171 | + } |
| 172 | + |
| 173 | +} |
| 174 | + |
| 175 | +testAlertPagesButtons(); |
0 commit comments