Skip to content

Commit 7e3e133

Browse files
authored
fix: Most common flaky Cypress tests (#21941)
1 parent 95b4323 commit 7e3e133

File tree

7 files changed

+48
-31
lines changed

7 files changed

+48
-31
lines changed

superset-frontend/cypress-base/cypress/integration/chart_list/list.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,15 +88,14 @@ describe('Charts list', () => {
8888
saveChartToDashboard('1 - Sample dashboard');
8989
saveChartToDashboard('2 - Sample dashboard');
9090
saveChartToDashboard('3 - Sample dashboard');
91-
saveChartToDashboard('4 - Sample dashboard');
9291
visitChartList();
9392
cy.getBySel('count-crosslinks').should('be.visible');
9493
cy.getBySel('crosslinks')
9594
.first()
9695
.trigger('mouseover')
9796
.then(() => {
9897
cy.get('.ant-tooltip')
99-
.contains('4 - Sample dashboard')
98+
.contains('3 - Sample dashboard')
10099
.invoke('removeAttr', 'target')
101100
.click();
102101
cy.wait('@get');

superset-frontend/cypress-base/cypress/integration/dashboard/editmode.test.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ function dragComponent(
6262
cy.getBySel('dashboard-charts-filter-search-input').type(component);
6363
cy.wait('@filtering');
6464
}
65+
cy.wait(500);
6566
drag(`[data-test="${target}"]`, component).to(
6667
'[data-test="grid-content"] [data-test="dragdroppable-object"]',
6768
);
@@ -148,16 +149,21 @@ function assertMetadata(text: string) {
148149
});
149150
}
150151
function clearMetadata() {
151-
cy.wait(500);
152152
cy.get('#json_metadata').then($jsonmetadata => {
153-
cy.wrap($jsonmetadata).type('{selectall} {backspace}');
153+
cy.wrap($jsonmetadata).find('.ace_content').click();
154+
cy.wrap($jsonmetadata)
155+
.find('.ace_text-input')
156+
.type('{selectall} {backspace}');
154157
});
155158
}
156159

157160
function writeMetadata(metadata: string) {
158-
cy.get('#json_metadata').then($jsonmetadata => {
159-
cy.wrap($jsonmetadata).type(metadata, { parseSpecialCharSequences: false });
160-
});
161+
cy.get('#json_metadata').then($jsonmetadata =>
162+
cy
163+
.wrap($jsonmetadata)
164+
.find('.ace_text-input')
165+
.type(metadata, { parseSpecialCharSequences: false }),
166+
);
161167
}
162168

163169
function openExplore(chartName: string) {

superset-frontend/cypress-base/cypress/integration/dashboard/nativeFilters.test.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -593,13 +593,13 @@ describe('Native filters', () => {
593593
});
594594

595595
it('User can cancel changes in native filter', () => {
596-
visitDashboard();
597-
enterNativeFilterEditModal(false);
598-
fillNativeFilterForm(
599-
testItems.filterType.value,
600-
'suffix',
601-
testItems.datasetForNativeFilter,
602-
);
596+
prepareDashboardFilters([
597+
{ name: 'country_name', column: 'country_name', datasetId: 2 },
598+
]);
599+
enterNativeFilterEditModal();
600+
cy.getBySel('filters-config-modal__name-input').type('|EDITED', {
601+
force: true,
602+
});
603603
cancelNativeFilterSettings();
604604
enterNativeFilterEditModal();
605605
cy.get(nativeFilters.filtersList.removeIcon).first().click();

superset-frontend/cypress-base/cypress/integration/explore/advanced_analytics.test.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ describe('Advanced analytics', () => {
2929
cy.visitChartByName('Num Births Trend');
3030
cy.verifySliceSuccess({ waitAlias: '@postJson' });
3131

32-
cy.get('.ant-collapse-header').contains('Advanced Analytics').click();
32+
cy.get('.ant-collapse-header')
33+
.contains('Advanced Analytics')
34+
.click({ force: true });
3335

3436
cy.get('[data-test=time_compare]').find('.ant-select').click();
3537
cy.get('[data-test=time_compare]')
@@ -43,13 +45,16 @@ describe('Advanced analytics', () => {
4345
cy.get('button[data-test="run-query-button"]').click();
4446
cy.wait('@postJson');
4547
cy.wait('@putExplore');
48+
4649
cy.reload();
4750
cy.verifySliceSuccess({
4851
waitAlias: '@postJson',
4952
chartSelector: 'svg',
5053
});
5154
cy.wait('@getExplore');
52-
cy.get('.ant-collapse-header').contains('Advanced Analytics').click();
55+
cy.get('.ant-collapse-header')
56+
.contains('Advanced Analytics')
57+
.click({ force: true });
5358
cy.get('[data-test=time_compare]')
5459
.find('.ant-select-selector')
5560
.contains('28 days');

superset-frontend/cypress-base/cypress/integration/explore/control.test.ts

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,29 +23,22 @@ import { interceptChart } from 'cypress/utils';
2323
import { FORM_DATA_DEFAULTS, NUM_METRIC } from './visualizations/shared.helper';
2424

2525
describe('Datasource control', () => {
26+
beforeEach(() => {
27+
cy.preserveLogin();
28+
});
29+
2630
const newMetricName = `abc${Date.now()}`;
2731

2832
it('should allow edit dataset', () => {
29-
let numScripts = 0;
30-
31-
cy.login();
3233
interceptChart({ legacy: true }).as('chartData');
3334

3435
cy.visitChartByName('Num Births Trend');
3536
cy.verifySliceSuccess({ waitAlias: '@chartData' });
3637

3738
cy.get('[data-test="datasource-menu-trigger"]').click();
3839

39-
cy.get('script').then(nodes => {
40-
numScripts = nodes.length;
41-
});
42-
4340
cy.get('[data-test="edit-dataset"]').click();
4441

45-
// should load additional scripts for the modal
46-
cy.get('script').then(nodes => {
47-
expect(nodes.length).to.greaterThan(numScripts);
48-
});
4942
cy.get('[data-test="edit-dataset-tabs"]').within(() => {
5043
cy.contains('Metrics').click();
5144
});
@@ -205,6 +198,7 @@ describe('Time range filter', () => {
205198
cy.get('input[value="now"]');
206199
});
207200
cy.get('[data-test=cancel-button]').click();
201+
cy.wait(500);
208202
cy.get('.ant-popover').should('not.be.visible');
209203
});
210204
});

superset-frontend/cypress-base/cypress/integration/explore/utils.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
* under the License.
1818
*/
1919

20+
import { interceptGet as interceptDashboardGet } from '../dashboard/utils';
21+
2022
export function interceptFiltering() {
2123
cy.intercept('GET', `/api/v1/chart/?q=*`).as('filtering');
2224
}
@@ -41,6 +43,10 @@ export function interceptExploreJson() {
4143
cy.intercept('POST', `/superset/explore_json/**`).as('getJson');
4244
}
4345

46+
export function interceptExploreGet() {
47+
cy.intercept('GET', `/api/v1/explore/?slice_id=**`).as('getExplore');
48+
}
49+
4450
export function setFilter(filter: string, option: string) {
4551
interceptFiltering();
4652

@@ -51,6 +57,10 @@ export function setFilter(filter: string, option: string) {
5157
}
5258

5359
export function saveChartToDashboard(dashboardName: string) {
60+
interceptDashboardGet();
61+
interceptUpdate();
62+
interceptExploreGet();
63+
5464
cy.getBySel('query-save-button').click();
5565
cy.get(
5666
'[data-test="save-chart-modal-select-dashboard-form"] [aria-label="Select a dashboard"]',
@@ -59,13 +69,16 @@ export function saveChartToDashboard(dashboardName: string) {
5969
.click();
6070
cy.get(
6171
'.ant-select-selection-search-input[aria-label="Select a dashboard"]',
62-
).type(dashboardName);
72+
).type(dashboardName.slice(0, 3));
6373
cy.get(`.ant-select-item-option[title="${dashboardName}"]`).click();
6474
cy.getBySel('btn-modal-save').click();
75+
76+
cy.wait('@update');
77+
cy.wait('@get');
78+
cy.wait('@getExplore');
6579
}
6680

6781
export function visitSampleChartFromList(chartName: string) {
6882
cy.getBySel('table-row').contains(chartName).click();
6983
cy.intercept('POST', '/superset/explore_json/**').as('getJson');
70-
cy.wait(500);
7184
}

superset-frontend/cypress-base/cypress/integration/sqllab/tabs.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ describe('SqlLab query tabs', () => {
3939
);
4040

4141
// add two new tabs
42-
cy.get('[data-test="add-tab-icon"]:visible:last').click();
42+
cy.get('[data-test="add-tab-icon"]:visible:last').click({ force: true });
4343
cy.contains('[role="tab"]', `Untitled Query ${initialUntitledCount + 1}`);
4444
cy.get(tabSelector).should('have.length', initialTabCount + 1);
4545

46-
cy.get('[data-test="add-tab-icon"]:visible:last').click();
46+
cy.get('[data-test="add-tab-icon"]:visible:last').click({ force: true });
4747
cy.contains('[role="tab"]', `Untitled Query ${initialUntitledCount + 2}`);
4848
cy.get(tabSelector).should('have.length', initialTabCount + 2);
4949

0 commit comments

Comments
 (0)