http://git-wip-us.apache.org/repos/asf/metron/blob/436cec43/metron-interface/metron-alerts/e2e/alerts-list/alerts-list.po.ts ---------------------------------------------------------------------- diff --git a/metron-interface/metron-alerts/e2e/alerts-list/alerts-list.po.ts b/metron-interface/metron-alerts/e2e/alerts-list/alerts-list.po.ts index 45f4fee..13aeb27 100644 --- a/metron-interface/metron-alerts/e2e/alerts-list/alerts-list.po.ts +++ b/metron-interface/metron-alerts/e2e/alerts-list/alerts-list.po.ts @@ -18,16 +18,23 @@ import {browser, element, by, protractor} from 'protractor'; import * as moment from 'moment/moment'; -import {waitForElementVisibility, waitForElementPresence, waitForElementInVisibility} from '../utils/e2e_util'; +import { + waitForElementVisibility, waitForElementPresence, waitForElementInVisibility, + waitForText, waitForCssClass, waitForCssClassNotToBePresent, waitForTextChange, + waitForStalenessOf, reduce_for_get_all, waitForElementCountGreaterThan, scrollIntoView, + waitForNonEmptyText, catchNoSuchElementError +} from '../utils/e2e_util'; export class MetronAlertsPage { + private EC = protractor.ExpectedConditions; + navigateTo() { - browser.waitForAngularEnabled(false); - return browser.get('/alerts-list'); + return browser.waitForAngularEnabled(false) + .then(() => browser.get('/alerts-list')); } clearLocalStorage() { - browser.executeScript('window.localStorage.clear();'); + return browser.executeScript('window.localStorage.clear();'); } isMetronLogoPresent() { @@ -72,23 +79,29 @@ export class MetronAlertsPage { clickActionDropdown() { let actionsDropDown = element(by.buttonText('ACTIONS')); - browser.actions().mouseMove(actionsDropDown).perform(); - return actionsDropDown.click(); + return scrollIntoView(actionsDropDown, true) + .then(() => actionsDropDown.click()); } clickActionDropdownOption(option: string) { - this.clickActionDropdown().then(() => { - element(by.cssContainingText('.dropdown-menu span', option)).click(); - browser.sleep(2000); - }); + return this.clickActionDropdown() + .then(() => element(by.cssContainingText('.dropdown-menu span', option)).click()) + .then(() => waitForCssClassNotToBePresent(element(by.css('#table-actions')), 'show')); } getActionDropdownItems() { - return this.clickActionDropdown().then(() => element.all(by.css('.dropdown-menu .dropdown-item.disabled')).getText()); + return this.clickActionDropdown() + .then(() => element.all(by.css('.dropdown-menu .dropdown-item.disabled')).reduce(reduce_for_get_all(), [])); } getTableColumnNames() { - return element.all(by.css('app-alerts-list .table th')).getText(); + return element.all(by.css('app-alerts-list .table th')).reduce(reduce_for_get_all(), []); + } + + getChangedPaginationText(previousText: string) { + let paginationElement = element(by.css('metron-table-pagination span')); + return waitForTextChange(paginationElement, previousText) + .then(() => paginationElement.getText()); } getPaginationText() { @@ -107,16 +120,18 @@ export class MetronAlertsPage { }); } - clickChevronRight(times = 1) { - for (let i = 0; i < times; i++) { - element(by.css('metron-table-pagination .fa.fa-chevron-right')).click(); - } + clickChevronRight() { + let paginationEle = element(by.css('metron-table-pagination .fa.fa-chevron-right')); + return waitForElementVisibility(paginationEle) + .then(() => browser.actions().mouseMove(paginationEle).perform()) + .then(() => paginationEle.click()) } clickChevronLeft(times = 1) { - for (let i = 0; i < times; i++) { - element(by.css('metron-table-pagination .fa.fa-chevron-left')).click(); - } + let paginationEle = element(by.css('metron-table-pagination .fa.fa-chevron-left')); + return waitForElementVisibility(paginationEle) + .then(() => browser.actions().mouseMove(paginationEle).perform()) + .then(() => paginationEle.click()); } clickSettings() { @@ -125,23 +140,23 @@ export class MetronAlertsPage { } getSettingsLabels() { - return element.all(by.css('app-configure-rows form label:not(.switch)')).getText(); + return element.all(by.css('app-configure-rows form label:not(.switch)')).reduce(reduce_for_get_all() ,[]); } getRefreshRateOptions() { - return element.all(by.css('.preset-row.refresh-interval .preset-cell')).getText(); + return element.all(by.css('.preset-row.refresh-interval .preset-cell')).reduce(reduce_for_get_all() ,[]); } getRefreshRateSelectedOption() { - return element.all(by.css('.preset-row.refresh-interval .preset-cell.is-active')).getText(); + return element.all(by.css('.preset-row.refresh-interval .preset-cell.is-active')).reduce(reduce_for_get_all() ,[]); } getPageSizeOptions() { - return element.all(by.css('.preset-row.page-size .preset-cell')).getText(); + return element.all(by.css('.preset-row.page-size .preset-cell')).reduce(reduce_for_get_all() ,[]); } getPageSizeSelectedOption() { - return element.all(by.css('.preset-row.page-size .preset-cell.is-active')).getText(); + return element.all(by.css('.preset-row.page-size .preset-cell.is-active')).reduce(reduce_for_get_all() ,[]); } clickRefreshInterval(intervalText: string) { @@ -154,30 +169,46 @@ export class MetronAlertsPage { clickConfigureTable() { let gearIcon = element(by.css('app-alerts-list .fa.fa-cog.configure-table-icon')); - waitForElementVisibility(gearIcon).then(() => gearIcon.click()); - browser.sleep(1000); + return waitForElementVisibility(gearIcon) + .then(() => scrollIntoView(gearIcon, true)) + .then(() => gearIcon.click()) + .then(() => waitForElementCountGreaterThan('app-configure-table tr', 282)); } clickCloseSavedSearch() { - element(by.css('app-saved-searches .close-button')).click(); - browser.sleep(2000); + return element(by.css('app-saved-searches .close-button')).click() + .then(() => waitForStalenessOf(element(by.css('app-saved-searches')))); } clickSavedSearch() { - element(by.buttonText('Searches')).click(); - browser.sleep(1000); + return element(by.buttonText('Searches')).click() + .then(() => waitForElementVisibility(element(by.css('app-saved-searches')))) + .then(() => browser.sleep(1000)); + } + + clickPlayPause(waitForPreviousClass: string) { + let playPauseButton = element(by.css('.btn.pause-play')); + return browser.actions().mouseMove(playPauseButton).perform() + .then(() => playPauseButton.click()) + .then(() => waitForCssClass(element(by.css('.btn.pause-play i')), waitForPreviousClass)); } - clickPlayPause() { - element(by.css('.btn.pause-play')).click(); + clickTableTextAndGetSearchText(name: string, textToWaitFor: string) { + browser.sleep(500); + return waitForElementVisibility(element.all(by.cssContainingText('table tr td a', name)).get(0)) + .then(() => element.all(by.cssContainingText('table tr td a', name)).get(0).click()) + .then(() => waitForText('.ace_line', textToWaitFor)) + .then(() => element(by.css('.ace_line')).getText()); } - clickTableText(name: string) { - waitForElementPresence(element.all(by.linkText(name))).then(() => element.all(by.linkText(name)).get(0).click()); + private clickTableText(name: string) { + waitForElementVisibility(element.all(by.linkText(name))).then(() => element.all(by.linkText(name)).get(0).click()); } - clickClearSearch() { - element(by.css('.btn-search-clear')).click(); + clickClearSearch(alertCount = '169') { + return element(by.css('.btn-search-clear')).click() + .then(() => waitForText('.ace_line', '*')) + .then(() => waitForText('.col-form-label-lg', `Alerts (${alertCount})`)); } getSavedSearchTitle() { @@ -197,36 +228,37 @@ export class MetronAlertsPage { } getRecentSearchOptions() { - browser.sleep(1000); - return element(by.linkText('Recent Searches')).element(by.xpath('..')).all(by.css('li')).getText(); + return element.all(by.css('[data-name="recent-searches"] li')).getText(); } getDefaultRecentSearchValue() { - browser.sleep(1000); - return element(by.linkText('Recent Searches')).element(by.xpath('..')).all(by.css('i')).getText(); + return element.all(by.css('[data-name="recent-searches"] i')).getText(); } getSavedSearchOptions() { - browser.sleep(1000); - return element(by.linkText('Saved Searches')).element(by.xpath('..')).all(by.css('li')).getText(); + return element.all(by.css('[data-name="saved-searches"] li')).getText(); } getDefaultSavedSearchValue() { - browser.sleep(1000); - return element(by.linkText('Saved Searches')).element(by.xpath('..')).all(by.css('i')).getText(); + return element.all(by.css('[data-name="saved-searches"] i')).getText(); } getSelectedColumnNames() { - return element.all(by.css('app-configure-table input[type="checkbox"]:checked')).map(ele => { - return ele.getAttribute('id').then(id => id.replace(/select-deselect-/, '')); - }); + return element.all(by.css('app-configure-table input[type="checkbox"]:checked')).reduce((acc, ele) => { + return ele.getAttribute('id').then(id => { + acc.push(id.replace(/select-deselect-/, '')); + return acc; + }) + }, []); } - toggleSelectCol(name: string, scrollTo = '') { - scrollTo = scrollTo === '' ? name : scrollTo; - let ele = element(by.css('app-configure-table label[for="select-deselect-' + name + '"]')); - let scrollToEle = element(by.css('app-configure-table label[for="select-deselect-' + scrollTo + '"]')); - browser.actions().mouseMove(scrollToEle).perform().then(() => ele.click()); + toggleSelectCol(name: string) { + const selector = `app-configure-table label[for=\"select-deselect-${name}\"]`; + const ele = element(by.css(selector)); + return waitForElementVisibility(ele) + .then(() => scrollIntoView(ele, true)) + .then(() => (element(by.css(selector)).click())) + .catch(err => console.log(err)); } saveSearch(name: string) { @@ -235,28 +267,41 @@ export class MetronAlertsPage { } saveConfigureColumns() { - element(by.css('app-configure-table')).element(by.buttonText('SAVE')).click(); + return element(by.css('app-configure-table')).element(by.buttonText('SAVE')).click(); } - clickRemoveSearchChip() { + clickRemoveSearchChipAndGetSearchText(expectedSearchText: string) { + return this.clickRemoveSearchChip() + .then(() => waitForText('.ace_line', expectedSearchText)) + .then(() => element(by.css('.ace_line')).getText()) + } + + private clickRemoveSearchChip(): any { let aceLine = element.all(by.css('.ace_keyword')).get(0); /* - Focus on the search text box by sending a empty string - move the mouse to the text in search bos so that delete buttons become visible - wait for delete buttons become visible - click on delete button */ - element(by.css('app-alerts-list .ace_text-input')).sendKeys('') + return element(by.css('app-alerts-list .ace_text-input')).sendKeys('') .then(() => browser.actions().mouseMove(aceLine).perform()) .then(() => this.waitForElementPresence(element(by.css('.ace_value i')))) .then(() => element.all(by.css('.ace_value i')).get(0).click()); } - setSearchText(search: string) { - this.clickClearSearch(); - element(by.css('app-alerts-list .ace_text-input')).sendKeys(protractor.Key.BACK_SPACE); - element(by.css('app-alerts-list .ace_text-input')).sendKeys(search); - element(by.css('app-alerts-list .ace_text-input')).sendKeys(protractor.Key.ENTER); - browser.sleep(2000); + setSearchText(search: string, alertCount = '169') { + // It is required to click on a visible element of Ace editor in order to + // bring focus to the input: https://stackoverflow.com/questions/37809915/element-not-visible-error-not-able-to-click-an-element + let EC = protractor.ExpectedConditions; + let aceInput = element(by.css('app-alerts-list .ace_text-input')); + let aceScroller = element(by.css('app-alerts-list .ace_scroller')); + return this.clickClearSearch(alertCount) + .then(() => browser.wait(EC.presenceOf(aceScroller))) + .then(() => aceScroller.click()) + .then(() => aceInput.sendKeys(protractor.Key.BACK_SPACE)) + .then(() => aceInput.sendKeys(search)) + .then(() => aceInput.sendKeys(protractor.Key.ENTER)) + .then(() => browser.sleep(10000)); } waitForElementPresence (element ) { @@ -272,25 +317,31 @@ export class MetronAlertsPage { toggleAlertInList(index: number) { let selector = by.css('app-alerts-list tbody tr label'); let checkbox = element.all(selector).get(index); - this.waitForElementPresence(checkbox).then(() => { - browser.actions().mouseMove(checkbox).perform().then(() => { - checkbox.click(); - }); - }); + return this.waitForElementPresence(checkbox) + .then(() => scrollIntoView(checkbox, true)) + .then(() => checkbox.click()); } getAlertStatus(rowIndex: number, previousText: string, colIndex = 8) { let row = element.all(by.css('app-alerts-list tbody tr')).get(rowIndex); let column = row.all(by.css('td a')).get(colIndex); - return this.waitForTextChange(column, previousText).then(() => { - return column.getText(); - }); + return this.waitForTextChange(column, previousText).then(() => column.getText()); } - waitForMetaAlert() { - browser.sleep(2000); - return element(by.css('button[data-name="search"]')).click() - .then(() => waitForElementPresence(element(by.css('.icon-cell.dropdown-cell')))); + waitForMetaAlert(expectedCount) { + let title = element(by.css('.col-form-label-lg')); + function waitForMetaAlert$() + { + return function () { + return browser.sleep(2000) + .then(() => element(by.css('button[data-name="search"]')).click()) + .then(() => waitForTextChange(title, `Alerts (169)`)) + .then(() => title.getText()) + .then((text) => text === `Alerts (${expectedCount})`) + .catch(catchNoSuchElementError()) + } + } + return browser.wait(waitForMetaAlert$()).catch(catchNoSuchElementError()); } isDateSeettingDisabled() { @@ -298,37 +349,74 @@ export class MetronAlertsPage { } clickDateSettings() { - element(by.css('app-time-range button.btn-search')).click(); - browser.sleep(2000); + return scrollIntoView(element(by.css('app-time-range button.btn-search')), true) + .then(() => element(by.css('app-time-range button.btn-search')).click()) + .then(() => waitForCssClass(element(by.css('app-time-range #time-range')), 'show')); + } + + hideDateSettings() { + return element(by.css('app-time-range button.btn-search')).click() + .then(() => waitForCssClassNotToBePresent(element(by.css('app-time-range #time-range')), 'show')) + .then(() => waitForElementInVisibility(element(by.css('app-time-range #time-range')))); } getTimeRangeTitles() { - return element.all(by.css('app-time-range .title')).getText(); + return element.all(by.css('app-time-range .title')).reduce(reduce_for_get_all(), []); } getQuickTimeRanges() { - return element.all(by.css('app-time-range .quick-ranges span')).getText(); + return element.all(by.css('app-time-range .quick-ranges span')).reduce(reduce_for_get_all(), []); } getValueForManualTimeRange() { - return element.all(by.css('app-time-range input.form-control')). getAttribute('value'); + return element.all(by.css('app-time-range input.form-control')).reduce((acc, ele) => { + return ele.getAttribute('value').then(value => { + acc.push(value); + return acc; + }); + }, []); } isManulaTimeRangeApplyButtonPresent() { return element.all(by.css('app-time-range')).all(by.buttonText('APPLY')).count().then(count => count === 1); } + waitForTextAndSubTextInTimeRange(currentTimeRangeVal) { + return waitForTextChange(element(by.css('app-time-range .time-range-value')), currentTimeRangeVal[1]) + .then(() => waitForTextChange(element(by.css('app-time-range .time-range-text')), currentTimeRangeVal[0])) + } + + async selectQuickTimeRangeAndGetTimeRangeAndTimeText(quickRange: string) { + let currentTimeRangeVal: any = []; + let timeRangeVal = '', timeRangeText = ''; + await element(by.css('app-time-range .time-range-value')).getText().then(text => timeRangeVal = text.trim()); + await element(by.css('app-time-range .time-range-text')).getText().then(text => timeRangeText = text.trim()); + + await this.selectQuickTimeRange(quickRange); + await waitForCssClassNotToBePresent(element(by.css('app-time-range #time-range')), 'show'); + await waitForTextChange(element(by.css('app-time-range .time-range-value')), timeRangeVal); + await waitForTextChange(element(by.css('app-time-range .time-range-text')), timeRangeText); + + return this.getTimeRangeButtonAndSubText(); + } + + selectQuickTimeRangeAndGetTimeRangeText(quickRange: string) { + return this.selectQuickTimeRange(quickRange) + .then(() => waitForElementInVisibility(element(by.css('#time-range')))) + .then(() => browser.wait(this.EC.textToBePresentInElement(element(by.css('app-time-range .time-range-text')), quickRange))) + .then(() => element.all(by.css('app-time-range button span')).get(0).getText()); + } + selectQuickTimeRange(quickRange: string) { - element.all(by.cssContainingText('.quick-ranges span', quickRange)).get(0).click(); - browser.sleep(2000); + return element(by.id(quickRange.toLowerCase().replace(/ /g,'-'))).click(); } getTimeRangeButtonText() { - return element.all(by.css('app-time-range button.btn-search span')).get(0).getText(); + return element(by.css('app-time-range .time-range-text')).getText(); } setDate(index: number, year: string, month: string, day: string, hour: string, min: string, sec: string) { - element.all(by.css('app-time-range .calendar')).get(index).click() + return element.all(by.css('app-time-range .calendar')).get(index).click() .then(() => element.all(by.css('.pika-select.pika-select-hour')).get(index).click()) .then(() => element.all(by.css('.pika-select.pika-select-hour')).get(index).element(by.cssContainingText('option', hour)).click()) .then(() => element.all(by.css('.pika-select.pika-select-minute')).get(index).click()) @@ -341,8 +429,6 @@ export class MetronAlertsPage { .then(() => element.all(by.css('.pika-select.pika-select-month')).get(index).element(by.cssContainingText('option', month)).click()) .then(() => element.all(by.css('.pika-table')).get(index).element(by.buttonText(day)).click()) .then(() => waitForElementInVisibility(element.all(by.css('.pika-single')).get(index))); - - browser.sleep(1000); } selectTimeRangeApplyButton() { @@ -350,11 +436,9 @@ export class MetronAlertsPage { } getChangesAlertTableTitle(previousText: string) { - // browser.pause(); let title = element(by.css('.col-form-label-lg')); - return this.waitForTextChange(title, previousText).then(() => { - return title.getText(); - }); + return waitForTextChange(title, previousText) + .then(() => title.getText()); } getAlertStatusById(id: string) { @@ -372,7 +456,7 @@ export class MetronAlertsPage { } expandMetaAlert(rowIndex: number) { - element.all(by.css('table tbody tr')).get(rowIndex).element(by.css('.icon-cell.dropdown-cell')).click(); + return element.all(by.css('table tbody tr')).get(rowIndex).element(by.css('.icon-cell.dropdown-cell')).click(); } getHiddenRowCount() { @@ -388,8 +472,8 @@ export class MetronAlertsPage { } clickOnMetaAlertRow(rowIndex: number) { - element.all(by.css('table tbody tr')).get(rowIndex).all(by.css('td')).get(5).click(); - browser.sleep(2000); + return element.all(by.css('table tbody tr')).get(rowIndex).all(by.css('td')).get(5).click() + .then(() => browser.sleep(2000)); } removeAlert(rowIndex: number) { @@ -397,42 +481,38 @@ export class MetronAlertsPage { } loadSavedSearch(name: string) { - element.all(by.css('app-saved-searches metron-collapse')).get(1).element(by.css('li[title="'+ name +'"]')).click(); - browser.sleep(1000); + return element.all(by.css('app-saved-searches metron-collapse')).get(1).element(by.css('li[title="'+ name +'"]')).click(); } loadRecentSearch(name: string) { - element.all(by.css('app-saved-searches metron-collapse')).get(0).all(by.css('li')).get(2).click(); - browser.sleep(1000); + return element.all(by.css('app-saved-searches metron-collapse')).get(0).all(by.css('li')).get(2).click(); } getTimeRangeButtonTextForNow() { - return element.all(by.css('app-time-range button span')).getText(); - } - - getTimeRangeButtonAndSubText() { - return waitForElementInVisibility(element(by.css('#time-range'))) - .then(() => element.all(by.css('app-time-range button span')).getText()) - .then(arr => { - let retArr = [arr[0]]; - for (let i=1; i < arr.length; i++) { - let dateStr = arr[i].split(' to '); - let fromTime = moment.utc(dateStr[0], 'YYYY-MM-DD HH:mm:ss Z').unix() * 1000; - let toTime = moment.utc(dateStr[1], 'YYYY-MM-DD HH:mm:ss Z').unix() * 1000; - retArr.push((toTime - fromTime) + ''); - } - return retArr; - }); + return element.all(by.css('app-time-range button span')).reduce(reduce_for_get_all(), []); + } + + async getTimeRangeButtonAndSubText() { + let timeRangetext = '', timeRangeValue = ''; + + await element(by.css('app-time-range .time-range-text')).getText().then(text => timeRangetext = text); + await element(by.css('app-time-range .time-range-value')).getText().then(text => timeRangeValue = text); + + let retArr = [timeRangetext]; + let dateStr = timeRangeValue.split(' to '); + let fromTime = moment.utc(dateStr[0], 'YYYY-MM-DD HH:mm:ss Z').unix() * 1000; + let toTime = moment.utc(dateStr[1], 'YYYY-MM-DD HH:mm:ss Z').unix() * 1000; + retArr.push((toTime - fromTime) + ''); + return retArr; } renameColumn(name: string, value: string) { - element(by.cssContainingText('app-configure-table span', name)) + return element(by.cssContainingText('app-configure-table span', name)) .element(by.xpath('../..')) .element(by.css('.input')).sendKeys(value); } getTableCellValues(cellIndex: number, startRowIndex: number, endRowIndex: number): any { - return element.all(by.css('table tbody tr td:nth-child(' + cellIndex + ')')).getText() - .then(val => val.slice(startRowIndex, endRowIndex)); + return element.all(by.css('table tbody tr td:nth-child(' + cellIndex + ')')).reduce(reduce_for_get_all(), []) } }
http://git-wip-us.apache.org/repos/asf/metron/blob/436cec43/metron-interface/metron-alerts/e2e/alerts-list/configure-table/configure-table.e2e-spec.ts ---------------------------------------------------------------------- diff --git a/metron-interface/metron-alerts/e2e/alerts-list/configure-table/configure-table.e2e-spec.ts b/metron-interface/metron-alerts/e2e/alerts-list/configure-table/configure-table.e2e-spec.ts index 6741e2f..c3636f5 100644 --- a/metron-interface/metron-alerts/e2e/alerts-list/configure-table/configure-table.e2e-spec.ts +++ b/metron-interface/metron-alerts/e2e/alerts-list/configure-table/configure-table.e2e-spec.ts @@ -21,21 +21,22 @@ import {customMatchers} from '../../matchers/custom-matchers'; import {LoginPage} from '../../login/login.po'; import {loadTestData, deleteTestData} from '../../utils/e2e_util'; -describe('metron-alerts configure table', function() { +describe('Test spec for table column configuration', function() { let page: MetronAlertsPage; let loginPage: LoginPage; let colNamesColumnConfig = [ 'score', 'id', 'timestamp', 'source:type', 'ip_src_addr', 'enrichments:geo:ip_dst_addr:country', 'ip_dst_addr', 'host', 'alert_status' ]; - beforeAll(() => { - loadTestData(); + beforeAll(async function() : Promise<any> { loginPage = new LoginPage(); - loginPage.login(); + + await loadTestData(); + await loginPage.login(); }); - afterAll(() => { - loginPage.logout(); - deleteTestData(); + afterAll(async function() : Promise<any> { + await loginPage.logout(); + await deleteTestData(); }); beforeEach(() => { @@ -43,40 +44,39 @@ describe('metron-alerts configure table', function() { jasmine.addMatchers(customMatchers); }); - it('should select columns from table configuration', () => { + it('should select columns from table configuration', async function() : Promise<any> { let newColNamesColumnConfig = [ 'score', 'timestamp', 'source:type', 'ip_src_addr', 'enrichments:geo:ip_dst_addr:country', 'ip_dst_addr', 'host', 'alert_status', 'guid' ]; - page.clearLocalStorage(); - page.navigateTo(); + await page.clearLocalStorage(); + await page.navigateTo(); - page.clickConfigureTable(); - expect(page.getSelectedColumnNames()).toEqualBcoz(colNamesColumnConfig, 'for default selected column names'); - page.toggleSelectCol('id'); - page.toggleSelectCol('guid', 'method'); - expect(page.getSelectedColumnNames()).toEqualBcoz(newColNamesColumnConfig, 'for guid added to selected column names'); - page.saveConfigureColumns(); + await page.clickConfigureTable(); + expect(await page.getSelectedColumnNames()).toEqualBcoz(colNamesColumnConfig, 'for default selected column names'); + await page.toggleSelectCol('id'); + await page.toggleSelectCol('guid'); + expect(await page.getSelectedColumnNames()).toEqualBcoz(newColNamesColumnConfig, 'for guid added to selected column names'); + await page.saveConfigureColumns(); }); - it('should rename columns from table configuration', () => { - page.clearLocalStorage(); - page.navigateTo(); + it('should rename columns from table configuration', async function() : Promise<any> { + await page.clearLocalStorage(); + await page.navigateTo(); - page.clickConfigureTable(); - page.renameColumn('enrichments:geo:ip_dst_addr:country', 'Country'); - page.saveConfigureColumns(); + await page.clickConfigureTable(); + await page.renameColumn('enrichments:geo:ip_dst_addr:country', 'Country'); + await page.saveConfigureColumns(); - page.clickTableText('FR'); - expect(page.getSearchText()).toEqual('Country:FR'); - expect(page.getChangesAlertTableTitle('Alerts (169)')).toEqual('Alerts (25)'); - page.clickClearSearch(); + expect(await page.clickTableTextAndGetSearchText('FR', 'Country:FR')).toEqual('Country:FR'); + expect(await page.getChangesAlertTableTitle('Alerts (169)')).toEqual('Alerts (25)'); + await page.clickClearSearch(); - expect(page.getChangesAlertTableTitle('Alerts (25)')).toEqual('Alerts (169)'); - page.setSearchText('Country:FR'); - expect(page.getChangesAlertTableTitle('Alerts (169)')).toEqual('Alerts (25)'); - page.clickClearSearch(); + expect(await page.getChangesAlertTableTitle('Alerts (25)')).toEqual('Alerts (169)'); + await page.setSearchText('Country:FR'); + expect(await page.getChangesAlertTableTitle('Alerts (169)')).toEqual('Alerts (25)'); + await page.clickClearSearch(); - expect(page.getTableColumnNames()).toContain('Country', 'for renamed column names for alert list table'); + expect(await page.getTableColumnNames()).toContain('Country', 'for renamed column names for alert list table'); }); http://git-wip-us.apache.org/repos/asf/metron/blob/436cec43/metron-interface/metron-alerts/e2e/alerts-list/meta-alerts/meta-alert.e2e-spec.ts ---------------------------------------------------------------------- diff --git a/metron-interface/metron-alerts/e2e/alerts-list/meta-alerts/meta-alert.e2e-spec.ts b/metron-interface/metron-alerts/e2e/alerts-list/meta-alerts/meta-alert.e2e-spec.ts index 00d677e..5425523 100644 --- a/metron-interface/metron-alerts/e2e/alerts-list/meta-alerts/meta-alert.e2e-spec.ts +++ b/metron-interface/metron-alerts/e2e/alerts-list/meta-alerts/meta-alert.e2e-spec.ts @@ -19,13 +19,14 @@ import { MetronAlertsPage } from '../alerts-list.po'; import {customMatchers} from '../../matchers/custom-matchers'; import {LoginPage} from '../../login/login.po'; -import {loadTestData, deleteTestData} from '../../utils/e2e_util'; +import {loadTestData, deleteTestData, createMetaAlertsIndex} from '../../utils/e2e_util'; import {TreeViewPage} from '../tree-view/tree-view.po'; import {MetronAlertDetailsPage} from '../../alert-details/alert-details.po'; import {MetaAlertPage} from './meta-alert.po'; import {AlertFacetsPage} from '../alert-filters/alert-filters.po'; +import {browser} from 'protractor'; -describe('meta-alerts workflow', function() { +describe('Test spec for meta alerts workflow', function() { let detailsPage: MetronAlertDetailsPage; let tablePage: MetronAlertsPage; let metaAlertPage: MetaAlertPage; @@ -33,122 +34,126 @@ describe('meta-alerts workflow', function() { let loginPage: LoginPage; let alertFacetsPage: AlertFacetsPage; - beforeAll(() => { - loadTestData(); - + beforeAll(async function() : Promise<any> { loginPage = new LoginPage(); - loginPage.login(); tablePage = new MetronAlertsPage(); treePage = new TreeViewPage(); tablePage = new MetronAlertsPage(); metaAlertPage = new MetaAlertPage(); detailsPage = new MetronAlertDetailsPage(); alertFacetsPage = new AlertFacetsPage(); + + await createMetaAlertsIndex(); + await loadTestData(); + await loginPage.login(); }); - afterAll(() => { - loginPage.logout(); - deleteTestData(); + afterAll(async function() : Promise<any> { + await loginPage.logout(); + await deleteTestData(); }); beforeEach(() => { jasmine.addMatchers(customMatchers); }); - it('should have all the steps for meta alerts workflow', () => { + it('should have all the steps for meta alerts workflow', async function() : Promise<any> { let comment1 = 'This is a sample comment'; let userNameAndTimestamp = '- admin - a few seconds ago'; - let confirmText = 'Do you wish to create a meta alert with 113 selected alerts?'; + let confirmText = 'Do you wish to create a meta alert with 22 selected alerts?'; let dashRowValues = { - 'firstDashRow': ['0', '192.168.138.158', 'ALERTS', '113'], - 'secondDashRow': ['0', '192.168.66.1', 'ALERTS', '56'] + 'firstDashRow': ['0', '192.168.138.2', 'ALERTS', '22'] }; - tablePage.navigateTo(); + await tablePage.navigateTo(); + expect(await tablePage.getChangesAlertTableTitle('Alerts (0)')).toEqual('Alerts (169)'); /* Create Meta Alert */ - treePage.selectGroup('ip_src_addr'); - expect(treePage.getDashGroupValues('192.168.138.158')).toEqualBcoz(dashRowValues.firstDashRow, 'First Dashrow to be present'); - expect(treePage.getDashGroupValues('192.168.66.1')).toEqualBcoz(dashRowValues.secondDashRow, 'Second Dashrow to be present'); + await treePage.selectGroup('ip_dst_addr'); + // Test cannot pass until issue with missing dash score is resolved: https://issues.apache.org/jira/browse/METRON-1631 + // expect(await treePage.getDashGroupValues('192.168.138.2')).toEqualBcoz(dashRowValues.firstDashRow, 'First Dashrow to be present'); - treePage.clickOnMergeAlerts('192.168.138.158'); - expect(treePage.getConfirmationText()).toEqualBcoz(confirmText, 'confirmation text to be present'); - treePage.clickNoForConfirmation(); + await treePage.clickOnMergeAlerts('192.168.138.2'); + expect(await treePage.getConfirmationText()).toEqualBcoz(confirmText, 'confirmation text to be present'); + await treePage.clickNoForConfirmation(); - treePage.clickOnMergeAlerts('192.168.138.158'); - treePage.clickYesForConfirmation(); + await treePage.clickOnMergeAlerts('192.168.138.2'); + await treePage.clickYesForConfirmation(); - treePage.waitForElementToDisappear('192.168.138.158'); + await treePage.waitForElementToDisappear('192.168.138.2'); - treePage.unGroup(); + await treePage.unGroup(); /* Table should have all alerts */ - tablePage.waitForMetaAlert(); - expect(tablePage.getPaginationText()).toEqualBcoz('1 - 25 of 57', 'pagination text to be present'); - expect(tablePage.getCellValue(0, 2, '(114)')).toContain('(113)', 'number of alerts in a meta alert should be correct'); - expect(tablePage.getNonHiddenRowCount()).toEqualBcoz(25, '25 rows to be visible'); - expect(tablePage.getAllRowsCount()).toEqualBcoz(138, '138 rows to be available'); - expect(tablePage.getHiddenRowCount()).toEqualBcoz(113, '113 rows to be hidden'); - tablePage.expandMetaAlert(0); - expect(tablePage.getNonHiddenRowCount()).toEqualBcoz(138, '138 rows to be visible after group expand'); - expect(tablePage.getAllRowsCount()).toEqualBcoz(138, '138 rows to be available after group expand'); - expect(tablePage.getHiddenRowCount()).toEqualBcoz(0, '0 rows to be hidden after group expand'); + await tablePage.waitForMetaAlert(148); + expect(await tablePage.getChangedPaginationText('1 - 25 of 169')).toEqualBcoz('1 - 25 of 148', 'pagination text to be present'); + expect(await tablePage.getCellValue(0, 2, '(14)')).toContain('(22)'); + expect(await tablePage.getNonHiddenRowCount()).toEqualBcoz(25, '25 rows to be visible'); + expect(await tablePage.getAllRowsCount()).toEqualBcoz(47, '47 rows to be available'); + expect(await tablePage.getHiddenRowCount()).toEqualBcoz(22, '22 rows to be hidden'); + await tablePage.expandMetaAlert(0); + expect(await tablePage.getNonHiddenRowCount()).toEqualBcoz(47, '47 rows to be visible after group expand'); + expect(await tablePage.getAllRowsCount()).toEqualBcoz(47, '47 rows to be available after group expand'); + expect(await tablePage.getHiddenRowCount()).toEqualBcoz(0, '0 rows to be hidden after group expand'); /* Meta Alert Status Change */ - tablePage.toggleAlertInList(0); - tablePage.clickActionDropdownOption('Open'); - expect(tablePage.getAlertStatus(0, 'NEW', 2)).toEqual('OPEN'); - expect(tablePage.getAlertStatus(1, 'NEW')).toEqual('OPEN'); - expect(tablePage.getAlertStatus(2, 'NEW')).toEqual('OPEN'); - - /* Details Edit Should work - add comments - remove comments - multiple alerts */ - tablePage.clickOnMetaAlertRow(0); - expect(detailsPage.getAlertDetailsCount()).toEqualBcoz(113, '113 alert details should be present'); - detailsPage.clickRenameMetaAlert(); - detailsPage.renameMetaAlert('e2e-meta-alert'); - detailsPage.cancelRename(); - expect(detailsPage.getAlertNameOrId()).not.toEqual('e2e-meta-alert'); - detailsPage.clickRenameMetaAlert(); - detailsPage.renameMetaAlert('e2e-meta-alert'); - detailsPage.saveRename(); + await tablePage.toggleAlertInList(0); + await tablePage.clickActionDropdownOption('Open'); + expect(await tablePage.getAlertStatus(0, 'NEW', 2)).toEqual('OPEN'); + expect(await tablePage.getAlertStatus(1, 'NEW')).toEqual('OPEN'); + expect(await tablePage.getAlertStatus(2, 'NEW')).toEqual('OPEN'); + + /* Details Edit - add comments - remove comments - multiple alerts */ + await tablePage.clickOnMetaAlertRow(0); + expect(await detailsPage.getAlertDetailsCount()).toEqualBcoz(22, '22 alert details should be present'); + await detailsPage.clickRenameMetaAlert(); + await detailsPage.renameMetaAlert('e2e-meta-alert'); + await detailsPage.cancelRename(); + expect(await detailsPage.getAlertNameOrId()).not.toEqual('e2e-meta-alert'); + await detailsPage.clickRenameMetaAlert(); + await detailsPage.renameMetaAlert('e2e-meta-alert'); + await detailsPage.saveRename(); expect(detailsPage.getAlertNameOrId()).toEqual('e2e-meta-alert'); - detailsPage.clickCommentsInSideNav(); - detailsPage.addCommentAndSave(comment1, 0); - expect(detailsPage.getCommentsText()).toEqual([comment1]); - expect(detailsPage.getCommentsUserNameAndTimeStamp()).toEqual([userNameAndTimestamp]); - expect(detailsPage.getCommentIconCountInListView()).toEqual(1); + // The below code will fail until this issue is resolved in Protractor: https://github.com/angular/protractor/issues/4693 + // This is because the connection resets before deleting the test comment, which causes the assertion to be false - detailsPage.deleteComment(); - detailsPage.clickYesForConfirmation(); + // await detailsPage.clickCommentsInSideNav(); + // await detailsPage.addCommentAndSave(comment1, 0); + // expect(await detailsPage.getCommentsText()).toEqual([comment1]); + // expect(await detailsPage.getCommentsUserNameAndTimeStamp()).toEqual([userNameAndTimestamp]); + // expect(await detailsPage.getCommentIconCountInListView()).toEqual(1); - detailsPage.closeDetailPane(); + // await detailsPage.deleteComment(); + // await detailsPage.clickYesForConfirmation(comment1); + await detailsPage.closeDetailPane(); /* Add to alert */ - tablePage.toggleAlertInList(3); - tablePage.clickActionDropdownOption('Add to Alert'); - expect(metaAlertPage.getPageTitle()).toEqualBcoz('Add to Alert', 'Add Alert Title should be present'); - expect(metaAlertPage.getMetaAlertsTitle()).toEqualBcoz('SELECT OPEN ALERT', 'select open alert title should be present'); - expect(metaAlertPage.getAvailableMetaAlerts()).toEqualBcoz('e2e-meta-alert (113)', 'Meta alert should be present'); - metaAlertPage.selectRadio(); - metaAlertPage.addToMetaAlert(); - expect(tablePage.getCellValue(0, 2, '(113')).toContain('(114)', 'alert count should be incremented'); - - /* Remove from alert */ + await tablePage.toggleAlertInList(3); + await tablePage.clickActionDropdownOption('Add to Alert'); + await metaAlertPage.waitForDialog(); + expect(await metaAlertPage.getPageTitle()).toEqualBcoz('Add to Alert', 'Add Alert Title should be present'); + expect(await metaAlertPage.getMetaAlertsTitle()).toEqualBcoz('SELECT OPEN ALERT', 'select open alert title should be present'); + expect(await metaAlertPage.getAvailableMetaAlerts()).toEqualBcoz('e2e-meta-alert (22)', 'Meta alert should be present'); + await metaAlertPage.selectRadio(); + await metaAlertPage.addToMetaAlert(); + expect(await tablePage.getCellValue(0, 2, '(22')).toContain('(23)', 'alert count should be incremented'); + + // /* Remove from alert */ let removAlertConfirmText = 'Do you wish to remove the alert from the meta alert?'; - tablePage.removeAlert(2); - expect(treePage.getConfirmationText()).toEqualBcoz(removAlertConfirmText, 'confirmation text to remove alert from meta alert'); - treePage.clickYesForConfirmation(); - expect(tablePage.getCellValue(0, 2, '(114')).toContain('(113)', 'alert count should be decremented'); + await tablePage.removeAlert(2); + expect(await treePage.getConfirmationText()).toEqualBcoz(removAlertConfirmText, 'confirmation text to remove alert from meta alert'); + await treePage.clickYesForConfirmation(); + expect(await tablePage.getCellValue(0, 2, '(23')).toContain('(22)', 'alert count should be decremented'); - /* Delete Meta Alert */ + // /* Delete Meta Alert */ let removeMetaAlertConfirmText = 'Do you wish to remove all the alerts from meta alert?'; - tablePage.removeAlert(0); - expect(treePage.getConfirmationText()).toEqualBcoz(removeMetaAlertConfirmText, 'confirmation text to remove meta alert'); - treePage.clickYesForConfirmation(); + await tablePage.removeAlert(0); + expect(await treePage.getConfirmationText()).toEqualBcoz(removeMetaAlertConfirmText, 'confirmation text to remove meta alert'); + await treePage.clickYesForConfirmation(); }); - it('should create a meta alert from nesting of more than one level', () => { + it('should create a meta alert from nesting of more than one level', async function() : Promise<any> { let groupByItems = { 'source:type': '1', 'ip_dst_addr': '7', @@ -178,70 +183,73 @@ describe('meta-alerts workflow', function() { 'a5e95569-a...0e2613b29a' ]; - let alertsAfterDeletedInMetaAlerts = [ - '82f8046d-d...03b17480dd', + let alertsAfterDeletedInMetaAlerts = [ '3c346bf9-b...cb04b43210', + '42f4ce28-8...b3d575b507', '5c1825f6-7...da3abe3aec', - '9041285e-9...a04a885b53', - 'ed906df7-2...91cc54c2f3', - 'e63ff7ae-d...cddbe0c0b3', - '3c346bf9-b...cb04b43210', - 'dcc483af-c...7bb802b652', - 'b71f085d-6...a4904d8fcf', '754b4f63-3...b39678207f', - 'd9430af3-e...9a18600ab2', + '82f8046d-d...03b17480dd', + '9041285e-9...a04a885b53', '9a943c94-c...3b9046b782', - 'f39dc401-3...1f9cf02cd9', - 'd887fe69-c...2fdba06dbc', - 'e38be207-b...60a43e3378', - 'eba8eccb-b...0005325a90', + 'a5e95569-a...0e2613b29a', 'adca96e3-1...979bf0b5f1', - '42f4ce28-8...b3d575b507', 'aed3d10f-b...8b8a139f25', - 'a5e95569-a...0e2613b29a' - ]; + 'b71f085d-6...a4904d8fcf', + 'c894bbcf-3...74cf0cc1fe', + 'd887fe69-c...2fdba06dbc', + 'd9430af3-e...9a18600ab2', + 'dcc483af-c...7bb802b652', + 'e63ff7ae-d...cddbe0c0b3', + 'eba8eccb-b...0005325a90', + 'ed906df7-2...91cc54c2f3', + 'f39dc401-3...1f9cf02cd9' ]; // Create a meta alert from a group that is nested by more than 1 level - treePage.selectGroup('source:type'); - treePage.selectGroup('ip_dst_addr'); - treePage.expandDashGroup('alerts_ui_e2e'); + await treePage.selectGroup('source:type'); + await treePage.selectGroup('ip_dst_addr'); + await treePage.expandDashGroup('alerts_ui_e2e'); - treePage.clickOnMergeAlertsInTable('alerts_ui_e2e', '224.0.0.251', 0); - treePage.clickYesForConfirmation(); + await treePage.clickOnMergeAlertsInTable('alerts_ui_e2e', '224.0.0.251', 0); + await treePage.clickYesForConfirmation(); - treePage.unGroup(); - tablePage.waitForMetaAlert(); + await treePage.unGroup(); + await tablePage.waitForMetaAlert(150); - expect(tablePage.getPaginationText()).toEqualBcoz('1 - 25 of 150', 'pagination text to be present'); + expect(await tablePage.getChangedPaginationText('1 - 25 of 169')).toEqualBcoz('1 - 25 of 150', 'pagination text to be present'); // Meta Alert should appear in Filters - alertFacetsPage.toggleFacetState(3); - expect(alertFacetsPage.getFacetValues(3)).toEqual({'metaalert': '1' }, 'for source:type facet'); + await alertFacetsPage.toggleFacetState(3); + let facetValues = await alertFacetsPage.getFacetValues(3); + expect(await facetValues['metaalert']).toEqual('1', 'for source:type facet'); // Meta Alert should not appear in Groups - expect(treePage.getGroupByItemNames()).toEqualBcoz(Object.keys(groupByItems), 'Group By Elements names should be present'); - expect(treePage.getGroupByItemCounts()).toEqualBcoz(Object.keys(groupByItems).map(key => groupByItems[key]), + expect(await treePage.getGroupByItemNames()).toEqualBcoz(Object.keys(groupByItems), 'Group By Elements names should be present'); + expect(await treePage.getGroupByItemCounts()).toEqualBcoz(Object.keys(groupByItems).map(key => groupByItems[key]), '5 Group By Elements values should be present'); - tablePage.setSearchText('guid:c894bbcf-3195-0708-aebe-0574cf0cc1fe'); - expect(tablePage.getChangesAlertTableTitle('Alerts (150)')).toEqual('Alerts (1)'); - tablePage.expandMetaAlert(0); - expect(tablePage.getAllRowsCount()).toEqual(21); - tablePage.expandMetaAlert(0); - tablePage.clickClearSearch(); - expect(tablePage.getChangesAlertTableTitle('Alerts (1)')).toEqual('Alerts (150)'); + await tablePage.setSearchText('guid:c894bbcf-3195-0708-aebe-0574cf0cc1fe', '150'); + expect(await tablePage.getChangesAlertTableTitle('Alerts (150)')).toEqual('Alerts (1)'); + await tablePage.expandMetaAlert(0); + expect(await tablePage.getAllRowsCount()).toEqual(21); + await tablePage.expandMetaAlert(0); + await tablePage.clickClearSearch('150'); + expect(await tablePage.getChangesAlertTableTitle('Alerts (1)')).toEqual('Alerts (150)'); // Delete a meta alert from the middle and check the data - tablePage.expandMetaAlert(0); - expect(tablePage.getTableCellValues(3, 1, 21)).toEqual(alertsInMetaAlerts); - tablePage.removeAlert(5); - treePage.clickYesForConfirmation(); - expect(tablePage.getCellValue(0, 2, '(20')).toContain('(19)', 'alert count should be decremented'); - expect(tablePage.getTableCellValues(3, 1, 20)).toEqual(alertsAfterDeletedInMetaAlerts); + await tablePage.expandMetaAlert(0); + let guidValues = await tablePage.getTableCellValues(3, 1, 21); + guidValues = guidValues.slice(1, 21).sort(); + expect(guidValues).toEqual(alertsInMetaAlerts.sort()); + await tablePage.removeAlert(5); + await treePage.clickYesForConfirmation(); + expect(await tablePage.getCellValue(0, 2, '(20')).toContain('(19)', 'alert count should be decremented'); + let guidValuesAfterDeleteOp = await tablePage.getTableCellValues(3, 1, 20); + guidValuesAfterDeleteOp = guidValuesAfterDeleteOp.slice(1, 20).sort(); + expect(guidValuesAfterDeleteOp).toEqual(alertsAfterDeletedInMetaAlerts.sort()); //Remove the meta alert - tablePage.removeAlert(0); - treePage.clickYesForConfirmation(); + await tablePage.removeAlert(0); + await treePage.clickYesForConfirmation(); }); }); http://git-wip-us.apache.org/repos/asf/metron/blob/436cec43/metron-interface/metron-alerts/e2e/alerts-list/meta-alerts/meta-alert.po.ts ---------------------------------------------------------------------- diff --git a/metron-interface/metron-alerts/e2e/alerts-list/meta-alerts/meta-alert.po.ts b/metron-interface/metron-alerts/e2e/alerts-list/meta-alerts/meta-alert.po.ts index 762deb8..7f8f13e 100644 --- a/metron-interface/metron-alerts/e2e/alerts-list/meta-alerts/meta-alert.po.ts +++ b/metron-interface/metron-alerts/e2e/alerts-list/meta-alerts/meta-alert.po.ts @@ -17,27 +17,36 @@ */ import {browser, element, by} from 'protractor'; +import {waitForElementInVisibility, waitForElementVisibility} from '../../utils/e2e_util'; export class MetaAlertPage { + waitForDialog() { + return waitForElementVisibility(element(by.css('app-meta-alerts'))) + .then(() => browser.sleep(2000)); + } + getPageTitle() { - return element(by.css('app-meta-alerts .form-title')).getText(); + let elementFinder = element(by.css('app-meta-alerts .form-title')); + return waitForElementVisibility(elementFinder).then(() => elementFinder.getText()) } getMetaAlertsTitle() { - return element(by.css('app-meta-alerts .title')).getText(); + let elementFinder = element(by.css('app-meta-alerts .title')); + return waitForElementVisibility(elementFinder).then(() => elementFinder.getText()); } getAvailableMetaAlerts() { - return element(by.css('app-meta-alerts .guid-name-container div')).getText(); + return waitForElementVisibility(element(by.css('app-meta-alerts .guid-name-container div'))) + .then(() => element(by.css('app-meta-alerts .guid-name-container div')).getText()); } selectRadio() { - return element.all(by.css('app-meta-alerts .checkmark')).click(); + return element.all(by.css('app-meta-alerts .checkmark')).get(0).click(); } addToMetaAlert() { - element.all(by.css('app-meta-alerts')).get(0).element(by.buttonText('ADD')).click(); - browser.sleep(2000); + return element.all(by.css('app-meta-alerts')).get(0).element(by.buttonText('ADD')).click() + .then(() => waitForElementInVisibility(element(by.css('app-meta-alerts')))); } } http://git-wip-us.apache.org/repos/asf/metron/blob/436cec43/metron-interface/metron-alerts/e2e/alerts-list/save-search/save-search.e2e-spec.ts ---------------------------------------------------------------------- diff --git a/metron-interface/metron-alerts/e2e/alerts-list/save-search/save-search.e2e-spec.ts b/metron-interface/metron-alerts/e2e/alerts-list/save-search/save-search.e2e-spec.ts index 350f11e..cab8455 100644 --- a/metron-interface/metron-alerts/e2e/alerts-list/save-search/save-search.e2e-spec.ts +++ b/metron-interface/metron-alerts/e2e/alerts-list/save-search/save-search.e2e-spec.ts @@ -21,19 +21,20 @@ import {MetronAlertsPage} from '../alerts-list.po'; import {LoginPage} from '../../login/login.po'; import {loadTestData, deleteTestData} from '../../utils/e2e_util'; -describe('metron-alerts Search', function() { +describe('Test spec for search and save search', function() { let page: MetronAlertsPage; let loginPage: LoginPage; - beforeAll(() => { - loadTestData(); + beforeAll(async function() : Promise<any> { loginPage = new LoginPage(); - loginPage.login(); + + await loadTestData(); + await loginPage.login(); }); - afterAll(() => { - loginPage.logout(); - deleteTestData(); + afterAll(async function() : Promise<any> { + await loginPage.logout(); + await deleteTestData(); }); beforeEach(() => { @@ -41,57 +42,57 @@ describe('metron-alerts Search', function() { jasmine.addMatchers(customMatchers); }); - it('should display all the default values for saved searches', () => { - page.clearLocalStorage(); - page.navigateTo(); + it('should display all the default values for saved searches', async function() : Promise<any> { + await page.clearLocalStorage(); + await page.navigateTo(); - page.clickSavedSearch(); - expect(page.getSavedSearchTitle()).toEqualBcoz('Searches', 'for saved searches title'); - expect(page.getRecentSearchOptions()).toEqualBcoz([], 'for recent search options'); - expect(page.getSavedSearchOptions()).toEqualBcoz([], 'for saved search options'); - expect(page.getDefaultRecentSearchValue()).toEqualBcoz([ 'No Recent Searches' ], 'for recent search default value'); - expect(page.getDefaultSavedSearchValue()).toEqualBcoz([ 'No Saved Searches' ], 'for saved search default value'); - page.clickCloseSavedSearch(); + await page.clickSavedSearch(); + expect(await page.getSavedSearchTitle()).toEqualBcoz('Searches', 'for saved searches title'); + expect(await page.getRecentSearchOptions()).toEqualBcoz([], 'for recent search options'); + expect(await page.getSavedSearchOptions()).toEqualBcoz([], 'for saved search options'); + expect(await page.getDefaultRecentSearchValue()).toEqualBcoz([ 'No Recent Searches' ], 'for recent search default value'); + expect(await page.getDefaultSavedSearchValue()).toEqualBcoz([ 'No Saved Searches' ], 'for saved search default value'); + await page.clickCloseSavedSearch(); }); - it('should have all save search controls and they save search should be working', () => { - page.saveSearch('e2e-1'); - page.clickSavedSearch(); - expect(page.getSavedSearchOptions()).toEqualBcoz([ 'e2e-1' ], 'for saved search options e2e-1'); - page.clickCloseSavedSearch(); + it('should have all save search controls and they save search should be working', async function() : Promise<any> { + await page.saveSearch('e2e-1'); + await page.clickSavedSearch(); + expect(await page.getSavedSearchOptions()).toEqualBcoz([ 'e2e-1' ], 'for saved search options e2e-1'); + await page.clickCloseSavedSearch(); }); - it('should populate search items when selected on table', () => { - page.clickTableText('US'); - expect(page.getSearchText()).toEqualBcoz('enrichments:geo:ip_dst_addr:country:US', 'for search text ip_dst_addr_country US'); - page.clickClearSearch(); - expect(page.getSearchText()).toEqualBcoz('*', 'for clear search'); - }); + it('should delete search items from search box', async function() : Promise<any> { + await page.clickClearSearch(); + expect(await page.getSearchText()).toEqual('*'); + expect(await page.getChangesAlertTableTitle('')).toEqual('Alerts (169)'); - it('should delete search items from search box', () => { - page.clickTableText('US'); - expect(page.getSearchText()).toEqualBcoz('enrichments:geo:ip_dst_addr:country:US', 'for search text ip_dst_addr_country US'); - page.clickRemoveSearchChip(); - expect(page.getSearchText()).toEqualBcoz('*', 'for search chip remove'); + expect(await page.clickTableTextAndGetSearchText('FR', 'enrichments:geo:ip_dst_addr:country:FR')).toEqualBcoz('enrichments:geo:ip_dst_addr:country:FR', 'for search text ip_dst_addr_country FR'); + expect(await page.clickRemoveSearchChipAndGetSearchText('*')).toEqualBcoz('*', 'for search chip remove'); }); - it('should delete first search items from search box having multiple search fields', () => { - page.clickTableText('US'); - page.clickTableText('alerts_ui_e2e'); - expect(page.getSearchText()).toEqual('enrichments:geo:ip_dst_addr:country:US AND source:type:alerts_ui_e2e', 'for search text US and alerts_ui_e2e'); - page.clickRemoveSearchChip(); - expect(page.getSearchText()).toEqual('source:type:alerts_ui_e2e', 'for search text alerts_ui_e2e after US is removed'); - page.clickRemoveSearchChip(); - expect(page.getSearchText()).toEqualBcoz('*', 'for search chip remove for two search texts'); + it('should delete first search items from search box having multiple search fields', async function() : Promise<any> { + await page.clickClearSearch(); + expect(await page.getSearchText()).toEqual('*'); + expect(await page.getChangesAlertTableTitle('')).toEqual('Alerts (169)'); + + expect(await page.clickTableTextAndGetSearchText('FR', 'enrichments:geo:ip_dst_addr:country:FR')).toEqual('enrichments:geo:ip_dst_addr:country:FR'); + expect(await page.clickTableTextAndGetSearchText('alerts_ui_e2e', 'enrichments:geo:ip_dst_addr:country:FR AND source:type:alerts_ui_e2e')).toEqual('enrichments:geo:ip_dst_addr:country:FR AND source:type:alerts_ui_e2e'); + + expect(await page.clickRemoveSearchChipAndGetSearchText('source:type:alerts_ui_e2e')).toEqual('source:type:alerts_ui_e2e'); + expect(await page.clickRemoveSearchChipAndGetSearchText('*')).toEqual('*'); }); - it('manually entering search queries to search box and pressing enter key should search', () => { - page.setSearchText('enrichments:geo:ip_dst_addr:country:US'); - expect(page.getPaginationText()).toEqualBcoz('1 - 22 of 22', + it('manually entering search queries to search box and pressing enter key should search', async function() : Promise<any> { + await page.setSearchText('enrichments:geo:ip_dst_addr:country:US'); + expect(await page.getChangesAlertTableTitle('Alerts (169)')).toEqual('Alerts (22)'); + expect(await page.getPaginationText()).toEqualBcoz('1 - 22 of 22', 'for pagination text with search text enrichments:geo:ip_dst_addr:country:US'); - page.setSearchText('enrichments:geo:ip_dst_addr:country:RU'); - expect(page.getPaginationText()).toEqualBcoz('1 - 25 of 44', + + await page.setSearchText('enrichments:geo:ip_dst_addr:country:RU'); + expect(await page.getChangesAlertTableTitle('Alerts (169)')).toEqual('Alerts (44)'); + expect(await page.getPaginationText()).toEqualBcoz('1 - 25 of 44', 'for pagination text with search text enrichments:geo:ip_dst_addr:country:RU as text'); }); http://git-wip-us.apache.org/repos/asf/metron/blob/436cec43/metron-interface/metron-alerts/e2e/alerts-list/tree-view/tree-view.e2e-spec.ts ---------------------------------------------------------------------- diff --git a/metron-interface/metron-alerts/e2e/alerts-list/tree-view/tree-view.e2e-spec.ts b/metron-interface/metron-alerts/e2e/alerts-list/tree-view/tree-view.e2e-spec.ts index 339b19f..3129674 100644 --- a/metron-interface/metron-alerts/e2e/alerts-list/tree-view/tree-view.e2e-spec.ts +++ b/metron-interface/metron-alerts/e2e/alerts-list/tree-view/tree-view.e2e-spec.ts @@ -19,46 +19,55 @@ import {customMatchers} from '../../matchers/custom-matchers'; import {LoginPage} from '../../login/login.po'; import {TreeViewPage} from './tree-view.po'; -import {loadTestData, deleteTestData} from '../../utils/e2e_util'; import {MetronAlertsPage} from '../alerts-list.po'; -describe('metron-alerts tree view', function () { +import {loadTestData, deleteTestData} from '../../utils/e2e_util'; + +describe('Test spec for tree view', function () { let page: TreeViewPage; let listPage: MetronAlertsPage; let loginPage: LoginPage; - beforeAll(() => { - loadTestData(); + beforeAll(async function() : Promise<any> { loginPage = new LoginPage(); page = new TreeViewPage(); listPage = new MetronAlertsPage(); - loginPage.login(); - page.navigateToAlertsList(); + + await loadTestData(); + await loginPage.login(); + jasmine.addMatchers(customMatchers); }); - afterAll(() => { - loginPage.logout(); - deleteTestData(); + + afterAll(async function() : Promise<any> { + await loginPage.logout(); + await deleteTestData(); }); beforeEach(() => { - jasmine.addMatchers(customMatchers); + }); - it('should have all group by elements', () => { + it('should have all group by elements', async function() : Promise<any> { let groupByItems = { 'source:type': '1', 'ip_dst_addr': '8', 'enrichm...:country': '3', 'ip_src_addr': '2' }; - expect(page.getGroupByCount()).toEqualBcoz(Object.keys(groupByItems).length, '4 Group By Elements should be present'); - expect(page.getGroupByItemNames()).toEqualBcoz(Object.keys(groupByItems), 'Group By Elements names should be present'); - expect(page.getGroupByItemCounts()).toEqualBcoz(Object.keys(groupByItems).map(key => groupByItems[key]), + + expect(await listPage.getChangesAlertTableTitle('Alerts (0)')).toEqualBcoz('Alerts (169)', 'for alerts title'); + + expect(await page.getGroupByCount()).toEqualBcoz(Object.keys(groupByItems).length, '4 Group By Elements should be present'); + expect(await page.getGroupByItemNames()).toEqualBcoz(Object.keys(groupByItems), 'Group By Elements names should be present'); + expect(await page.getGroupByItemCounts()).toEqualBcoz(Object.keys(groupByItems).map(key => groupByItems[key]), '4 Group By Elements values should be present'); }); - it('drag and drop should change group order', () => { +// HTML5 Drag and Drop with Selenium Webdriver issue effects this test: +// https://github.com/SeleniumHQ/selenium-google-code-issue-archive/issues/3604 + + xit('drag and drop should change group order', async function() : Promise<any> { let before = { 'firstDashRow': ['0', 'alerts_ui_e2e', 'ALERTS', '169'], 'firstSubGroup': '0 US (22)', @@ -75,105 +84,110 @@ describe('metron-alerts tree view', function () { 'thirdDashSubGroup': '0 alerts_ui_e2e (25)' }; - page.selectGroup('source:type'); - page.selectGroup('enrichments:geo:ip_dst_addr:country'); - page.expandDashGroup('alerts_ui_e2e'); - expect(page.getDashGroupValues('alerts_ui_e2e')).toEqualBcoz(before.firstDashRow, 'First Dash Row should be correct'); - expect(page.getSubGroupValues('alerts_ui_e2e', 'US')).toEqualBcoz(before.firstSubGroup, + await page.selectGroup('source:type'); + await page.selectGroup('enrichments:geo:ip_dst_addr:country'); + expect(await page.getDashGroupValues('alerts_ui_e2e')).toEqualBcoz(before.firstDashRow, 'First Dash Row should be correct'); + + await page.expandDashGroup('alerts_ui_e2e'); + expect(await page.getSubGroupValues('alerts_ui_e2e', 'US')).toEqualBcoz(before.firstSubGroup, 'Dash Group Values should be correct for US'); - expect(page.getSubGroupValues('alerts_ui_e2e', 'RU')).toEqualBcoz(before.secondSubGroup, + expect(await page.getSubGroupValues('alerts_ui_e2e', 'RU')).toEqualBcoz(before.secondSubGroup, 'Dash Group Values should be present for RU'); - expect(page.getSubGroupValues('alerts_ui_e2e', 'FR')).toEqualBcoz(before.thirdSubGroup, + expect(await page.getSubGroupValues('alerts_ui_e2e', 'FR')).toEqualBcoz(before.thirdSubGroup, 'Dash Group Values should be present for FR'); - page.dragGroup('source:type', 'ip_src_addr'); - //page.selectGroup('source:type'); - expect(page.getDashGroupValues('US')).toEqualBcoz(after.firstDashRow, 'First Dash Row after ' + + await page.simulateDragAndDrop('source:type', 'ip_src_addr'); + + expect(await page.getDashGroupValues('US')).toEqualBcoz(after.firstDashRow, 'First Dash Row after ' + 'reorder should be correct'); - expect(page.getDashGroupValues('RU')).toEqualBcoz(after.secondDashRow, 'Second Dash Row after ' + + expect(await page.getDashGroupValues('RU')).toEqualBcoz(after.secondDashRow, 'Second Dash Row after ' + 'reorder should be correct'); - expect(page.getDashGroupValues('FR')).toEqualBcoz(after.thirdDashRow, 'Third Dash Row after ' + + expect(await page.getDashGroupValues('FR')).toEqualBcoz(after.thirdDashRow, 'Third Dash Row after ' + 'reorder should be correct'); - page.expandDashGroup('US'); - expect(page.getSubGroupValues('US', 'alerts_ui_e2e')).toEqualBcoz(after.firstDashSubGroup, + await page.expandDashGroup('US'); + expect(await page.getSubGroupValues('US', 'alerts_ui_e2e')).toEqualBcoz(after.firstDashSubGroup, 'First Dash Group Values should be present for alerts_ui_e2e'); - page.expandDashGroup('RU'); - expect(page.getSubGroupValues('RU', 'alerts_ui_e2e')).toEqualBcoz(after.secondDashSubGroup, + await page.expandDashGroup('RU'); + expect(await page.getSubGroupValues('RU', 'alerts_ui_e2e')).toEqualBcoz(after.secondDashSubGroup, 'Second Dash Group Values should be present for alerts_ui_e2e'); - page.expandDashGroup('FR'); - expect(page.getSubGroupValues('FR', 'alerts_ui_e2e')).toEqualBcoz(after.thirdDashSubGroup, + await page.expandDashGroup('FR'); + expect(await page.getSubGroupValues('FR', 'alerts_ui_e2e')).toEqualBcoz(after.thirdDashSubGroup, 'Third Dash Group Values should be present for alerts_ui_e2e'); - page.dragGroup('source:type', 'ip_dst_addr'); - page.unGroup(); + await page.simulateDragAndDrop('source:type', 'ip_dst_addr'); + await page.unGroup(); + }); - it('should have group details for single group by', () => { + // Test cannot pass until issue with missing dash score is resolved: https://issues.apache.org/jira/browse/METRON-1631 + xit('should have group details for single group by', async function() : Promise<any> { let dashRowValues = ['0', 'alerts_ui_e2e', 'ALERTS', '169']; - let row1_page1 = ['-', 'dcda4423-7...0962fafc47', '2017-09-13 17:59:32', 'alerts_ui_e2e', - '192.168.138.158', 'US', '72.34.49.86', 'comarksecurity.com', 'NEW', '', '']; - let row1_page2 = ['-', '07b29c29-9...ff19eaa888', '2017-09-13 17:59:37', 'alerts_ui_e2e', - '192.168.138.158', 'FR', '62.75.195.236', '62.75.195.236', 'NEW', '', '']; + let row1_page1 = ['-','acf5a641-9...a316e14fbe', '2017-09-13 17:59:35', 'alerts_ui_e2e', + '192.168.66.1', '', '192.168.66.121', 'node1', 'NEW']; + let row1_page2 = ['-', '3097a3d9-f...1cfb870355', '2017-09-13 18:00:22', 'alerts_ui_e2e', + '192.168.66.1', '','192.168.66.121', 'node1', 'NEW']; - page.selectGroup('source:type'); - expect(page.getActiveGroups()).toEqualBcoz(['source:type'], 'only source type group should be selected'); - expect(page.getDashGroupValues('alerts_ui_e2e')).toEqualBcoz(dashRowValues, 'Dash Group Values should be present'); + await page.unGroup(); + await page.selectGroup('source:type'); + expect(await page.getActiveGroups()).toEqualBcoz(['source:type'], 'only source type group should be selected'); + expect(await page.getDashGroupValues('alerts_ui_e2e')).toEqualBcoz(dashRowValues, 'Dash Group Values should be present'); - page.expandDashGroup('alerts_ui_e2e'); - expect(page.getDashGroupTableValuesForRow('alerts_ui_e2e', 0)).toEqualBcoz(row1_page1, 'Dash Group Values should be present'); + await page.expandDashGroup('alerts_ui_e2e'); + expect(await page.getTableValuesByRowId('alerts_ui_e2e', 0, 'acf5a641-9...a316e14fbe')).toEqualBcoz(row1_page1, 'Dash Group Values should be present'); - page.clickOnNextPage('alerts_ui_e2e'); - expect(page.getTableValuesByRowId('alerts_ui_e2e', 0, 'FR')).toEqualBcoz(row1_page2, 'Dash Group Values should be present'); + await page.clickOnNextPage('alerts_ui_e2e'); + expect(await page.getTableValuesByRowId('alerts_ui_e2e', 0, '3097a3d9-f...1cfb870355')).toEqualBcoz(row1_page2, 'Dash Group Values should be present'); - page.unGroup(); - expect(page.getActiveGroups()).toEqualBcoz([], 'no groups should be selected'); + await page.unGroup(); + expect(await page.getActiveGroups()).toEqualBcoz([], 'no groups should be selected'); }); - it('should have group details for multiple group by', () => { + it('should have group details for multiple group by', async function() : Promise<any> { - let usGroupIds = ['9a969c64-b...001cb011a3','a651f7c3-1...a97d4966c9','afc36901-3...d931231ab2','d860ac35-1...f9e282d571','04a5c3d0-9...af17c06fbc']; - let frGroupIds = ['07b29c29-9...ff19eaa888','7cd91565-1...de5be54a6e','ca5bde58-a...f3a88d2df4','5d6faf83-8...b88a407647','e2883424-f...79bb8b0606']; + let usGroupIds = ['a651f7c3-1...a97d4966c9', '5cfff1c7-6...ef3d766fc7', '7022e863-5...3c1fb629ed', '5404950f-9...86ce704b22', '8eb077ae-3...b77fed1ab4']; + let frGroupIds = ['07b29c29-9...ff19eaa888', 'c27f0bd2-3...697eaf8692', 'ba44eb73-6...6f9c15b261', '6a437817-e...dd0b37d280', '48fc3a55-4...3479974d34']; - page.selectGroup('source:type'); - page.selectGroup('ip_dst_addr'); - page.selectGroup('enrichments:geo:ip_dst_addr:country'); - expect(page.getActiveGroups()).toEqualBcoz(['source:type', 'ip_dst_addr', 'enrichments:geo:ip_dst_addr:country'], '3 groups should be selected'); + await page.unGroup(); + await page.selectGroup('source:type'); + await page.selectGroup('ip_dst_addr'); + await page.selectGroup('enrichments:geo:ip_dst_addr:country'); + expect(await page.getActiveGroups()).toEqualBcoz(['source:type', 'ip_dst_addr', 'enrichm...:country'], '3 groups should be selected'); - expect(page.getDashGroupValues('alerts_ui_e2e')).toEqualBcoz(['0', 'alerts_ui_e2e', 'ALERTS', '169'], + expect(await page.getDashGroupValues('alerts_ui_e2e')).toEqualBcoz(['0', 'alerts_ui_e2e', 'ALERTS', '169'], 'Top Level Group Values should be present for alerts_ui_e2e'); - page.expandDashGroup('alerts_ui_e2e'); - expect(page.getSubGroupValuesByPosition('alerts_ui_e2e', '204.152.254.221', 0)).toEqualBcoz('0 204.152.254.221 (13)', + await page.expandDashGroup('alerts_ui_e2e'); + expect(await page.getSubGroupValuesByPosition('alerts_ui_e2e', '204.152.254.221', 0)).toEqualBcoz('0 204.152.254.221 (13)', 'Second Level Group Values should be present for 204.152.254.221'); - page.expandSubGroupByPosition('alerts_ui_e2e', '204.152.254.221', 0); - expect(page.getSubGroupValuesByPosition('alerts_ui_e2e', 'US', 0)).toEqualBcoz('0 US (13)', + await page.expandSubGroupByPosition('alerts_ui_e2e', '204.152.254.221', 0); + expect(await page.getSubGroupValuesByPosition('alerts_ui_e2e', 'US', 0)).toEqualBcoz('0 US (13)', 'Third Level Group Values should be present for US'); - page.expandSubGroup('alerts_ui_e2e', 'US'); - expect(page.getSubGroupValuesByPosition('alerts_ui_e2e', 'US', 0)).toEqualBcoz('0 US (13)', + await page.expandSubGroup('alerts_ui_e2e', 'US'); + expect(await page.getSubGroupValuesByPosition('alerts_ui_e2e', 'US', 0)).toEqualBcoz('0 US (13)', 'Third Level Group Values should not change when expanded for US'); - expect(page.getCellValuesFromTable('alerts_ui_e2e', 'id', '04a5c3d0-9...af17c06fbc')).toEqual(usGroupIds, 'rows should be present for US'); + expect(await page.getCellValuesFromTable('alerts_ui_e2e', 'id', 'a651f7c3-1...a97d4966c9')).toEqual(usGroupIds, 'rows should be present for US'); - page.expandSubGroup('alerts_ui_e2e', '62.75.195.236'); - expect(page.getSubGroupValuesByPosition('alerts_ui_e2e', 'FR', 1)).toEqualBcoz('0 FR (23)', + await page.expandSubGroup('alerts_ui_e2e', '62.75.195.236'); + expect(await page.getSubGroupValuesByPosition('alerts_ui_e2e', 'FR', 1)).toEqualBcoz('0 FR (23)', 'Third Level Group Values should be present for FR'); - page.expandSubGroupByPosition('alerts_ui_e2e', 'FR', 1); - expect(page.getSubGroupValuesByPosition('alerts_ui_e2e', 'FR', 1)).toEqualBcoz('0 FR (23)', + await page.expandSubGroupByPosition('alerts_ui_e2e', 'FR', 1); + expect(await page.getSubGroupValuesByPosition('alerts_ui_e2e', 'FR', 1)).toEqualBcoz('0 FR (23)', 'Third Level Group Values should not change when expanded for FR'); - expect(page.getCellValuesFromTable('alerts_ui_e2e', 'id', 'e2883424-f...79bb8b0606')).toEqual(usGroupIds.concat(frGroupIds), 'rows should be present for FR'); - - page.unGroup(); - expect(page.getActiveGroups()).toEqualBcoz([], 'no groups should be selected'); + expect(await page.getCellValuesFromTable('alerts_ui_e2e', 'id', '07b29c29-9...ff19eaa888')).toEqual(usGroupIds.concat(frGroupIds), 'rows should be present for FR'); + + await page.unGroup(); + expect(await page.getActiveGroups()).toEqualBcoz([], 'no groups should be selected'); }); - it('should have sort working for group details for multiple sub groups', () => { + it('should have sort working for group details for multiple sub groups', async function() : Promise<any> { let usTSCol = ['2017-09-13 17:59:32', '2017-09-13 17:59:42', '2017-09-13 17:59:53', '2017-09-13 18:00:02', '2017-09-13 18:00:14']; let ruTSCol = ['2017-09-13 17:59:33', '2017-09-13 17:59:48', '2017-09-13 17:59:51', '2017-09-13 17:59:54', '2017-09-13 17:59:57']; @@ -183,50 +197,52 @@ describe('metron-alerts tree view', function () { let ruSortedTSCol = ['2017-09-14 06:29:40', '2017-09-14 06:29:40', '2017-09-14 06:29:40', '2017-09-14 06:29:40', '2017-09-13 18:02:13']; let frSortedTSCol = ['2017-09-14 06:29:40', '2017-09-14 04:29:40', '2017-09-13 18:02:20', '2017-09-13 18:02:05', '2017-09-13 18:02:04']; - page.selectGroup('source:type'); - page.selectGroup('enrichments:geo:ip_dst_addr:country'); + await page.unGroup(); + await page.selectGroup('source:type'); + await page.selectGroup('enrichments:geo:ip_dst_addr:country'); - page.expandDashGroup('alerts_ui_e2e'); - page.expandSubGroup('alerts_ui_e2e', 'US'); - page.expandSubGroup('alerts_ui_e2e', 'RU'); - page.expandSubGroup('alerts_ui_e2e', 'FR'); + await page.expandDashGroup('alerts_ui_e2e'); + await page.expandSubGroup('alerts_ui_e2e', 'US'); + await page.expandSubGroup('alerts_ui_e2e', 'RU'); + await page.expandSubGroup('alerts_ui_e2e', 'FR'); let unsortedTS = [...usTSCol, ...ruTSCol, ...frTSCol]; let sortedTS = [...usSortedTSCol, ...ruSortedTSCol, ...frSortedTSCol]; - page.sortSubGroup('alerts_ui_e2e', 'timestamp'); + await page.sortSubGroup('alerts_ui_e2e', 'timestamp'); - expect(page.getCellValuesFromTable('alerts_ui_e2e', 'timestamp', '2017-09-13 18:00:37')).toEqual(unsortedTS, + expect(await page.getCellValuesFromTable('alerts_ui_e2e', 'timestamp', '2017-09-13 18:00:37')).toEqual(unsortedTS, 'timestamp should be sorted asc'); - page.sortSubGroup('alerts_ui_e2e', 'timestamp'); + await page.sortSubGroup('alerts_ui_e2e', 'timestamp'); - expect(page.getCellValuesFromTable('alerts_ui_e2e', 'timestamp', '2017-09-13 18:02:04')).toEqual(sortedTS, + expect(await page.getCellValuesFromTable('alerts_ui_e2e', 'timestamp', '2017-09-13 18:02:04')).toEqual(sortedTS, 'timestamp should be sorted dsc'); - page.unGroup(); + await page.unGroup(); expect(page.getActiveGroups()).toEqualBcoz([], 'no groups should be selected'); }); - it('should have search working for group details for multiple sub groups', () => { + it('should have search working for group details for multiple sub groups', async function() : Promise<any> { + + await page.unGroup(); + await listPage.setSearchText('enrichments:geo:ip_dst_addr:country:FR'); + + expect(await listPage.getChangesAlertTableTitle('Alerts (169)')).toEqual('Alerts (25)'); - page.selectGroup('source:type'); - page.selectGroup('enrichments:geo:ip_dst_addr:country'); + await page.selectGroup('source:type'); + await page.selectGroup('enrichments:geo:ip_dst_addr:country'); - page.expandDashGroup('alerts_ui_e2e'); - expect(page.getNumOfSubGroups('alerts_ui_e2e')).toEqual(3, 'three sub groups should be present'); + await page.expandDashGroup('alerts_ui_e2e'); + expect(await page.getNumOfSubGroups('alerts_ui_e2e')).toEqual(1, 'three sub groups should be present'); - listPage.setSearchText('enrichments:geo:ip_dst_addr:country:FR'); - expect(page.getNumOfSubGroups('alerts_ui_e2e')).toEqual(1, 'one sub groups should be present'); - page.expandSubGroup('alerts_ui_e2e', 'FR'); + await page.expandSubGroup('alerts_ui_e2e', 'FR'); let expected = ['FR', 'FR', 'FR', 'FR', 'FR']; - expect(page.getCellValuesFromTable('alerts_ui_e2e', 'enrichments:geo:ip_dst_addr:country', 'FR')).toEqual(expected, + expect(await page.getCellValuesFromTable('alerts_ui_e2e', 'enrichments:geo:ip_dst_addr:country', 'FR')).toEqual(expected, 'id should be sorted'); - - page.unGroup(); - expect(page.getActiveGroups()).toEqualBcoz([], 'no groups should be selected'); + await page.unGroup(); }); }); http://git-wip-us.apache.org/repos/asf/metron/blob/436cec43/metron-interface/metron-alerts/e2e/alerts-list/tree-view/tree-view.po.ts ---------------------------------------------------------------------- diff --git a/metron-interface/metron-alerts/e2e/alerts-list/tree-view/tree-view.po.ts b/metron-interface/metron-alerts/e2e/alerts-list/tree-view/tree-view.po.ts index 368f709..047578a 100644 --- a/metron-interface/metron-alerts/e2e/alerts-list/tree-view/tree-view.po.ts +++ b/metron-interface/metron-alerts/e2e/alerts-list/tree-view/tree-view.po.ts @@ -16,42 +16,47 @@ * limitations under the License. */ -import {browser, element, by} from 'protractor'; +import { browser, element, by } from 'protractor'; import { waitForElementPresence, waitForTextChange, waitForElementVisibility, - waitForElementInVisibility + waitForElementInVisibility, waitForCssClass, waitForStalenessOf, + waitForElementCountGreaterThan, reduce_for_get_all, scrollIntoView } from '../../utils/e2e_util'; export class TreeViewPage { navigateToAlertsList() { - browser.waitForAngularEnabled(false); return browser.get('/alerts-list'); } clickOnRow(id: string) { let idElement = element(by.css('a[title="' + id +'"]')); - waitForElementPresence(idElement) + let td = idElement.element(by.xpath('../..')).all(by.css('td')).get(9); + let detailsPane = element(by.css('.metron-slider-pane-details')); + return waitForElementPresence(idElement) .then(() => browser.actions().mouseMove(idElement).perform()) - .then(() => idElement.element(by.xpath('../..')).all(by.css('td')).get(9).click()); - browser.sleep(2000); + .then(() => browser.actions().mouseMove(td).perform()) + .then(() => browser.actions().click().perform()) + .then(() => waitForElementVisibility(detailsPane)) + .then(() => browser.sleep(2000)); } getActiveGroups() { - return element.all(by.css('app-group-by .group-by-items.active')).getAttribute('data-name'); + return waitForElementCountGreaterThan('app-group-by .group-by-items .name', 4) + .then(() => element.all(by.css('app-group-by .group-by-items.active .name')).reduce(reduce_for_get_all(), [])); } getGroupByCount() { - return waitForElementPresence(element.all(by.css('app-group-by .group-by-items'))).then(() => { + return waitForElementPresence(element(by.css('app-group-by .group-by-items'))).then(() => { return element.all(by.css('app-group-by .group-by-items')).count(); }); } getGroupByItemNames() { - return element.all(by.css('app-group-by .group-by-items .name')).getText(); + return element.all(by.css('app-group-by .group-by-items .name')).reduce(reduce_for_get_all(), []); } getGroupByItemCounts() { - return element.all(by.css('app-group-by .group-by-items .count')).getText(); + return element.all(by.css('app-group-by .group-by-items .count')).reduce(reduce_for_get_all(), []); } getSubGroupValues(name: string, rowName: string) { @@ -63,31 +68,79 @@ export class TreeViewPage { } selectGroup(name: string) { - return element(by.css('app-group-by div[data-name="' + name + '"]')).click(); - } - - dragGroup(from: string, to: string) { - browser.actions().dragAndDrop( - element(by.css('app-group-by div[data-name="' + from + '"]')), - element(by.css('app-group-by div[data-name="' + to + '"]')) - ).perform(); - } - - getDashGroupValues(name: string) { - return waitForElementPresence(element(by.css('[data-name="' + name + '"] .card-header span'))).then(() => { - return element.all(by.css('[data-name="' + name + '"] .card-header span')).getText(); - }); + return element(by.css('app-group-by div[data-name="' + name + '"]')).click() + .then(() => waitForCssClass(element(by.css('app-group-by div[data-name="' + name + '"]')), 'active')) + .then(() => browser.waitForAngular()); + } + + async simulateDragAndDrop(target: string, destination: string) { + target = `app-group-by div[data-name=\"${target}\"]`; + destination = `app-group-by div[data-name=\"${destination}\"]`; + return await browser.executeScript((target, destination) => { + let getEventOptions = (el, relatedElement) => { + //coordinates from destination element + const coords = el.getBoundingClientRect(); + const x = coords.x || coords.left; + const y = coords.y || coords.top; + return { + x: x, + y: y, + clientX: x, + clientY: y, + screenX: x, + screenY: y, + //target reference + relatedTarget: relatedElement + }; + }; + + let raise = (el, type, options?) => { + const o = options || { which: 1 }; + const e = document.createEvent('Event'); + e.initEvent(type, true, true); + Object.keys(o).forEach(apply); + el.dispatchEvent(e); + function apply(key) { + e[key] = o[key]; + } + }; + + + let targetEl = document.querySelector(target); + let destinationEl = document.querySelector(destination); + let options = getEventOptions(destinationEl, targetEl); + + //start drag + raise(targetEl, 'mousedown'); + raise(targetEl, 'mousemove'); + //set event on location + raise(destinationEl, 'mousemove', options); + //drop + raise(destinationEl, 'mouseup', options); + + }, target, destination); + } + + async getDashGroupValues(name: string) { + let dashScore = await element(by.css('[data-name="' + name + '"] .dash-score')).getText(); + let groupName = await element(by.css('[data-name="' + name + '"] .text-light.severity-padding .title')).getText(); + let title = await element(by.css('[data-name="' + name + '"] .text-light.two-line .text-dark')).getText(); + let count = await element(by.css('[data-name="' + name + '"] .text-light.two-line .title')).getText(); + + return Promise.all([dashScore, groupName, title, count]); } expandDashGroup(name: string) { let cardElement = element(by.css('.card[data-name="' + name +'"]')); - let downArrowElement = element(by.css('.card[data-name="' + name + '"] .mrow.top-group')); + let cardHeader = element(by.css('.card[data-name="' + name + '"] .card-header')); + let cardBody = element(by.css('.card[data-name="' + name + '"] .collapse')); - return waitForElementVisibility(cardElement) - .then(() => browser.actions().mouseMove(cardElement).perform()) - .then(() => waitForElementVisibility(downArrowElement)) - .then(() => downArrowElement.click()) - .then(() => browser.sleep(2000)); + return waitForElementPresence(cardBody) + .then(() => waitForElementVisibility(cardHeader)) + .then(() => browser.actions().mouseMove(element(by.css('.card[data-name="' + name + '"] .card-header .down-arrow'))).perform()) + .then(() => cardHeader.click()) + .then(() => waitForCssClass(cardBody, 'show')) + .then(() => waitForElementVisibility(element(by.css('.card[data-name="' + name + '"] .collapse table tbody tr:nth-child(1)')))); } expandSubGroup(groupName: string, rowName: string) { @@ -97,21 +150,14 @@ export class TreeViewPage { expandSubGroupByPosition(groupName: string, rowName: string, position: number) { let subGroupElement = element.all(by.css('[data-name="' + groupName + '"] tr[data-name="' + rowName + '"]')).get(position); return waitForElementVisibility(subGroupElement) - .then(() => browser.actions().mouseMove(subGroupElement).perform()) - .then(() => subGroupElement.click()); - } - - getDashGroupTableValuesForRow(name: string, rowId: number) { - this.scrollToDashRow(name); - return waitForElementPresence(element(by.css('[data-name="' + name + '"] table tbody tr'))).then(() => { - return element.all(by.css('[data-name="' + name + '"] table tbody tr')).get(rowId).all(by.css('td')).getText(); - }); + .then(() => scrollIntoView(subGroupElement.element(by.css('.fa-caret-right')), true)) + .then(() => subGroupElement.click()) + .then(() => waitForElementVisibility(subGroupElement.element(by.css('.fa-caret-down')))); } - getTableValuesByRowId(name: string, rowId: number, waitForAnchor: string) { - return waitForElementPresence(element(by. cssContainingText('[data-name="' + name + '"] a', waitForAnchor))).then(() => { - return element.all(by.css('[data-name="' + name + '"] table tbody tr')).get(rowId).all(by.css('td')).getText(); - }); + async getTableValuesByRowId(name: string, rowId: number, waitForAnchor: string) { + await waitForElementPresence(element(by. cssContainingText('[data-name="' + name + '"] a', waitForAnchor))); + return element.all(by.css('[data-name="' + name + '"] table tbody tr')).get(rowId).all(by.css('td a')).reduce(reduce_for_get_all(), []); } getTableValuesForRow(name: string, rowName: string, waitForAnchor: string) { @@ -122,9 +168,7 @@ export class TreeViewPage { scrollToDashRow(name: string) { let scrollToEle = element(by.css('[data-name="' + name + '"] .card-header')); - waitForElementPresence(scrollToEle).then(() => { - return browser.actions().mouseMove(scrollToEle).perform(); - }); + return scrollIntoView(scrollToEle, true); } clickOnNextPage(name: string) { @@ -132,12 +176,12 @@ export class TreeViewPage { } unGroup() { - return element(by.css('app-group-by .ungroup-button')).click(); + return element(by.css('app-group-by .ungroup-button')).click() + .then(() => waitForStalenessOf(element(by.css('app-tree-view')))); } getIdOfAllExpandedRows() { return element.all(by.css('[data-name="' + name + '"] table tbody tr')).then(row => { - browser.pause(); }); } @@ -146,26 +190,23 @@ export class TreeViewPage { } getCellValuesFromTable(groupName: string, cellName: string, waitForAnchor: string) { - return waitForElementPresence(element(by.cssContainingText('[data-name="' + cellName + '"] a', waitForAnchor))).then(() => { - return element.all(by.css('[data-name="' + groupName + '"] table tbody [data-name="' + cellName + '"]')).map(element => { - browser.actions().mouseMove(element).perform(); - return (element.getText()); - }); - }); + let waitForEle = element.all(by.cssContainingText(`[data-name="${cellName}"] a`, waitForAnchor)).get(0); + return waitForElementPresence(waitForEle) + .then(() => scrollIntoView(waitForEle, true)) + .then(() => element.all(by.css(`[data-name="${groupName}"] [data-name="${cellName}"]`)).reduce(reduce_for_get_all(), [])) } sortSubGroup(groupName: string, colName: string) { - return element.all(by.css('[data-name="' + groupName + '"] metron-config-sorter[title="' + colName + '"]')).click(); + return element(by.css(`[data-name="${groupName}"] metron-config-sorter[title="${colName}"]`)).click(); } toggleAlertInTree(index: number) { let selector = by.css('app-tree-view tbody tr'); let checkbox = element.all(selector).get(index).element(by.css('label')); - waitForElementPresence(checkbox).then(() => { - browser.actions().mouseMove(checkbox).perform().then(() => { - checkbox.click(); - }); - }); + + return waitForElementPresence(checkbox) + .then(() => browser.actions().mouseMove(checkbox).perform()) + .then(() => checkbox.click()); } getAlertStatusForTreeView(rowIndex: number, previousText) { @@ -195,7 +236,7 @@ export class TreeViewPage { clickNoForConfirmation() { let maskElement = element(by.className('modal-backdrop')); let closeButton = element(by.css('.metron-dialog')).element(by.buttonText('Cancel')); - waitForElementVisibility(maskElement) + return waitForElementVisibility(maskElement) .then(() => closeButton.click()) .then(() => waitForElementInVisibility(maskElement)); } @@ -203,7 +244,7 @@ export class TreeViewPage { clickYesForConfirmation() { let okButton = element(by.css('.metron-dialog')).element(by.buttonText('OK')); let maskElement = element(by.className('modal-backdrop')); - waitForElementVisibility(maskElement) + return waitForElementVisibility(maskElement) .then(() => okButton.click()) .then(() => waitForElementInVisibility(maskElement)); } @@ -211,4 +252,9 @@ export class TreeViewPage { waitForElementToDisappear(groupName: string) { return waitForElementInVisibility(element.all(by.css('[data-name="' + groupName + '"]'))); } + + waitForTextChangeAndExpand(groupName: string, subGroupName: string, previousValue: string) { + return waitForTextChange(element(by.css(`[data-name="${subGroupName}"] .group-value`)), previousValue) + .then(() => this.expandSubGroup(groupName, subGroupName)); + } } http://git-wip-us.apache.org/repos/asf/metron/blob/436cec43/metron-interface/metron-alerts/e2e/login/login.e2e-spec.ts ---------------------------------------------------------------------- diff --git a/metron-interface/metron-alerts/e2e/login/login.e2e-spec.ts b/metron-interface/metron-alerts/e2e/login/login.e2e-spec.ts index dc53889..337f286 100644 --- a/metron-interface/metron-alerts/e2e/login/login.e2e-spec.ts +++ b/metron-interface/metron-alerts/e2e/login/login.e2e-spec.ts @@ -16,29 +16,35 @@ * limitations under the License. */ import { LoginPage } from './login.po'; +import {deleteTestData, loadTestData} from '../utils/e2e_util'; -describe('login to application', function() { +describe('Test spec for login page', function() { let page: LoginPage; - beforeEach(() => { - page = new LoginPage(); + beforeAll(async function() : Promise<any> { + page = new LoginPage(); + await loadTestData(); }); - it('should display error message for invalid credentials', () => { - page.navigateToLogin(); - page.setUserNameAndPassword('admin', 'admin'); - page.submitLoginForm(); - expect(page.getErrorMessage()).toEqual('Login failed for admin'); + afterAll(async function() : Promise<any> { + await deleteTestData(); }); - it('should login for valid credentials', () => { - page.navigateToLogin(); - page.setUserNameAndPassword('admin', 'password'); - page.submitLoginForm(); + it('should display error message for invalid credentials', async function() : Promise<any> { + await page.navigateToLogin(); + await page.setUserNameAndPassword('admin', 'admin'); + await page.submitLoginForm(); + expect(await page.getErrorMessage()).toEqual('Login failed for admin'); }); - it('should logout', () => { - page.logout(); - expect(page.getLocation()).toEqual('http://localhost:4200/login'); + it('should login for valid credentials', async function() : Promise<any> { + await page.navigateToLogin(); + await page.setUserNameAndPassword('admin', 'password'); + await page.submitLoginForm(); + }); + + it('should logout', async function() : Promise<any> { + await page.logout(); + expect(await page.getLocation()).toEqual('http://localhost:4200/login'); }); });