-
Notifications
You must be signed in to change notification settings - Fork 576
Extend screenshot with specific file path in local & element by selector #137
Extend screenshot with specific file path in local & element by selector #137
Conversation
src/chrome/local-runtime.ts
Outdated
@@ -244,8 +246,20 @@ export default class LocalRuntime { | |||
} | |||
|
|||
// Returns the S3 url or local file path | |||
async returnScreenshot(): Promise<string> { | |||
const data = await screenshot(this.client) | |||
async returnScreenshot(selector?: string, options?: ScreenshotOptions): Promise<string> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if consumers want to pass options but not a selector?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right, I added the omit check to the api
…ocal-screenshot # Conflicts: # README.md # docs/api.md # src/api.ts # src/chrome/local-runtime.ts # src/types.ts # src/util.ts
… feature/extend-local-screenshot
# Conflicts: # src/api.ts # src/chrome/local-runtime.ts # src/util.ts
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @elisherer thank you for this PR. It's great that you've been able to address more or less all of #113! I left a few comments on the code of some issues I noticed. Did you test out the screenshot('.myDiv')
functionality and confirm it works as expected?
src/util.ts
Outdated
} | ||
|
||
const screenshot = await Page.captureScreenshot({ | ||
format: 'png', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we be passing captureScreenshotOptions
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lost in an inner merge, sorry.
will add a unit test, so it will not happen,
src/util.ts
Outdated
} | ||
} | ||
|
||
function writeToFileSync(data) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's a mistake, obviously 😀
src/util.ts
Outdated
return process.env['CHROMELESS_S3_BUCKET_NAME'] | ||
} | ||
|
||
function getS3BucketURL() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's nit-picky, but I'd prefer we call this getS3BucketUrl()
as it's more consistent with the naming convention throughout the rest of the code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no problem
…erver, bug fix for pdf write file, safer evaluation of expressions by string because tsc adds unwanted code
… on running chrome's version.
# Conflicts: # package.json # src/api.ts # src/chrome/local-runtime.ts # src/util.test.ts
Would appreciate any help with running the unit tests, It works very well on my machine. I wanted to stop using Google and start using our own page in chrome. |
if (isS3Configured()) { | ||
return await uploadToS3(data, 'image/png') | ||
} else { | ||
return writeToFile(data, 'png', options && options.filePath) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is filePath
truly required? Otherwise this might pass an object to writeToFile
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
either options is falsy or it is truthy and then it would be the value of filePath (or I didn't understand your concern?)
@@ -56,9 +59,9 @@ export async function waitForNode( | |||
waitTimeout: number, | |||
): Promise<void> { | |||
const { Runtime } = client |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Curious why you stringified these functions... I'm pretty sure they get stringified downstream. Is that not the case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
when running ava under nyc, it is added with coverage code which breaks once passed to the browser (i.e cov_### globals)
… feature/extend-local-screenshot
@adieuadieu, have you got the chance to go over my changes yet? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @elisherer thank you for your continued effort on this PR and addressing our feedback. I apologize for the delay from our end in reviewing it.
Using our own page for the tests rather than google.com is definitely the right direction.
If you could resolve the merge conflict introduced by #224 (CHROMELESS_S3_OBJECT_KEY_PREFIX
env variable), then I'd be ready to approve the PR. 😃
const testHtml = fs.readFileSync('./src/__tests__/test.html') | ||
const testUrl = `data:text/html,${testHtml}` | ||
|
||
const getPngMetaData = async (filePath): Promise<any> => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great job not introducing a dependency!
… feature/extend-local-screenshot # Conflicts: # src/chrome/local-runtime.ts
@adieuadieu, no more conflicts 😄 |
…-screenshot Extend screenshot with specific file path in local & element by selector
I extended the
screenshot()
function to receive 2 optional argumentsselector
(much like the other functions) - (optionally waits and) captures the viewport of an elementoptions
- for future extend-ability an object of options; starting withfilePath
in case the consumer wants to save the image in a specific path. (use case would be that running user will not have write permissions to the OS temp folder)Also, fixed some typos of
chromlessOptions
tochromelessOptions
(chrome missing e)