Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/types/src/browser-proxy/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ export interface IBrowserProxyPlugin {

makeScreenshot(applicant: string): Promise<string | void>;

makeElementScreenshot(applicant: string, selector: Selector, scroll?: boolean): Promise<string | void>;
makeElementScreenshot(applicant: string, selector: Selector): Promise<string | void>;

uploadFile(applicant: string, filePath: string): Promise<string | void>;

Expand Down
5 changes: 2 additions & 3 deletions packages/e2e-test-app/static-fixtures/screenshot.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@
</head>

<body data-test-automation-id="root" style="padding:0;">
<div style="position: relative; width: 100px; height: 100px;padding:0;background-color: red;">

<div data-test-automation-id="testElement" style="position: relative; width: 100px; height: 100px;padding:0;background-color: red;">
</div>
</body>

</html>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import {run} from 'testring';
import {assert} from 'chai';
import {getTargetUrl} from './utils';

run(async (api) => {
const app = api.application;
await app.url(getTargetUrl(api, 'screenshot.html'));

const base64String = await app.makeElementScreenshot(app.root.testElement);

assert.ok(
typeof base64String === 'string' && base64String.length > 0,
'makeElementScreenshot should return a non-empty string',
);

assert.doesNotThrow(
() => Buffer.from(base64String, 'base64'),
'returned string should be valid base64 encoded',
);
});
4 changes: 2 additions & 2 deletions packages/plugin-selenium-driver/src/plugin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1247,12 +1247,12 @@ export class SeleniumPlugin implements IBrowserProxyPlugin {
return client.takeScreenshot();
}

public async makeElementScreenshot(applicant: string, selector: Selector, scroll: boolean = true): Promise<string | void> {
public async makeElementScreenshot(applicant: string, selector: Selector): Promise<string | void> {
await this.createClient(applicant);
const client = this.getBrowserClient(applicant);
const element = await this.getElement(applicant, selector);

return client.takeElementScreenshot(await element.elementId, scroll);
return client.takeElementScreenshot(await element.elementId);
}

public async uploadFile(
Expand Down
14 changes: 12 additions & 2 deletions packages/web-application/src/web-application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ export class WebApplication extends PluggableModule {
if (typeof selector === 'string') {
return { type: 'xpath', xpath: selector } as XpathSelector;
}

if (this.isShadowElementPathProxy(selector)) {
return { type: 'shadow-css', css: selector.toShadowCSSSelector(), parentSelectors: selector.getParentSelectors(), isShadowElement: true } as ShadowCssSelector;
}
Expand Down Expand Up @@ -458,7 +458,7 @@ export class WebApplication extends PluggableModule {
return result;
}


@stepLog(function (this: WebApplication, xpath: ElementPath, timeout: number = this.WAIT_TIMEOUT) {
return `Checking if ${this.formatXpath(xpath)} is visible for ${timeout}`;
})
Expand Down Expand Up @@ -1714,6 +1714,16 @@ export class WebApplication extends PluggableModule {
return null;
}

@stepLog(function (this: WebApplication, xpath: ElementPath) {
return `Making screenshot of ${this.formatXpath(xpath)}`;
})
public async makeElementScreenshot(xpath: ElementPath, timeout: number = this.WAIT_TIMEOUT): Promise<string | null> {
await this.waitForExist(xpath, timeout);

const normalizedXPath = this.normalizeSelector(xpath);
return await this.client.makeElementScreenshot(normalizedXPath);
}

@stepLog(function (this: WebApplication, fullPath: string) {
return `Uploading file ${fullPath}`;
})
Expand Down
4 changes: 2 additions & 2 deletions packages/web-application/src/web-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,8 @@ export class WebClient implements IWebApplicationClient {
return this.makeRequest(BrowserProxyActions.makeScreenshot, []);
}

public makeElementScreenshot(selector: Selector, scroll?: boolean) {
return this.makeRequest(BrowserProxyActions.makeElementScreenshot, [selector, scroll]);
public makeElementScreenshot(selector: Selector) {
return this.makeRequest(BrowserProxyActions.makeElementScreenshot, [selector]);
}

public uploadFile(path: string) {
Expand Down