Skip to content

Commit

Permalink
e2e-test: add savePlot (#5479)
Browse files Browse the repository at this point in the history
### Intent

The goal of this PR was to improve the test by removing a hardcoded wait
that was previously required for the test to work and pass. I was able
to make improvements to the test and it runs/passes but occasionally I
kept running into a flake of RPC timeout on CI runs for the python plot
test. Maybe that was the original issue? (The in-line comment didn't
say). Adding the wait back in does seem to remove the flake, so maybe
that was it after-all. Regardless, there are still improvements worth
merging in.

### Approach

A new method, savePlot, was introduced to encapsulate and enhance the
logic for saving a plot to a selected file type. Additionally, some
before/after hooks were cleaned up for better readability.

### QA Notes
* Confirmed plots test [PASS on
Windows](https://d38p2avprg8il3.cloudfront.net/playwright-report-12008951342/index.html#?q=plots).
* I did not see an open issue for the RPC timeout? If we don't have one,
I can add it and tag it to this test.
  • Loading branch information
midleman authored Nov 25, 2024
1 parent 6bb8daf commit c3c4896
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 145 deletions.
51 changes: 43 additions & 8 deletions test/automation/src/positron/positronPlots.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,20 @@ export class PositronPlots {
copyPlotButton: Locator;
zoomPlotButton: Locator;
currentPlot: Locator;
savePlotModal: Locator;
overwriteModal: Locator;

constructor(private code: Code) {
this.nextPlotButton = this.code.driver.getLocator(NEXT_PLOT_BUTTON);
this.previousPlotButton = this.code.driver.getLocator(PREVIOUS_PLOT_BUTTON);
this.clearPlotsButton = this.code.driver.getLocator(CLEAR_PLOTS_BUTTON);
this.plotSizeButton = this.code.driver.getLocator(PLOT_SIZE_BUTTON);
this.savePlotButton = this.code.driver.getLocator(SAVE_PLOT_BUTTON);
this.copyPlotButton = this.code.driver.getLocator(COPY_PLOT_BUTTON);
this.zoomPlotButton = this.code.driver.getLocator(ZOOM_PLOT_BUTTON);
this.currentPlot = this.code.driver.getLocator(CURRENT_PLOT);
this.nextPlotButton = this.code.driver.page.locator(NEXT_PLOT_BUTTON);
this.previousPlotButton = this.code.driver.page.locator(PREVIOUS_PLOT_BUTTON);
this.clearPlotsButton = this.code.driver.page.locator(CLEAR_PLOTS_BUTTON);
this.plotSizeButton = this.code.driver.page.locator(PLOT_SIZE_BUTTON);
this.savePlotButton = this.code.driver.page.locator(SAVE_PLOT_BUTTON);
this.copyPlotButton = this.code.driver.page.locator(COPY_PLOT_BUTTON);
this.zoomPlotButton = this.code.driver.page.locator(ZOOM_PLOT_BUTTON);
this.currentPlot = this.code.driver.page.locator(CURRENT_PLOT);
this.savePlotModal = this.code.driver.page.locator('.positron-modal-dialog-box').filter({ hasText: 'Save Plot' });
this.overwriteModal = this.code.driver.page.locator('.positron-modal-dialog-box').filter({ hasText: 'The file already exists' });
}

async waitForCurrentPlot() {
Expand Down Expand Up @@ -98,4 +102,35 @@ export class PositronPlots {
// wait for clipboard to be populated
await this.code.wait(500);
}

async savePlot({ name, format, overwrite = true }: { name: string; format: 'JPEG' | 'PNG' | 'SVG' | 'PDF' | 'TIFF'; overwrite?: boolean }) {
// click save and wait for save plot modal
await this.savePlotButton.click();
await expect(this.savePlotModal).toBeVisible();

// enter new name and select format
await this.savePlotModal.getByLabel('Name', { exact: true }).fill(name);
await this.savePlotModal.getByLabel('Format').click();
await this.code.driver.page.getByRole('button', { name: format }).click();

// ensure dropdown value has updated
await expect(this.savePlotModal.getByLabel(`Format${format}`)).toBeVisible();
// bug workaround related to RPC timeout
await this.code.driver.page.waitForTimeout(1000);

// save plot
await this.savePlotModal.getByRole('button', { name: 'Save' }).click();

// handle overwrite dialog
if (await this.overwriteModal.isVisible()) {
if (overwrite) {
await this.overwriteModal.getByRole('button', { name: 'Overwrite' }).click();
await expect(this.savePlotModal).not.toBeVisible();
} else {
await this.overwriteModal.getByRole('button', { name: 'Cancel' }).click();
}
} else {
await expect(this.savePlotModal).not.toBeVisible();
}
}
}
8 changes: 4 additions & 4 deletions test/automation/src/positron/positronPopups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,19 +89,19 @@ export class PositronPopups {
}

async waitForModalDialogBox() {
await this.code.waitForElement(POSITRON_MODAL_DIALOG_BOX);
await expect(this.code.driver.page.locator(POSITRON_MODAL_DIALOG_BOX)).toBeVisible({ timeout: 30000 });
}

async waitForModalDialogBoxToDisappear() {
expect(this.code.driver.page.locator(POSITRON_MODAL_DIALOG_BOX)).not.toBeVisible({ timeout: 30000 });
await expect(this.code.driver.page.locator(POSITRON_MODAL_DIALOG_BOX)).not.toBeVisible({ timeout: 30000 });
}

async clickOkOnModalDialogBox() {
await this.code.waitAndClick(POSITRON_MODAL_DIALOG_BOX_OK);
await this.code.driver.page.locator(POSITRON_MODAL_DIALOG_BOX_OK).click();
}

async clickCancelOnModalDialogBox() {
await this.code.waitAndClick(POSITRON_MODAL_DIALOG_BOX_CANCEL);
await this.code.driver.page.locator(POSITRON_MODAL_DIALOG_BOX_CANCEL).click();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ test.describe('SQLite DB Connection', { tag: ['@web', '@win', '@pr'] }, () => {
});

await test.step('Open connections pane', async () => {
await app.workbench.positronLayouts.enterLayout('fullSizedAuxBar');
await app.workbench.positronVariables.clickDatabaseIconForVariableRow('conn');
await app.workbench.positronConnections.connectIcon.click();
});
Expand Down
Loading

0 comments on commit c3c4896

Please sign in to comment.