dosubot[bot] commented on issue #33615:
URL: https://github.com/apache/superset/issues/33615#issuecomment-2919068469

   <!-- Answer -->
   Here’s a Cypress script template to automate opening and saving charts in 
Superset, which will populate the missing query context for each chart. This 
template assumes you have a list of chart IDs and valid Superset credentials.
   
   ### 1. Cypress Setup
   
   If you haven’t already, install Cypress in your project:
   
   ```bash
   npm install cypress --save-dev
   ```
   
   Create a new test file, for example: `cypress/e2e/save_charts.cy.js`.
   
   ### 2. Script Template
   
   ```js
   // cypress/e2e/save_charts.cy.js
   
   const supersetUrl = 'http://localhost:8088'; // Change if your Superset runs 
elsewhere
   const username = 'YOUR_USERNAME';
   const password = 'YOUR_PASSWORD';
   const chartIds = [2030, 2910]; // Add all your chart IDs here
   
   describe('Bulk open and save charts to populate query context', () => {
     before(() => {
       // Log in to Superset
       cy.visit(`${supersetUrl}/login/`);
       cy.get('input[name="username"]').type(username);
       cy.get('input[name="password"]').type(password);
       cy.get('button[type="submit"]').click();
       // Wait for login to complete
       cy.url().should('not.include', '/login');
     });
   
     chartIds.forEach(chartId => {
       it(`Open and save chart ${chartId}`, () => {
         // Visit the Explore page for the chart
         cy.visit(`${supersetUrl}/explore/?slice_id=${chartId}`);
         // Wait for the chart to load
         cy.get('[data-test="query-save-button"]', { timeout: 20000 
}).should('be.visible');
         // Click the Save (overwrite) button
         cy.get('[data-test="query-save-button"]').click();
         cy.get('[data-test="save-overwrite-radio"]').check();
         cy.get('[data-test="btn-modal-save"]').click();
         // Wait for save to complete (optional: check for success notification)
         cy.contains('Chart saved', { timeout: 10000 });
       });
     });
   });
   ```
   
   ### 3. How to Run
   
   Start your Superset instance and run Cypress:
   
   ```bash
   npx cypress open
   ```
   
   Select the test file you created and let it run. Cypress will log in, open 
each chart, and save it, which will generate the query context needed for the 
`/api/v1/chart/{pk}/data/` endpoint.
   
   ### 4. Customization
   
   - Update `supersetUrl`, `username`, `password`, and `chartIds` as needed.
   - If you use SSO or a different login flow, adjust the login steps 
accordingly.
   - You can expand the script to read chart IDs from a file or API if needed.
   
   ### References
   
   This template is based on patterns and selectors used in Superset’s own 
Cypress tests, such as the use of `[data-test="query-save-button"]` and the 
save modal flow, as seen in the official test files 
([example](https://github.com/apache/superset/blob/master/superset-frontend/cypress-base/cypress/e2e/explore/link.test.ts)).
   
   If you need to save charts to a specific dashboard or want to automate more 
complex flows, you can adapt functions like `saveChartToDashboard` from 
Superset’s test suite 
([example](https://github.com/apache/superset/blob/master/superset-frontend/cypress-base/cypress/e2e/explore/utils.ts)).
   
   Let me know if you need a version that saves to dashboards or handles other 
custom flows!
   
   
   <!-- Dosu Comment Footer -->
   *To reply, just mention my name [@dosu](https://go.dosu.dev/dosubot).*
   
   ---
   <sup>How did I do? 
[Good](https://app.dosu.dev/response-feedback/7486daf8-c6d3-4f0d-aa82-4620d3857eb5?feedback_type=great_response)
 | 
[Irrelevant](https://app.dosu.dev/response-feedback/7486daf8-c6d3-4f0d-aa82-4620d3857eb5?feedback_type=irrelevant_answer)
 | 
[Incorrect](https://app.dosu.dev/response-feedback/7486daf8-c6d3-4f0d-aa82-4620d3857eb5?feedback_type=incorrect_sources)
 | 
[Verbose](https://app.dosu.dev/response-feedback/7486daf8-c6d3-4f0d-aa82-4620d3857eb5?feedback_type=too_verbose)
 | 
[Hallucination](https://app.dosu.dev/response-feedback/7486daf8-c6d3-4f0d-aa82-4620d3857eb5?feedback_type=hallucination)
 | [Report 
🐛](https://app.dosu.dev/response-feedback/7486daf8-c6d3-4f0d-aa82-4620d3857eb5?feedback_type=bug_report)
 | 
[Other](https://app.dosu.dev/response-feedback/7486daf8-c6d3-4f0d-aa82-4620d3857eb5?feedback_type=other)</sup>&nbsp;&nbsp;[![Join
 
Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[!
 [Share on 
X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/apache/superset/issues/33615)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to