From 5aa7f427140a3a404a88072bf5f6b35f96cf531a Mon Sep 17 00:00:00 2001 From: Sebastian Ang <22081109+sang2925@users.noreply.github.com> Date: Thu, 11 May 2023 09:28:23 -0700 Subject: [PATCH] Flaky tests update (#133) * update commenting function cypress * remove all graphql wait * removed graphql wait blue team * update node to 16.20 workflow * Update command to address test failure. --------- Co-authored-by: Courtney Carpenter --- .github/workflows/test.yml | 14 +- .../e2e/blueteam/campaign-card-tests.cy.js | 1 - .../e2e/blueteam/view-raw-logs.cy.js | 8 +- .../e2e/redteam/add-delete-comments.cy.js | 126 ++++-------------- .../e2e/redteam/campaign-card-tests.cy.js | 1 - .../e2e/redteam/command-count.cy.js | 6 - .../e2e/redteam/edit-comments.cy.js | 12 +- .../e2e/redteam/graphql/beacons.cy.js | 1 - .../e2e/redteam/graphql/commandTypes.cy.js | 1 - .../e2e/redteam/graphql/commands.skip.js | 1 - .../e2e/redteam/graphql/hosts.cy.js | 1 - .../e2e/redteam/graphql/links.cy.js | 1 - .../e2e/redteam/graphql/operators.cy.js | 1 - .../redteam/graphql/presentationItems.cy.js | 1 - .../e2e/redteam/graphql/searchCommands.cy.js | 1 - .../e2e/redteam/graphql/servers.cy.js | 1 - .../e2e/redteam/hide-show-host.cy.js | 2 +- .../e2e/redteam/multi-command-comment.cy.js | 10 +- .../e2e/redteam/username-on-comments.cy.js | 24 +--- applications/redeye-e2e/src/support/beacon.js | 3 +- .../redeye-e2e/src/support/campaignCard.js | 4 +- .../redeye-e2e/src/support/commands.js | 111 +++++++++------ applications/redeye-e2e/src/support/e2e.js | 98 +++++++------- .../redeye-e2e/src/support/explore.js | 12 +- package.json | 2 + yarn.lock | 29 ++++ 26 files changed, 205 insertions(+), 267 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 2f1a848b..55b5c679 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -33,7 +33,7 @@ jobs: strategy: fail-fast: false matrix: - node-version: [16.19.0] + node-version: [16.20.0] steps: - name: Checkout uses: actions/checkout@v3 @@ -43,7 +43,7 @@ jobs: - name: Cache uses: actions/setup-node@v3 with: - node-version: 16.19.0 + node-version: 16.20.0 cache: 'yarn' - run: yarn install --immutable --inline-builds @@ -66,7 +66,7 @@ jobs: fail-fast: false matrix: containers: [1, 2] - node-version: [16.19.0] + node-version: [16.20.0] steps: - name: Checkout @@ -77,7 +77,7 @@ jobs: - name: Cache uses: actions/setup-node@v3 with: - node-version: 16.19.0 + node-version: 16.20.0 cache: 'yarn' - name: Download the build folders @@ -98,7 +98,6 @@ jobs: config: baseUrl=http://localhost:3500 record: true parallel: true - headed: true config-file: applications/redeye-e2e/cypress.config.js spec: applications/redeye-e2e/src/integration/e2e/redteam/**/**/**/*.cy.js ci-build-id: ${{ needs.prepare.outputs.uuid }} @@ -116,7 +115,7 @@ jobs: fail-fast: false matrix: containers: [1, 2] - node-version: [16.19.0] + node-version: [16.20.0] steps: - name: Checkout @@ -127,7 +126,7 @@ jobs: - name: Cache uses: actions/setup-node@v3 with: - node-version: 16.19.0 + node-version: 16.20.0 cache: 'yarn' - name: Download the build folders @@ -148,7 +147,6 @@ jobs: config: baseUrl=http://localhost:3500 record: true parallel: true - headed: true config-file: applications/redeye-e2e/cypress.config.js spec: applications/redeye-e2e/src/integration/e2e/blueteam/**/*.cy.js ci-build-id: ${{ needs.prepare.outputs.uuid }} diff --git a/applications/redeye-e2e/src/integration/e2e/blueteam/campaign-card-tests.cy.js b/applications/redeye-e2e/src/integration/e2e/blueteam/campaign-card-tests.cy.js index ec2450e3..ab77c798 100644 --- a/applications/redeye-e2e/src/integration/e2e/blueteam/campaign-card-tests.cy.js +++ b/applications/redeye-e2e/src/integration/e2e/blueteam/campaign-card-tests.cy.js @@ -15,7 +15,6 @@ describe('Search and filter campaigns and verify beacon counts', () => { cy.selectCampaign(camp); cy.clickSearch(); cy.get('[cy-test=search]').click().type(cmd).type('{enter}'); - cy.wait('@searchCommands'); cy.get('[cy-test=search-result-item]').should('have.length.gt', 0).and('contain', cmd); cy.closeSearch(); }); diff --git a/applications/redeye-e2e/src/integration/e2e/blueteam/view-raw-logs.cy.js b/applications/redeye-e2e/src/integration/e2e/blueteam/view-raw-logs.cy.js index 51dcca53..e93eb020 100644 --- a/applications/redeye-e2e/src/integration/e2e/blueteam/view-raw-logs.cy.js +++ b/applications/redeye-e2e/src/integration/e2e/blueteam/view-raw-logs.cy.js @@ -23,10 +23,8 @@ describe('View Raw Logs', () => { // Expand first command cy.get('[cy-test=info-row]').eq(0).click(); cy.wait(500); - cy.get('[cy-test=openRawLogs]').should('be.visible'); + cy.get('[cy-test=openRawLogs]').should('be.visible').click(); - // Click "Show Raw Logs" link; verify log appears - cy.get('[cy-test=openRawLogs]').click(); verifyRawLogs(); }); @@ -38,10 +36,8 @@ describe('View Raw Logs', () => { // Click expandable row under first comment cy.get('[cy-test=command-info]').eq(0).click(); cy.wait(500); - cy.get('[cy-test=openRawLogs]').should('be.visible'); + cy.get('[cy-test=openRawLogs]').should('be.visible').click(); - // Click "Show Raw Logs" link; verify log appears - cy.get('[cy-test=openRawLogs]').click(); verifyRawLogs(); }); diff --git a/applications/redeye-e2e/src/integration/e2e/redteam/add-delete-comments.cy.js b/applications/redeye-e2e/src/integration/e2e/redteam/add-delete-comments.cy.js index dd0790a5..80b91655 100644 --- a/applications/redeye-e2e/src/integration/e2e/redteam/add-delete-comments.cy.js +++ b/applications/redeye-e2e/src/integration/e2e/redteam/add-delete-comments.cy.js @@ -1,149 +1,81 @@ /// +import 'cypress-map'; describe('Add Delete Campaign Comments', () => { const camp = 'addDeleteComments'; const fileName = 'gt.redeye'; const cmd = 'dcsync'; - const comment = 'Another comment'; - const tag = 'testing'; - - let count; it('Add campaign comments and check counts', () => { cy.uploadCampaign(camp, fileName); cy.searchForCampaign(camp); - cy.get('[cy-test=comment-count]') - .find('span') - .then((num) => num.text().split(' ').shift()) - .as('campaignCommentCount'); + cy.get('[cy-test=comment-count] > span') + .map('innerText') + .map(parseInt) + .reduce(Cypress._.add, 0) + .as('campaignCommentCount') + .asEnv('campaignCommentCount') + .should('equals', 5); // Open campaign and log starting number of comments via Comments tab cy.selectCampaign(camp); cy.clickCommentsTab(); - cy.get('[data-test-id=virtuoso-item-list]').should('exist'); cy.get('[cy-test=comment-group]') - .its('length') - .then((num) => parseInt(num)) - .as('commentsTabCount'); + .map('innerText') + .as('commentsTabCount') + .asEnv('commentsTabCount') + .should('have.length', 5); // Log starting number of comments via Presentation Mode cy.clickPresentationMode(); - cy.get('[cy-test=presentation-root]').should('exist'); cy.get('[cy-test=all] [cy-test=count]') - .find('span') - .first() - .should('be.visible') - .invoke('text') - .as('presentationCommentCount'); - - // Verify comment counts all match - cy.get('@campaignCommentCount').then((campaignCommentCount) => { - cy.get('@commentsTabCount').then((commentsTabCount) => { - cy.get('@presentationCommentCount').then((presentationCommentCount) => { - expect(+campaignCommentCount) - .to.eq(+commentsTabCount) - .and.to.eq(+presentationCommentCount); - }); - }); - }); + .map('innerText') + .map(parseInt) + .reduce(Cypress._.add, 0) + .as('presentationCommentCount') + .asEnv('presentationCommentCount') + .should('equals', 5); // Add a new comment cy.clickExplorerMode(); cy.clickCommandTypesTab(); cy.selectCommandType(cmd); - cy.addNewComment('0', comment, tag); + cy.addNewComment('0', 'Another comment', 'testing'); + + cy.clickPresentationMode(); + cy.get('@presentationCommentCount').should('equals', 6); // Log new number of comments via Comments tab - should be 1 more cy.clickExplorerMode(); cy.clickCommentsTab(); - cy.get('[data-test-id=virtuoso-item-list]').should('exist'); - cy.get('@commentsTabCount').then((commentsTabCount) => { - cy.get('[cy-test=comment-group]') - .its('length') - .then((num) => { - const commentsTabCount2 = parseInt(num); - expect(commentsTabCount2).to.eq(commentsTabCount + 1); - }); - }); + cy.get('@commentsTabCount').should('have.length', 6); - // Log new number of comments via Presentation Mode - should be one more - cy.clickPresentationMode(); - cy.get('[cy-test=presentation-root]').should('exist'); - cy.get('@presentationCommentCount').then((presentationCommentCount) => { - cy.get('[cy-test=all] [cy-test=count]') - .find('span') - .first() - .then((num) => { - const presentationCommentCount2 = num.text(); - expect(+presentationCommentCount2).to.eq(+presentationCommentCount + +'1'); - }); - }); - - // Return to campaign menu and log new number of comments - should be one more than original, and all comment counts should match cy.returnToCampaignCard(); - cy.get('[cy-test=campaign-card]').its('length').should('be.gte', 1); cy.searchForCampaign(camp); - cy.get('@campaignCommentCount').then((campaignCommentCount) => { - cy.get('[cy-test=comment-count]') - .find('span') - .then((num) => { - const campaignCommentCount2 = num.text(); - expect(+campaignCommentCount2).to.eq(+campaignCommentCount + +'1'); - }); - }); + cy.get('@campaignCommentCount').should('equals', 6); }); it('Delete campaign comments and check counts', () => { - // Search for campaign and log number of comments on campaign card - cy.searchForCampaign(camp); - cy.get('[cy-test=comment-count]') - .find('span') - .invoke('text') - .then((num) => { - count = num.split(' ').shift(); - }) - .as('campaignCommentCount'); - // Open campaign, go to command, delete a comment cy.selectCampaign(camp); cy.clickCommandTypesTab(); cy.selectCommandType(cmd); cy.deleteComment(0); + cy.clickPresentationMode(); + expect(Cypress.env('presentationCommentCount')).to.equal(5); + // Log new number of comments via Comments tab - should be 1 less cy.clickExplorerMode(); cy.clickCommentsTab(); - cy.get('[data-test-id=virtuoso-item-list]').should('exist'); - cy.get('[cy-test=comment-group]') - .its('length') - .then((num) => parseInt(num)) - .then((commentsTabCount) => { - expect(commentsTabCount).to.eq(+count - +'1'); - }); - - // Log new number of comments via Presentation Mode - should be one less - cy.clickPresentationMode(); - cy.get('[cy-test=presentation-root]').should('exist'); - cy.get('[cy-test=all] [cy-test=count]') - .find('span') - .first() - .then((num) => { - const presentationCommentCount = num.text(); - expect(+presentationCommentCount).to.eq(+count - +'1'); - }); + expect(Cypress.env('commentsTabCount')).to.have.length(5); // Return to campaign menu and log new number of comments - should be one less than original, and all comment counts should match cy.returnToCampaignCard(); - cy.get('[cy-test=campaign-card]').its('length').should('be.gte', 1); cy.searchForCampaign(camp); - cy.get('[cy-test=comment-count]') - .find('span') - .invoke('text') - .then((newCount) => { - expect(+newCount).to.eq(+count - +'1'); - }); + expect(Cypress.env('campaignCommentCount')).to.equal(5); }); after(() => { diff --git a/applications/redeye-e2e/src/integration/e2e/redteam/campaign-card-tests.cy.js b/applications/redeye-e2e/src/integration/e2e/redteam/campaign-card-tests.cy.js index 2f35fe43..b5242125 100644 --- a/applications/redeye-e2e/src/integration/e2e/redteam/campaign-card-tests.cy.js +++ b/applications/redeye-e2e/src/integration/e2e/redteam/campaign-card-tests.cy.js @@ -15,7 +15,6 @@ describe('Search and filter campaigns and verify beacon counts', () => { cy.selectCampaign(camp); cy.clickSearch(); cy.get('[cy-test=search]').click().type(cmd).type('{enter}'); - cy.wait('@searchCommands'); cy.get('[cy-test=search-result-item]').should('have.length.gt', 0).and('contain', cmd); cy.closeSearch(); }); diff --git a/applications/redeye-e2e/src/integration/e2e/redteam/command-count.cy.js b/applications/redeye-e2e/src/integration/e2e/redteam/command-count.cy.js index 54c6149d..d830f8c4 100644 --- a/applications/redeye-e2e/src/integration/e2e/redteam/command-count.cy.js +++ b/applications/redeye-e2e/src/integration/e2e/redteam/command-count.cy.js @@ -24,7 +24,6 @@ describe('Command counts', () => { Cypress.$('[cy-test=row-command-count]').each(function () { sum += +Cypress.$(this).text() || 0; }); - cy.log(sum); expect(sum).to.eq(+commandTotal); }); }); @@ -49,7 +48,6 @@ describe('Command counts', () => { Cypress.$('[cy-test=row-command-count]').each(function () { sum += +Cypress.$(this).text() || 0; }); - cy.log(sum); expect(sum).to.eq(+commandTotal); }); }); @@ -69,8 +67,6 @@ describe('Command counts', () => { .eq(0) .invoke('text') .then((countHost1) => { - // cy.log(countHost1); - // Click host to open details cy.get('[cy-test=info-row]').eq(1).click(); @@ -78,7 +74,6 @@ describe('Command counts', () => { cy.url().then((url) => { const returnedUrl = url.split('/')[5]; - // cy.log(returnedUrl); const query = `query commandIds($beaconId: String, $campaignId: String!, $commandIds: [String!], $commandType: String, $hostId: String, $operatorId: String, $sort: SortType) { commandIds(beaconId: $beaconId, campaignId: $campaignId, commandIds: $commandIds, commandType: $commandType, hostId: $hostId, operatorId: $operatorId, sort: $sort) @@ -118,7 +113,6 @@ describe('Command counts', () => { cy.url().then((url) => { const returnedUrl = url.split('/')[5]; - // cy.log(returnedUrl); const query = `query commandIds($beaconId: String, $campaignId: String!, $commandIds: [String!], $commandType: String, $hostId: String, $operatorId: String, $sort: SortType) { commandIds(beaconId: $beaconId, campaignId: $campaignId, commandIds: $commandIds, commandType: $commandType, hostId: $hostId, operatorId: $operatorId, sort: $sort) diff --git a/applications/redeye-e2e/src/integration/e2e/redteam/edit-comments.cy.js b/applications/redeye-e2e/src/integration/e2e/redteam/edit-comments.cy.js index f308e6e8..c7cbbdbd 100644 --- a/applications/redeye-e2e/src/integration/e2e/redteam/edit-comments.cy.js +++ b/applications/redeye-e2e/src/integration/e2e/redteam/edit-comments.cy.js @@ -5,8 +5,6 @@ describe('Edit Campaign Comments', () => { const editedComment = 'Edited comment text'; const fileName = 'gt.redeye'; const comment = 'commenthere'; - const tag = 'testing'; - const tag1 = 'test_1'; const tag2 = 'test_2'; it('Add comment and edit the text afterward', () => { @@ -21,15 +19,11 @@ describe('Edit Campaign Comments', () => { cy.addNewComment('0', comment, tag2); - cy.get('[cy-test=add-comment]').eq(0).scrollIntoView().should('be.visible').click({ force: true }); + cy.get('[cy-test=add-comment]').eq(0).should('be.visible').click({ force: true }); - cy.get('[cy-test=existing-comment-display]') - .scrollIntoView() - .should('be.visible') - .and('contain', comment) - .and('contain', tag2); + cy.get('[cy-test=existing-comment-display]').should('be.visible').should('contain', comment).and('contain', tag2); - cy.get('[cy-test=add-comment]').eq(0).click({ force: true }); + cy.get('[cy-test=add-comment]').eq(0).should('be.visible').click({ force: true }); // After saving comment, edit the comment text cy.editExistingComment(0, editedComment); diff --git a/applications/redeye-e2e/src/integration/e2e/redteam/graphql/beacons.cy.js b/applications/redeye-e2e/src/integration/e2e/redteam/graphql/beacons.cy.js index 1fcefa01..3bb3615a 100644 --- a/applications/redeye-e2e/src/integration/e2e/redteam/graphql/beacons.cy.js +++ b/applications/redeye-e2e/src/integration/e2e/redteam/graphql/beacons.cy.js @@ -10,7 +10,6 @@ describe('Query Beacons', () => { cy.url().then((url) => { const returnedUrl = url.split('/')[5]; - cy.log(returnedUrl); const query = `query beacons($campaignId: String!) { beacons(campaignId: $campaignId) { diff --git a/applications/redeye-e2e/src/integration/e2e/redteam/graphql/commandTypes.cy.js b/applications/redeye-e2e/src/integration/e2e/redteam/graphql/commandTypes.cy.js index c8920d5e..4b25c6ae 100644 --- a/applications/redeye-e2e/src/integration/e2e/redteam/graphql/commandTypes.cy.js +++ b/applications/redeye-e2e/src/integration/e2e/redteam/graphql/commandTypes.cy.js @@ -10,7 +10,6 @@ describe('Query CommandTypes', () => { cy.url().then((url) => { const returnedUrl = url.split('/')[5]; - cy.log(returnedUrl); const query = `query commandTypes($campaignId: String!) { commandTypes(campaignId: $campaignId) { diff --git a/applications/redeye-e2e/src/integration/e2e/redteam/graphql/commands.skip.js b/applications/redeye-e2e/src/integration/e2e/redteam/graphql/commands.skip.js index 74c5c8c0..1cf1217a 100644 --- a/applications/redeye-e2e/src/integration/e2e/redteam/graphql/commands.skip.js +++ b/applications/redeye-e2e/src/integration/e2e/redteam/graphql/commands.skip.js @@ -15,7 +15,6 @@ describe('Query Commands & CommandsIds', () => { cy.url().then((url) => { const returnedUrl = url.split('/')[5]; - cy.log(returnedUrl); const query = `query commandIds($beaconId: String, $campaignId: String!, $commandIds: [String!], $commandType: String, $hostId: String, $operatorId: String, $sort: SortType) { commandIds(beaconId: $beaconId, campaignId: $campaignId, commandIds: $commandIds, commandType: $commandType, hostId: $hostId, operatorId: $operatorId, sort: $sort) diff --git a/applications/redeye-e2e/src/integration/e2e/redteam/graphql/hosts.cy.js b/applications/redeye-e2e/src/integration/e2e/redteam/graphql/hosts.cy.js index 261a76fe..d97a8651 100644 --- a/applications/redeye-e2e/src/integration/e2e/redteam/graphql/hosts.cy.js +++ b/applications/redeye-e2e/src/integration/e2e/redteam/graphql/hosts.cy.js @@ -10,7 +10,6 @@ describe('Query Hosts', () => { cy.url().then((url) => { const returnedUrl = url.split('/')[5]; - cy.log(returnedUrl); const query = `query hosts($campaignId: String!) { hosts(campaignId: $campaignId) { diff --git a/applications/redeye-e2e/src/integration/e2e/redteam/graphql/links.cy.js b/applications/redeye-e2e/src/integration/e2e/redteam/graphql/links.cy.js index 8c13090a..cbeeb5f4 100644 --- a/applications/redeye-e2e/src/integration/e2e/redteam/graphql/links.cy.js +++ b/applications/redeye-e2e/src/integration/e2e/redteam/graphql/links.cy.js @@ -10,7 +10,6 @@ describe('Get All Links', () => { cy.url().then((url) => { const returnedUrl = url.split('/')[5]; - cy.log(returnedUrl); const query = `query links($campaignId: String!) { links(campaignId: $campaignId) { diff --git a/applications/redeye-e2e/src/integration/e2e/redteam/graphql/operators.cy.js b/applications/redeye-e2e/src/integration/e2e/redteam/graphql/operators.cy.js index 9d3d78b0..829c33b0 100644 --- a/applications/redeye-e2e/src/integration/e2e/redteam/graphql/operators.cy.js +++ b/applications/redeye-e2e/src/integration/e2e/redteam/graphql/operators.cy.js @@ -10,7 +10,6 @@ describe('Query Operators', () => { cy.url().then((url) => { const returnedUrl = url.split('/')[5]; - cy.log(returnedUrl); const query = `query operators($campaignId: String!) { operators(campaignId: $campaignId) { diff --git a/applications/redeye-e2e/src/integration/e2e/redteam/graphql/presentationItems.cy.js b/applications/redeye-e2e/src/integration/e2e/redteam/graphql/presentationItems.cy.js index 967385a7..b99dcd60 100644 --- a/applications/redeye-e2e/src/integration/e2e/redteam/graphql/presentationItems.cy.js +++ b/applications/redeye-e2e/src/integration/e2e/redteam/graphql/presentationItems.cy.js @@ -12,7 +12,6 @@ describe('Query Presentation Items', () => { cy.url().then((url) => { const returnedUrl = url.split('/')[5]; - cy.log(returnedUrl); const query = `query presentationItems($campaignId: String!) { presentationItems(campaignId: $campaignId) { diff --git a/applications/redeye-e2e/src/integration/e2e/redteam/graphql/searchCommands.cy.js b/applications/redeye-e2e/src/integration/e2e/redteam/graphql/searchCommands.cy.js index d505f9fc..785b546f 100644 --- a/applications/redeye-e2e/src/integration/e2e/redteam/graphql/searchCommands.cy.js +++ b/applications/redeye-e2e/src/integration/e2e/redteam/graphql/searchCommands.cy.js @@ -12,7 +12,6 @@ describe('Search Request', () => { cy.url().then((url) => { const returnedUrl = url.split('/')[5]; - cy.log(returnedUrl); const query = `query searchCommands($campaignId: String!, $searchQuery: String!) { searchCommands(campaignId: $campaignId, searchQuery: $searchQuery) { diff --git a/applications/redeye-e2e/src/integration/e2e/redteam/graphql/servers.cy.js b/applications/redeye-e2e/src/integration/e2e/redteam/graphql/servers.cy.js index cd1fac10..9c0c1894 100644 --- a/applications/redeye-e2e/src/integration/e2e/redteam/graphql/servers.cy.js +++ b/applications/redeye-e2e/src/integration/e2e/redteam/graphql/servers.cy.js @@ -10,7 +10,6 @@ describe('Query Servers', () => { cy.url().then((url) => { const returnedUrl = url.split('/')[5]; - cy.log(returnedUrl); const query = `query servers($campaignId: String!, $username: String!) { servers(campaignId: $campaignId, username: $username) { diff --git a/applications/redeye-e2e/src/integration/e2e/redteam/hide-show-host.cy.js b/applications/redeye-e2e/src/integration/e2e/redteam/hide-show-host.cy.js index f3d388cb..567701bd 100644 --- a/applications/redeye-e2e/src/integration/e2e/redteam/hide-show-host.cy.js +++ b/applications/redeye-e2e/src/integration/e2e/redteam/hide-show-host.cy.js @@ -11,7 +11,7 @@ describe('Hide a host', () => { const camp = 'hideshowhost'; const fileName = 'gt.redeye'; - it.only('Hide host via Meta tab using toggle in left nav panel', () => { + it('Hide host via Meta tab using toggle in left nav panel', () => { cy.uploadCampaign(camp, fileName); // Search for new campaign by name diff --git a/applications/redeye-e2e/src/integration/e2e/redteam/multi-command-comment.cy.js b/applications/redeye-e2e/src/integration/e2e/redteam/multi-command-comment.cy.js index 0342b617..9c2bd3ed 100644 --- a/applications/redeye-e2e/src/integration/e2e/redteam/multi-command-comment.cy.js +++ b/applications/redeye-e2e/src/integration/e2e/redteam/multi-command-comment.cy.js @@ -28,8 +28,6 @@ describe('Multi-Command Comments', () => { cy.favoriteComment(0); cy.get('[cy-test=comment-input]').type(comment).type('{enter}'); cy.addNewTags(tag); - // cy.get('[cy-test=save-comment]').click(); - // cy.wait(1000); // Verify comments are saved cy.clickExplorerMode(); @@ -58,16 +56,16 @@ describe('Multi-Command Comments', () => { cy.get('[cy-test=number-commands]').should('contain', startingCommands); // cy.log(startingCommands); - cy.get('[cy-test=add-command-this-comment]').click(); - cy.wait('@addCommandToCommandGroup'); + cy.get('[cy-test=add-command-this-comment]').should('be.visible').click(); + + cy.wait(300); + cy.get('[cy-test=command-added]').should('be.visible'); - // cy.wait(1000); // Log new number of commands - should be 1 more than earlier cy.get('[cy-test=number-commands]').then((number2) => { const updatedCommands = number2.text().split(' ').shift(); cy.get('[cy-test=number-commands]').should('contain', updatedCommands); - // cy.log(updatedCommands); expect(+updatedCommands).to.equal(+startingCommands + +'1'); }); }); diff --git a/applications/redeye-e2e/src/integration/e2e/redteam/username-on-comments.cy.js b/applications/redeye-e2e/src/integration/e2e/redteam/username-on-comments.cy.js index 3f3b50f5..e7ac0671 100644 --- a/applications/redeye-e2e/src/integration/e2e/redteam/username-on-comments.cy.js +++ b/applications/redeye-e2e/src/integration/e2e/redteam/username-on-comments.cy.js @@ -1,26 +1,15 @@ /// -let user; - +const user = 'cypress'; describe('Username shows on comments when appropriate', () => { const camp = 'username'; const fileName = 'gt.redeye'; const normalizeText = (s) => s.replace(/\s/g, '').toLowerCase(); - function getUserName() { - cy.get('[cy-test=user]') - .should('be.visible') - .then(($name) => { - user = normalizeText($name.text()); - }); - } - it('Username should not appear when favoriting a comment', () => { // Upload campaign and log username cy.uploadCampaign(camp, fileName); - getUserName(); - // Open campaign, find an existing comment, and mark it as a favorite cy.selectCampaign(camp); @@ -38,12 +27,6 @@ describe('Username shows on comments when appropriate', () => { }); it('Username should appear when comment is edited', () => { - // Log username and open campaign - - cy.get('[cy-test=appTitle]').should('be.visible'); - - getUserName(); - cy.selectCampaign(camp); // Find an existing comment and edit it @@ -63,11 +46,6 @@ describe('Username shows on comments when appropriate', () => { }); it('Username should appear when new comment is made', () => { - cy.get('[cy-test=appTitle]').should('be.visible'); - - // Log username and open campaign - getUserName(); - cy.selectCampaign(camp); // Add a new comment diff --git a/applications/redeye-e2e/src/support/beacon.js b/applications/redeye-e2e/src/support/beacon.js index 975570a3..fb193759 100644 --- a/applications/redeye-e2e/src/support/beacon.js +++ b/applications/redeye-e2e/src/support/beacon.js @@ -62,8 +62,9 @@ Cypress.Commands.add('clickAddComments', (index) => { //ADD MULTI COMMAND COMMENTS Cypress.Commands.add('addMultiCommandComment', () => { - cy.get('[cy-test=multi-command-comment]').click(); + cy.get('[cy-test=multi-command-comment]').click({ force: true }); cy.get('[cy-test=comment-on-commands]').should('be.disabled'); + cy.wait(500); }); ////NEW diff --git a/applications/redeye-e2e/src/support/campaignCard.js b/applications/redeye-e2e/src/support/campaignCard.js index 94013d4f..7ae32f2c 100644 --- a/applications/redeye-e2e/src/support/campaignCard.js +++ b/applications/redeye-e2e/src/support/campaignCard.js @@ -7,8 +7,8 @@ Cypress.Commands.add('clickCampaignCard', (index) => { //SELECT CAMPAIGN Cypress.Commands.add('selectCampaign', (camp) => { - cy.get('[cy-test=campaign-name]').contains(camp).scrollIntoView().click(); - // cy.wait(['@servers', '@beacons', '@hosts', '@links', '@commandTypes', '@operators', '@timeline']); + cy.get('[cy-test=campaign-name]').contains(camp).should('be.visible').scrollIntoView().click(); + cy.wait(1000); cy.get('.superGraph').should('be.visible'); cy.get('[cy-test=timeline]').should('be.visible'); }); diff --git a/applications/redeye-e2e/src/support/commands.js b/applications/redeye-e2e/src/support/commands.js index d9738861..f422fd55 100644 --- a/applications/redeye-e2e/src/support/commands.js +++ b/applications/redeye-e2e/src/support/commands.js @@ -1,5 +1,6 @@ /* eslint-disable cypress/no-unnecessary-waiting */ /// +import 'cypress-real-events'; import { graphqlRequest, mutRequest } from '../support/utils'; @@ -34,7 +35,10 @@ Cypress.Commands.add('loginAPI', (user = 'cypress') => { cacheAcrossSpecs: true, } ), - cy.visit('http://localhost:3500/#/campaigns/all'); + cy.visit('http://localhost:3500/#/campaigns/all', { + timeout: 80000, + }); + cy.wait(1000); }); Cypress.Commands.add('loginBlue', (user) => { @@ -53,27 +57,24 @@ Cypress.Commands.add('logout', () => { //HOVER OVER TO ADD NEW COMMENT IF NONE EXIST Cypress.Commands.add('addComment', (index, cmt) => { - cy.get('[cy-test=command-info] [cy-test=add-comment]') + cy.get('[cy-test=add-comment]') .eq(index) + .realHover() .invoke('attr', 'style', 'visibility: visible') .should('be.visible') - .click({ force: true }); + .realClick(); cy.get('[cy-test=comment-box]').should('be.visible'); - cy.get('[cy-test=comment-input]').type(cmt); + cy.get('[cy-test=comment-input]').should('be.visible').type(cmt); }); //DELETE COMMENT Cypress.Commands.add('deleteComment', (index) => { - cy.get('[cy-test=add-comment]') - .eq(index) - .click() - .wait(100) - .then(() => { - cy.get('[cy-test=comment-dialog]').should('be.visible'); - }); - + cy.get('[cy-test=command-info]').should('be.visible'); + cy.get('[cy-test=add-comment]').should('be.visible').eq(index).click({ force: true }); + cy.get('[cy-test=comment-dialog]').should('be.visible'); cy.get('[cy-test=delete-comment]').click(); - cy.contains('Delete Comment').click(); + cy.contains('Delete Comment').click({ force: true }); + cy.wait(500); }); // ADD TO EXISTING COMMENT @@ -84,7 +85,7 @@ Cypress.Commands.add('addToExistingComment', (index, cmt) => { .should('be.visible') .click({ force: true }); cy.get('[cy-test=comment-box]').should('be.visible'); - cy.get('[cy-test=add-command-existing-comment]').click({ force: true }); + cy.get('[cy-test=add-command-existing-comment]').should('be.visible').click({ force: true }); cy.get('[cy-test=search-comments]').type(cmt); }); @@ -94,48 +95,71 @@ Cypress.Commands.add('addExistingTags', (...term) => { cy.get('[cy-test=tag-input]').type(tags); cy.get('[cy-test=tag-list-item]').contains(tags).click(); }); - cy.get('[cy-test=save-comment]').should('be.visible').click(); - cy.wait('@addCommandGroupAnnotation'); + cy.get('[cy-test=save-comment]').should('be.visible').realClick(); + // cy.wait('@addCommandGroupAnnotation'); }); //ADD TAGS TO COMMENT Cypress.Commands.add('addNewTags', { prevSubject: false }, (...term) => { term.forEach((tags) => { cy.get('[cy-test=tag-input]').type(tags); - cy.get('[cy-test=add-tag]').contains(tags).click({ force: true }); + cy.get('[cy-test=add-tag]').contains(tags).realClick(); }); - cy.get('[cy-test=save-comment]').should('be.visible').click(); - cy.wait('@addCommandGroupAnnotation'); + cy.get('[cy-test=save-comment]').should('be.visible').realClick(); + // cy.wait('@addCommandGroupAnnotation'); + cy.wait(300); }); //MARK COMMENT AS FAVORITE Cypress.Commands.add('favoriteComment', (index) => { - cy.get('[cy-test=fav-comment]').should('be.visible').eq(index).click({ force: true }); + cy.get('[cy-test=fav-comment]').should('be.visible').eq(index).realClick(); }); //ADD NEW COMMENT Cypress.Commands.add('addNewComment', (index, comment, tag) => { - cy.get('[cy-test=command-info]') - .eq(index) - .then(($co) => { - if ($co.find('[cy-test=add-comment]').length > 0) { - cy.get('[cy-test=add-comment]').then(($btn) => { - if ($btn.is(':visible')) { - cy.log('COMMENT ALREADY HERE'); - cy.get('[cy-test=add-comment]').click({ force: true }); - cy.get('[cy-test=add-new-comment]').click({ force: true }); - cy.get('[cy-test=comment-input]').type(comment).type('{enter}'); - cy.addExistingTags(tag); - cy.wait(300); - } else { - cy.log('NEW COMMENT '); - cy.addComment(index, comment); - cy.addNewTags(tag); - cy.wait(300); - } - }); + cy.get('[cy-test=add-comment]') + .should((_) => {}) + .then(($button) => { + if ($button.length) { + cy.get('[cy-test=add-comment]') + .eq(index) + .realHover() + .invoke('attr', 'style', 'visibility: visible') + .should('be.visible') + .realClick(); + cy.get('[cy-test=comment-box]').should('be.visible'); + cy.get('[cy-test=comment-input]').should('be.visible').type(comment); + cy.addNewTags(tag); + cy.wait(300); + return; + } else { + cy.wrap($button).click(); + cy.get('[cy-test=add-new-comment]').click({ force: true }); + cy.get('[cy-test=comment-input]').type(comment).type('{enter}'); + cy.addExistingTags(tag); } }); + // cy.get('[cy-test=command-info]') + // .eq(index) + // .then(($co) => { + // if ($co.find('[cy-test=add-comment]').length > 0) { + // cy.get('[cy-test=add-comment]').then(($btn) => { + // if ($btn.is(':visible')) { + // cy.log('COMMENT ALREADY HERE'); + // cy.get('[cy-test=add-comment]').click({ force: true }); + // cy.get('[cy-test=add-new-comment]').click({ force: true }); + // cy.get('[cy-test=comment-input]').type(comment).type('{enter}'); + // cy.addExistingTags(tag); + // cy.wait(300); + // } else { + // cy.log('NEW COMMENT '); + // cy.addComment(index, comment); + // cy.addNewTags(tag); + // cy.wait(300); + // } + // }); + // } + // }); }); // Edit an existing comment; do not edit tags @@ -143,7 +167,7 @@ Cypress.Commands.add('editExistingComment', (index, editedCommentText) => { cy.get('[cy-test=edit-comment]').eq(index).click(); cy.get('[cy-test=comment-input]').click().clear().type(editedCommentText); cy.get('[cy-test=save-comment]').click(); - cy.wait('@updateAnnotation'); + // cy.wait('@updateAnnotation'); }); // Reply to a comment (only adds text, no tags) @@ -180,7 +204,8 @@ Cypress.Commands.add('infoRowTotal', (num) => { //ACTUAL COMMANDS Cypress.Commands.add('selectCommandType', (cmd) => { cy.get('[cy-test=commands]').contains(cmd).click(); - cy.wait(['@commands', '@commandIds']); + // cy.wait(['@commands', '@commandIds']); + cy.wait(500); }); // Delete campaign using GraphQL @@ -219,7 +244,7 @@ Cypress.Commands.add('closeRawLogs', () => { // Search campaign for specific term Cypress.Commands.add('searchCampaignFor', (searchTerm) => { cy.get('[cy-test=search]').click().clear().type(searchTerm).type('{enter}'); - cy.wait('@searchAnnotations'); + // cy.wait('@searchAnnotations'); }); // Edit an existing comment; do not edit tags @@ -227,7 +252,7 @@ Cypress.Commands.add('editExistingComment', (index, editedCommentText) => { cy.get('[cy-test=edit-comment]').eq(index).click(); cy.get('[cy-test=comment-input]').click().clear().type(editedCommentText); cy.get('[cy-test=save-comment]').click(); - cy.wait('@updateAnnotation'); + // cy.wait('@updateAnnotation'); }); // Reply to a comment (only adds text, no tags) diff --git a/applications/redeye-e2e/src/support/e2e.js b/applications/redeye-e2e/src/support/e2e.js index 1cbaba0e..c724e6c8 100644 --- a/applications/redeye-e2e/src/support/e2e.js +++ b/applications/redeye-e2e/src/support/e2e.js @@ -6,13 +6,13 @@ import './beacon'; import './computer'; import './campaignCard'; import './utils'; +// import 'cypress-map'; Cypress.on('uncaught:exception', (err, runnable, promise) => { if (promise) { return false; } if (err.message.includes('ResizeObserver loop limit exceeded')) { - // ignore the error return false; } }); @@ -40,54 +40,54 @@ export const aliasMutation = (req, operationName) => { //LOGIN LOCALLY beforeEach(() => { - cy.intercept('POST', 'http://localhost:4000/api/graphql', (req) => { - // Queries - aliasQuery(req, 'searchCommands'); - aliasQuery(req, 'annotation'); - aliasQuery(req, 'annotations'); - aliasQuery(req, 'beacons'); - aliasQuery(req, 'campaign'); - aliasQuery(req, 'campaigns'); - aliasQuery(req, 'commandGroup'); - aliasQuery(req, 'commandGroups'); - aliasQuery(req, 'commandIds'); - aliasQuery(req, 'commandTypes'); - aliasQuery(req, 'commands'); - aliasQuery(req, 'files'); - aliasQuery(req, 'globalOperators'); - aliasQuery(req, 'hosts'); - aliasQuery(req, 'images'); - aliasQuery(req, 'links'); - aliasQuery(req, 'logs'); - aliasQuery(req, 'logsByBeaconId'); - aliasQuery(req, 'operators'); - aliasQuery(req, 'parsingProgress'); - aliasQuery(req, 'presentationItems'); - aliasQuery(req, 'searchAnnotations'); - aliasQuery(req, 'searchCommands'); - aliasQuery(req, 'servers'); - aliasQuery(req, 'tags'); - aliasQuery(req, 'timeline'); + // cy.intercept('POST', 'http://localhost:4000/api/graphql', (req) => { + // // Queries + // aliasQuery(req, 'searchCommands'); + // aliasQuery(req, 'annotation'); + // aliasQuery(req, 'annotations'); + // aliasQuery(req, 'beacons'); + // aliasQuery(req, 'campaign'); + // aliasQuery(req, 'campaigns'); + // aliasQuery(req, 'commandGroup'); + // aliasQuery(req, 'commandGroups'); + // aliasQuery(req, 'commandIds'); + // aliasQuery(req, 'commandTypes'); + // aliasQuery(req, 'commands'); + // aliasQuery(req, 'files'); + // aliasQuery(req, 'globalOperators'); + // aliasQuery(req, 'hosts'); + // aliasQuery(req, 'images'); + // aliasQuery(req, 'links'); + // aliasQuery(req, 'logs'); + // aliasQuery(req, 'logsByBeaconId'); + // aliasQuery(req, 'operators'); + // aliasQuery(req, 'parsingProgress'); + // aliasQuery(req, 'presentationItems'); + // aliasQuery(req, 'searchAnnotations'); + // aliasQuery(req, 'searchCommands'); + // aliasQuery(req, 'servers'); + // aliasQuery(req, 'tags'); + // aliasQuery(req, 'timeline'); - // Mutations - aliasMutation(req, 'addAnnotationToCommandGroup'); - aliasMutation(req, 'addCommandGroupAnnotation'); - aliasMutation(req, 'addCommandToCommandGroup'); - aliasMutation(req, 'addLocalServerFolder'); - aliasMutation(req, 'anonymizeCampaign'); - aliasMutation(req, 'createCampaign'); - aliasMutation(req, 'createGlobalOperator'); - aliasMutation(req, 'deleteAnnotation'); - aliasMutation(req, 'deleteCampaign'); - aliasMutation(req, 'renameCampaign'); - aliasMutation(req, 'serversParse'); - aliasMutation(req, 'toggleBeaconHidden'); - aliasMutation(req, 'toggleHostHidden'); - aliasMutation(req, 'toggleServerHidden'); - aliasMutation(req, 'updateAnnotation'); - aliasMutation(req, 'updateBeaconMetadata'); - aliasMutation(req, 'updateHostMetadata'); - aliasMutation(req, 'updateServerMetadata'); - }); + // // Mutations + // aliasMutation(req, 'addAnnotationToCommandGroup'); + // aliasMutation(req, 'addCommandGroupAnnotation'); + // aliasMutation(req, 'addCommandToCommandGroup'); + // aliasMutation(req, 'addLocalServerFolder'); + // aliasMutation(req, 'anonymizeCampaign'); + // aliasMutation(req, 'createCampaign'); + // aliasMutation(req, 'createGlobalOperator'); + // aliasMutation(req, 'deleteAnnotation'); + // aliasMutation(req, 'deleteCampaign'); + // aliasMutation(req, 'renameCampaign'); + // aliasMutation(req, 'serversParse'); + // aliasMutation(req, 'toggleBeaconHidden'); + // aliasMutation(req, 'toggleHostHidden'); + // aliasMutation(req, 'toggleServerHidden'); + // aliasMutation(req, 'updateAnnotation'); + // aliasMutation(req, 'updateBeaconMetadata'); + // aliasMutation(req, 'updateHostMetadata'); + // aliasMutation(req, 'updateServerMetadata'); + // }); cy.loginAPI(); }); diff --git a/applications/redeye-e2e/src/support/explore.js b/applications/redeye-e2e/src/support/explore.js index 8253719b..78e1acdb 100644 --- a/applications/redeye-e2e/src/support/explore.js +++ b/applications/redeye-e2e/src/support/explore.js @@ -26,7 +26,7 @@ Cypress.Commands.add('clickTab', (name) => { // RETURN TO CAMPAIGN CARD Cypress.Commands.add('returnToCampaignCard', () => { cy.get('[cy-test=return-campaign-menu]').first().click({ force: true }); - cy.wait('@campaigns'); + // cy.wait('@campaigns'); }); // CLICK EXPLORER ON EXPLORER PANEL @@ -37,11 +37,10 @@ Cypress.Commands.add('clickExplorerMode', () => { // CLICK PRESENTATION MODE ON EXPLORER PANEL Cypress.Commands.add('clickPresentationMode', () => { cy.get('[cy-test=presentation-mode').click(); - cy.wait('@presentationItems'); + // cy.wait('@presentationItems'); + cy.get('[cy-test=presentation-root]').should('be.visible'); cy.get('div.bp4-spinner-annimation').should('not.exist'); - cy.get('[cy-test=favorited]').should('be.visible'); - cy.get('.superGraph').should('be.visible'); - + cy.get('.superGraph').should('be.visible', { timeout: 90000 }); cy.wait(1000); }); @@ -83,6 +82,7 @@ Cypress.Commands.add('clickOperatorsTab', () => { Cypress.Commands.add('clickCommentsTab', () => { cy.get('[cy-test=comments]').click(); cy.wait(500); + cy.get('[data-test-id=virtuoso-item-list]').should('exist'); }); // CLICK BEACONS ON EXPLORER OVERVIEW PANEL @@ -268,6 +268,7 @@ Cypress.Commands.add('showHideServerMetaTab', () => { Cypress.Commands.add('showHideItem', (index) => { cy.get('[cy-test=quick-meta-button]').eq(index).click(); cy.get('[cy-test=show-hide-item]').click(); + cy.wait(400); }); // VERIFY SHOW/HIDE DIALOG BOX APPEARS @@ -297,6 +298,7 @@ Cypress.Commands.add('verifyCannotHideFinal', () => { // CONFIRM SHOW OR HIDE FROM CONFIRMATION MODAL Cypress.Commands.add('confirmShowHide', () => { cy.get('[cy-test=confirm-show-hide]').click(); + cy.wait(400); cy.get('[cy-test=confirm-show-hide]').should('not.exist'); }); diff --git a/package.json b/package.json index 895cda82..d97608b7 100644 --- a/package.json +++ b/package.json @@ -150,7 +150,9 @@ "concurrently": "^7.6.0", "cross-env": "^7.0.3", "cypress": "^12.11.0", + "cypress-map": "^1.19.1", "cypress-multi-reporters": "^1.6.1", + "cypress-real-events": "^1.7.6", "dotenv": "^8.2.0", "eslint": "^8.22.0", "eslint-config-airbnb": "^19.0.4", diff --git a/yarn.lock b/yarn.lock index f3dff8db..7fd07ddb 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6118,6 +6118,17 @@ __metadata: languageName: node linkType: hard +"cypress-map@npm:^1.19.1": + version: 1.19.1 + resolution: "cypress-map@npm:1.19.1" + dependencies: + string-format: ^2.0.0 + peerDependencies: + cypress: ">=12" + checksum: a46add387b1b094632db7b2f8dd1f2833ff3c2fa7a89f00d1fb1d517b053dd1e0a9d5149d5b7bc12bfcd03e3a51af8e27560a3c43dab1ca406e2a542ed9ac878 + languageName: node + linkType: hard + "cypress-multi-reporters@npm:^1.6.1": version: 1.6.1 resolution: "cypress-multi-reporters@npm:1.6.1" @@ -6130,6 +6141,15 @@ __metadata: languageName: node linkType: hard +"cypress-real-events@npm:^1.7.6": + version: 1.7.6 + resolution: "cypress-real-events@npm:1.7.6" + peerDependencies: + cypress: ^4.x || ^5.x || ^6.x || ^7.x || ^8.x || ^9.x || ^10.x || ^11.x || ^12.x + checksum: 715ead42990e5464a2613dea2ebbcdfd093b47beee38f7afdff817e5dd701753e103103b2806864771a55aee700580253534497ca6802c88ef9688c6b095917c + languageName: node + linkType: hard + "cypress@npm:^12.11.0": version: 12.11.0 resolution: "cypress@npm:12.11.0" @@ -13178,7 +13198,9 @@ __metadata: cross-env: ^7.0.3 crypto-js: ^4.0.0 cypress: ^12.11.0 + cypress-map: ^1.19.1 cypress-multi-reporters: ^1.6.1 + cypress-real-events: ^1.7.6 d3: ^6.7.0 dayjs: ^1.11.7 dotenv: ^8.2.0 @@ -14260,6 +14282,13 @@ __metadata: languageName: node linkType: hard +"string-format@npm:^2.0.0": + version: 2.0.0 + resolution: "string-format@npm:2.0.0" + checksum: dada2ef95f6d36c66562c673d95315f80457fa7dce2f3609a2e75d1190b98c88319028cf0a5b6c043d01c18d581b2641579f79480584ba030d6ac6fceb30bc55 + languageName: node + linkType: hard + "string-length@npm:^4.0.1": version: 4.0.2 resolution: "string-length@npm:4.0.2"