Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add scrollTo selector #774

Open
wants to merge 12 commits into
base: master
Choose a base branch
from

Conversation

aliu145
Copy link

@aliu145 aliu145 commented May 15, 2018

No description provided.

@aliu145
Copy link
Author

aliu145 commented May 15, 2018

@garris I'm not sure why the update to README.md failed Docker Cloud

Copy link
Owner

@garris garris left a comment

Choose a reason for hiding this comment

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

This looks great. Would you please add a test for this in https://github.com/garris/BackstopJS/blob/master/test/configs/backstop_features.js

Maybe you can sneak an non-obvious nested element inside the index.html that we use for testing. Then please run the smoke test to insure it’s working as expected.

Just let me know if you have any questions.

@aliu145
Copy link
Author

aliu145 commented May 17, 2018

I added a test, but wasn't able to run it since I'm running into issues installing BackstopJS dependencies (puppeteer)... would you be able to help pull my branch and run it?

@garris
Copy link
Owner

garris commented May 18, 2018

No problem — will do this tomorrow.

Question— does puppeteer install on windows correctly if you just install with npm install puppeteer into some directory? I am not clear if there is a problem with puppeteer or the backstop installation.

@aliu145
Copy link
Author

aliu145 commented May 24, 2018

@garris - Hello! any update on this? When will it be able to be merged in? Thanks.

Copy link
Owner

@garris garris left a comment

Choose a reason for hiding this comment

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

Hi Anna, Thank you very much for the PR. I added a few comments. It might take a bit more effort in some areas but I hope you stick with it. Please reach out if you have questions. Best, Garris


if (scrollToSelector) {
chromy
.wait()
Copy link
Owner

Choose a reason for hiding this comment

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

what does this line do?

if (scrollToSelector) {
chromy
.wait()
.evaluate(`_scrollToSelector = '${scrollToSelector}'`)
Copy link
Owner

Choose a reason for hiding this comment

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

I dont think you need this line.

.evaluate(`_scrollToSelector = '${scrollToSelector}'`)
.evaluate(function() {
document.querySelector(_scrollToSelector).scrollIntoView();
}, scrollToSelector);
Copy link
Owner

Choose a reason for hiding this comment

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

I think you want this...

.evaluate(function(scrollToSelector){
  document.querySelector(scrollToSelector).scrollIntoView();
}, scrollToSelector);

Copy link
Owner

Choose a reason for hiding this comment

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

You probably also need to guard against scrollToSelector not being found.

@@ -16,6 +17,15 @@ module.exports = async (page, scenario) => {
await page.click(clickSelectorIndex);
}
}

if (scrollToSelector) {
for (const scrollToSelectorIndex of [].concat(scrollToSelector)) {
Copy link
Owner

Choose a reason for hiding this comment

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

Do you intend scrollToSelector to take an array value? or just a string? Array feels like it would produce some noisy results.

index.html Outdated
@@ -46,6 +46,9 @@ <h1>Visual regression testing for web apps.</h1>
<p class="getItBlock col-10">
<span class="cta"><a href="https://github.com/garris/BackstopJS" class="github-link"><img src="assets/github-icon.png" class="github-icon" alt="Get it on GitHub"></a></span>
<span class="cta"><a href="https://github.com/garris/BackstopJS">Get it on github!</a></span>
<a href="https://github.com/garris/BackstopJS" class="puppy-link">
Copy link
Owner

Choose a reason for hiding this comment

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

Is this going to show up on the backstop brochure page? It's a bit of a sequitur 🤔

label: 'scrollTo',
url: '../../index.html',
scrollToSelector: '.puppy-link',
selectors: ['puppy-link']
Copy link
Owner

Choose a reason for hiding this comment

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

I thought this feature was intended to test a child-element inside a scrollable div? I thought the below-the-fold elements that were direct children of the body tag already worked correctly? Am I missing something here?

Copy link
Author

Choose a reason for hiding this comment

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

It is... how can I write a backstop_features test that can imitate this? Do I need to add a scrollable div to index.html?

Copy link
Owner

Choose a reason for hiding this comment

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

In this case — I think it’s best that you create a folder in the test directory, maybe call it “special_cases” or something like that. And in there you can add an html file which easily simulates the issue. For that scenario you can point to that file. Does that make sense?

Copy link
Owner

Choose a reason for hiding this comment

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

I just thought — what might be better instead is to add a folder to the examples directory and call it “scrolling_cases”. In there you can add an html file which simulated the issue and a backstop config which demonstrates how to test the case. You can add a short readme with a sentence which explains the issue and how to resolve it so other users can learn from your example.

Copy link
Author

Choose a reason for hiding this comment

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

ohhhh gotcha! OK I will work on adding that

@garris
Copy link
Owner

garris commented May 25, 2018

Hi @aliu145 -- very sorry -- I had actually started a review but ran out of time and never submitted the comments. The review is up. Please take a look and feel free to reach out if you have questions.

Also -- did you finally resolve your installation issue? Generally we like to test our work before posting a PR.

Thanks!

@aliu145
Copy link
Author

aliu145 commented Jun 26, 2018

Hmm, as I'm testing this, it's working for puppeteer:

image

But not for chromy:

image

Do you have any idea why that might be?

Copy link
Owner

@garris garris left a comment

Choose a reason for hiding this comment

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

Thanks for this — I’ll be in Japan in holiday for two weeks. Will review as soon as I can. Cheers, Garris

@garris
Copy link
Owner

garris commented Jun 26, 2018

See my comment for the Chromy script issue.

.evaluate(`_scrollToSelector = '${scrollToSelector}'`)
.evaluate(function() {
document.querySelector(_scrollToSelector).scrollIntoView();
}, scrollToSelector);
Copy link
Author

Choose a reason for hiding this comment

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

Hi @garris, I made these updates but it's still not working (ie the screenshot shows that it did not properly scroll the container)

@aliu145
Copy link
Author

aliu145 commented Jul 12, 2018

@garris , I am still seeing issue where the same code is able to scroll container with puppeteer, but doesn't work with chromy :/

Here is the chromy script:
` if (scrollToSelector) {

chromy

  .wait(scrollToSelector)

  .evaluate(function () {

    document.querySelector(scrollToSelector).scrollIntoView();

  }, scrollToSelector);

}`

Do you have any suggestions?

@garris
Copy link
Owner

garris commented Jul 13, 2018

Ok Ms Anna, Fixed and Merged!

Final changes here 👉 128c647

Please test & validate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants