Skip to content

Commit

Permalink
Bokeh plot verification with zoom test (#4394)
Browse files Browse the repository at this point in the history
Verification of a simple bokeh plot including zoom validation. Zoom
validation performed by screenshotting the plot before and after zoom
and requiring the screenshots not match.

### QA Notes

All smoke tests should pass
  • Loading branch information
testlabauto authored Aug 19, 2024
1 parent 6ae1858 commit 61223ef
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 1 deletion.
6 changes: 5 additions & 1 deletion test/automation/src/positron/positronPlots.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,12 @@ export class PositronPlots {
await this.code.waitForElement(CURRENT_STATIC_PLOT);
}

getWebviewPlotLocator(selector: string): Locator {
return this.code.driver.getFrame(OUTER_WEBVIEW_FRAME).last().frameLocator(INNER_WEBVIEW_FRAME).last().locator(selector);
}

async waitForWebviewPlot(selector: string) {
await this.code.driver.getFrame(OUTER_WEBVIEW_FRAME).last().frameLocator(INNER_WEBVIEW_FRAME).last().locator(selector).waitFor({ state: 'visible' });
await this.getWebviewPlotLocator(selector).waitFor({ state: 'visible' });
}

async clearPlots() {
Expand Down
70 changes: 70 additions & 0 deletions test/smoke/src/areas/positron/plots/plots.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,76 @@ tree`;
await simplePlotTest(app, script, '.jstree-container-ul');

});


it('Python - Verifies boken Python widget [C730343]', async function () {
const app = this.app as Application;

const script = `from bokeh.plotting import figure, output_file, show
# instantiating the figure object
graph = figure(title = "Bokeh Line Graph")
# the points to be plotted
x = [1, 2, 3, 4, 5]
y = [5, 4, 3, 2, 1]
# plotting the line graph
graph.line(x, y)
# displaying the model
show(graph)`;


await app.workbench.positronConsole.pasteCodeToConsole(script);
await app.workbench.positronConsole.sendEnterKey();

// selector not factored out as it is unique to bokeh
const bokehCanvas = '.bk-Canvas';
await app.workbench.positronPlots.waitForWebviewPlot(bokehCanvas);

await app.workbench.positronLayouts.enterLayout('fullSizedAuxBar');

// selector not factored out as it is unique to bokeh
await app.workbench.positronPlots.getWebviewPlotLocator('.bk-tool-icon-box-zoom').click();

const canvasLocator = app.workbench.positronPlots.getWebviewPlotLocator(bokehCanvas);
const boundingBox = await canvasLocator.boundingBox();

// plot capture before zoom
const bufferBeforeZoom = await canvasLocator.screenshot();

if (boundingBox) {

await app.code.driver.clickAndDrag({
from: {
x: boundingBox.x + boundingBox.width / 3,
y: boundingBox.y + boundingBox.height / 3
},
to: {
x: boundingBox.x + 2 * (boundingBox.width / 3),
y: boundingBox.y + 2 * (boundingBox.height / 3)
}
});
} else {
fail('Bounding box not found');
}

// plot capture after zoom
const bufferAfterZoom = await canvasLocator.screenshot();

// two plot captures should be different
const data = await compareImages(bufferAfterZoom, bufferBeforeZoom, options);
expect(data.rawMisMatchPercentage).toBeGreaterThan(0.0);

await app.workbench.positronPlots.clearPlots();

await app.workbench.positronPlots.waitForNoPlots();

await app.workbench.positronLayouts.enterLayout('stacked');

});

});

describe('R Plots', () => {
Expand Down

0 comments on commit 61223ef

Please sign in to comment.