Skip to content
This repository was archived by the owner on Nov 24, 2018. It is now read-only.

Extend screenshot with specific file path in local & element by selector #137

Merged

Conversation

elisherer
Copy link
Contributor

I extended the screenshot() function to receive 2 optional arguments

  • selector (much like the other functions) - (optionally waits and) captures the viewport of an element
  • options - for future extend-ability an object of options; starting with filePath 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 to chromelessOptions (chrome missing e)

@@ -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> {
Copy link
Contributor

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?

Copy link
Contributor Author

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
Copy link
Collaborator

@adieuadieu adieuadieu left a 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',
Copy link
Collaborator

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?

Copy link
Contributor Author

@elisherer elisherer Aug 6, 2017

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) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's this?

Copy link
Contributor Author

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() {
Copy link
Collaborator

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no problem

@adieuadieu adieuadieu modified the milestones: v1.3, v1.2 Aug 6, 2017
Eli Sherer and others added 4 commits August 6, 2017 18:25
…erver, bug fix for pdf write file, safer evaluation of expressions by string because tsc adds unwanted code
# Conflicts:
#	package.json
#	src/api.ts
#	src/chrome/local-runtime.ts
#	src/util.test.ts
@elisherer
Copy link
Contributor Author

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)
Copy link
Contributor

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

Copy link
Contributor Author

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
Copy link
Contributor

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?

Copy link
Contributor Author

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)

@elisherer
Copy link
Contributor Author

@adieuadieu, have you got the chance to go over my changes yet?
@joelgriffith, have you seen my responses to your comments?

Copy link
Collaborator

@adieuadieu adieuadieu left a 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> => {
Copy link
Collaborator

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
@elisherer
Copy link
Contributor Author

@adieuadieu, no more conflicts 😄

@adieuadieu adieuadieu modified the milestones: v1.4, v1.3 Aug 29, 2017
@adieuadieu adieuadieu merged commit af5f380 into schickling:master Aug 30, 2017
adieuadieu added a commit that referenced this pull request Aug 30, 2017
@adieuadieu adieuadieu mentioned this pull request Aug 30, 2017
@elisherer elisherer deleted the feature/extend-local-screenshot branch August 30, 2017 12:46
webpolis pushed a commit to webpolis/yb-chromeless that referenced this pull request Oct 5, 2017
…-screenshot

Extend screenshot with specific file path in local & element by selector
webpolis pushed a commit to webpolis/yb-chromeless that referenced this pull request Oct 5, 2017
@mattcanty mattcanty mentioned this pull request Feb 13, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants