You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by di...@apache.org on 2022/10/25 15:22:20 UTC

[superset] 01/01: Fix high frequency flaky tests

This is an automated email from the ASF dual-hosted git repository.

diegopucci pushed a commit to branch fix/cypress-flaky
in repository https://gitbox.apache.org/repos/asf/superset.git

commit a5407cc3bdb23b34f888bd0aeee41d1dfc46940f
Author: geido <di...@gmail.com>
AuthorDate: Tue Oct 25 18:21:55 2022 +0300

    Fix high frequency flaky tests
---
 .../cypress/integration/chart_list/list.test.ts         |  3 +--
 .../cypress/integration/dashboard/editmode.test.ts      | 15 ++++++++++-----
 .../integration/explore/advanced_analytics.test.ts      |  9 +++++++--
 .../cypress/integration/explore/control.test.ts         | 15 ++++-----------
 .../cypress-base/cypress/integration/explore/utils.ts   | 17 +++++++++++++++--
 .../cypress/integration/sqllab/tabs.test.ts             |  4 ++--
 6 files changed, 39 insertions(+), 24 deletions(-)

diff --git a/superset-frontend/cypress-base/cypress/integration/chart_list/list.test.ts b/superset-frontend/cypress-base/cypress/integration/chart_list/list.test.ts
index faaf00ddf5..c64effd411 100644
--- a/superset-frontend/cypress-base/cypress/integration/chart_list/list.test.ts
+++ b/superset-frontend/cypress-base/cypress/integration/chart_list/list.test.ts
@@ -88,7 +88,6 @@ describe('Charts list', () => {
       saveChartToDashboard('1 - Sample dashboard');
       saveChartToDashboard('2 - Sample dashboard');
       saveChartToDashboard('3 - Sample dashboard');
-      saveChartToDashboard('4 - Sample dashboard');
       visitChartList();
       cy.getBySel('count-crosslinks').should('be.visible');
       cy.getBySel('crosslinks')
@@ -96,7 +95,7 @@ describe('Charts list', () => {
         .trigger('mouseover')
         .then(() => {
           cy.get('.ant-tooltip')
-            .contains('4 - Sample dashboard')
+            .contains('3 - Sample dashboard')
             .invoke('removeAttr', 'target')
             .click();
           cy.wait('@get');
diff --git a/superset-frontend/cypress-base/cypress/integration/dashboard/editmode.test.ts b/superset-frontend/cypress-base/cypress/integration/dashboard/editmode.test.ts
index 9f05f2fc29..f4cc44acc8 100644
--- a/superset-frontend/cypress-base/cypress/integration/dashboard/editmode.test.ts
+++ b/superset-frontend/cypress-base/cypress/integration/dashboard/editmode.test.ts
@@ -148,16 +148,21 @@ function assertMetadata(text: string) {
     });
 }
 function clearMetadata() {
-  cy.wait(500);
   cy.get('#json_metadata').then($jsonmetadata => {
-    cy.wrap($jsonmetadata).type('{selectall} {backspace}');
+    cy.wrap($jsonmetadata).find('.ace_content').click();
+    cy.wrap($jsonmetadata)
+      .find('.ace_text-input')
+      .type('{selectall} {backspace}');
   });
 }
 
 function writeMetadata(metadata: string) {
-  cy.get('#json_metadata').then($jsonmetadata => {
-    cy.wrap($jsonmetadata).type(metadata, { parseSpecialCharSequences: false });
-  });
+  cy.get('#json_metadata').then($jsonmetadata =>
+    cy
+      .wrap($jsonmetadata)
+      .find('.ace_text-input')
+      .type(metadata, { parseSpecialCharSequences: false }),
+  );
 }
 
 function openExplore(chartName: string) {
diff --git a/superset-frontend/cypress-base/cypress/integration/explore/advanced_analytics.test.ts b/superset-frontend/cypress-base/cypress/integration/explore/advanced_analytics.test.ts
index f43076bbbf..f38fdbd3a9 100644
--- a/superset-frontend/cypress-base/cypress/integration/explore/advanced_analytics.test.ts
+++ b/superset-frontend/cypress-base/cypress/integration/explore/advanced_analytics.test.ts
@@ -29,7 +29,9 @@ describe('Advanced analytics', () => {
     cy.visitChartByName('Num Births Trend');
     cy.verifySliceSuccess({ waitAlias: '@postJson' });
 
-    cy.get('.ant-collapse-header').contains('Advanced Analytics').click();
+    cy.get('.ant-collapse-header')
+      .contains('Advanced Analytics')
+      .click({ force: true });
 
     cy.get('[data-test=time_compare]').find('.ant-select').click();
     cy.get('[data-test=time_compare]')
@@ -43,13 +45,16 @@ describe('Advanced analytics', () => {
     cy.get('button[data-test="run-query-button"]').click();
     cy.wait('@postJson');
     cy.wait('@putExplore');
+
     cy.reload();
     cy.verifySliceSuccess({
       waitAlias: '@postJson',
       chartSelector: 'svg',
     });
     cy.wait('@getExplore');
-    cy.get('.ant-collapse-header').contains('Advanced Analytics').click();
+    cy.get('.ant-collapse-header')
+      .contains('Advanced Analytics')
+      .click({ force: true });
     cy.get('[data-test=time_compare]')
       .find('.ant-select-selector')
       .contains('28 days');
diff --git a/superset-frontend/cypress-base/cypress/integration/explore/control.test.ts b/superset-frontend/cypress-base/cypress/integration/explore/control.test.ts
index 5686ad43f8..98bb95f000 100644
--- a/superset-frontend/cypress-base/cypress/integration/explore/control.test.ts
+++ b/superset-frontend/cypress-base/cypress/integration/explore/control.test.ts
@@ -23,12 +23,13 @@ import { interceptChart } from 'cypress/utils';
 import { FORM_DATA_DEFAULTS, NUM_METRIC } from './visualizations/shared.helper';
 
 describe('Datasource control', () => {
+  beforeEach(() => {
+    cy.preserveLogin();
+  });
+
   const newMetricName = `abc${Date.now()}`;
 
   it('should allow edit dataset', () => {
-    let numScripts = 0;
-
-    cy.login();
     interceptChart({ legacy: true }).as('chartData');
 
     cy.visitChartByName('Num Births Trend');
@@ -36,16 +37,8 @@ describe('Datasource control', () => {
 
     cy.get('[data-test="datasource-menu-trigger"]').click();
 
-    cy.get('script').then(nodes => {
-      numScripts = nodes.length;
-    });
-
     cy.get('[data-test="edit-dataset"]').click();
 
-    // should load additional scripts for the modal
-    cy.get('script').then(nodes => {
-      expect(nodes.length).to.greaterThan(numScripts);
-    });
     cy.get('[data-test="edit-dataset-tabs"]').within(() => {
       cy.contains('Metrics').click();
     });
diff --git a/superset-frontend/cypress-base/cypress/integration/explore/utils.ts b/superset-frontend/cypress-base/cypress/integration/explore/utils.ts
index 83e391acc0..eb8631c753 100644
--- a/superset-frontend/cypress-base/cypress/integration/explore/utils.ts
+++ b/superset-frontend/cypress-base/cypress/integration/explore/utils.ts
@@ -17,6 +17,8 @@
  * under the License.
  */
 
+import { interceptGet as interceptDashboardGet } from '../dashboard/utils';
+
 export function interceptFiltering() {
   cy.intercept('GET', `/api/v1/chart/?q=*`).as('filtering');
 }
@@ -41,6 +43,10 @@ export function interceptExploreJson() {
   cy.intercept('POST', `/superset/explore_json/**`).as('getJson');
 }
 
+export function interceptExploreGet() {
+  cy.intercept('GET', `/api/v1/explore/?slice_id=**`).as('getExplore');
+}
+
 export function setFilter(filter: string, option: string) {
   interceptFiltering();
 
@@ -51,6 +57,10 @@ export function setFilter(filter: string, option: string) {
 }
 
 export function saveChartToDashboard(dashboardName: string) {
+  interceptDashboardGet();
+  interceptUpdate();
+  interceptExploreGet();
+
   cy.getBySel('query-save-button').click();
   cy.get(
     '[data-test="save-chart-modal-select-dashboard-form"] [aria-label="Select a dashboard"]',
@@ -59,13 +69,16 @@ export function saveChartToDashboard(dashboardName: string) {
     .click();
   cy.get(
     '.ant-select-selection-search-input[aria-label="Select a dashboard"]',
-  ).type(dashboardName);
+  ).type(dashboardName.slice(0, 3));
   cy.get(`.ant-select-item-option[title="${dashboardName}"]`).click();
   cy.getBySel('btn-modal-save').click();
+
+  cy.wait('@update');
+  cy.wait('@get');
+  cy.wait('@getExplore');
 }
 
 export function visitSampleChartFromList(chartName: string) {
   cy.getBySel('table-row').contains(chartName).click();
   cy.intercept('POST', '/superset/explore_json/**').as('getJson');
-  cy.wait(500);
 }
diff --git a/superset-frontend/cypress-base/cypress/integration/sqllab/tabs.test.ts b/superset-frontend/cypress-base/cypress/integration/sqllab/tabs.test.ts
index c7f1a23e47..0f08593022 100644
--- a/superset-frontend/cypress-base/cypress/integration/sqllab/tabs.test.ts
+++ b/superset-frontend/cypress-base/cypress/integration/sqllab/tabs.test.ts
@@ -39,11 +39,11 @@ describe('SqlLab query tabs', () => {
       );
 
       // add two new tabs
-      cy.get('[data-test="add-tab-icon"]:visible:last').click();
+      cy.get('[data-test="add-tab-icon"]:visible:last').click({ force: true });
       cy.contains('[role="tab"]', `Untitled Query ${initialUntitledCount + 1}`);
       cy.get(tabSelector).should('have.length', initialTabCount + 1);
 
-      cy.get('[data-test="add-tab-icon"]:visible:last').click();
+      cy.get('[data-test="add-tab-icon"]:visible:last').click({ force: true });
       cy.contains('[role="tab"]', `Untitled Query ${initialUntitledCount + 2}`);
       cy.get(tabSelector).should('have.length', initialTabCount + 2);