GithubHelp home page GithubHelp logo

Comments (29)

timhaines avatar timhaines commented on June 1, 2024 1

Hi @rsimha

I've spent a little more time digging into the script tag issue specifically.

If I clone your project, and run gulp or gulp serve I see the local js. However, if I run gulp visual-diff and open http://localhost:8000/examples/article.amp.html, then I see https://cdn.ampproject.org/v0.js. So, your replacement is not working as you intended when you run gulp visual-diff.

Can you reproduce what I've mentioned here? I think that will help you get to a point where you can troubleshoot why the runtime isn't getting swapped in correctly?

I don't think the problems you're seeing are related to the particular Percy library you're using. This same issue would be occurring if you switched to our webdriver client for example. I suspect the image height issue would too.

I'd like to help you quickly to get to a place where all of these issues are ironed out. Will be in touch further about this generally, probably over email. I'm happy to keep chatting about these two specific issues on GitHub here though.

from percy-capybara.

rsimha avatar rsimha commented on June 1, 2024

/to @fotinakis @timhaines

from percy-capybara.

timhaines avatar timhaines commented on June 1, 2024

Hi @rsimha. In one snapshot, the images sources are img/[email protected] and img/[email protected] and in the other they're img/[email protected] and img/[email protected]

Do you have some JS in place that's switching the img source?

It looks like the css you have setup maintains the image height, but fixes the width?

Is this enough info for you to resolve this?

from percy-capybara.

rsimha avatar rsimha commented on June 1, 2024

@timhaines I didn't have visibility into that behavior, so I wasn't aware that the img source was at play. I'll investigate on our side. Thanks!

from percy-capybara.

rsimha avatar rsimha commented on June 1, 2024

@timhaines Unfortunately, after investigating, this appears to be a bug. I re-ran the visual tests locally, and when img/[email protected] is rendered locally, it appears in the correct aspect ratio. However, the Percy snapshots are displaying the wrong aspect ration (way taller than it is supposed to be).

The original images are here: https://github.com/ampproject/amphtml/tree/master/examples/visual-tests/article-access.amp/img

Any ideas?

from percy-capybara.

rsimha avatar rsimha commented on June 1, 2024

A more illustrative example of what's going wrong is here: https://percy.io/ampproject/amphtml/builds/538856/view/25118149/375?mode=head&snapshot=25118149

Scroll down to see that the image that's supposed to have a 1x1 aspect ratio is being rendered with double the height. When I ran this test locally with Percy / Capybara / Chrome, I noticed that the images were showing up with the correct aspect ratio.

from percy-capybara.

rsimha avatar rsimha commented on June 1, 2024

@timhaines I did a visual diff with another test page, which does more stuff with JS to see if this is an overall JS problem with the Percy backend. This test page is designed to display the first paragraph of an article, with a "Login to read more" message to indicate that the user hasn't subscribed to the service.

Here is what I'm seeing on my machine when Percy / Capybara / Chrome are in action. Notice that the image is showing in the correct aspect ratio, and there are no JS errors. Also notice that only the first paragraph of the article is displayed, followed by the "Login to read more" message, as expected.

However, when this same page is rendered by the Percy backend, here's the snapshot that is generated (I've cropped just the top portion). Notice that the image is double the height, the entire article is displayed, and the "Login to read more" message doesn't show up, but instead, we see the "Oops, something broke" message. Any idea what's going on here? (link to snapshot)

from percy-capybara.

rsimha avatar rsimha commented on June 1, 2024

@fotinakis @timhaines We're seeing the same issue with our real-world page visual tests that use the Python library. See https://percy.io/ampproject/danielrozenberg/builds/539438

Since this is breaking all our tests right now, would it be possible to prioritize the investigation of this issue? Note that all these pages render perfectly fine on a local Chrome browser, so I'm quite sure this has something to do with how the Percy backend renders AMP pages from DOM snapshots with JS enabled.

/cc @danielrozenberg @cramforce

from percy-capybara.

timhaines avatar timhaines commented on June 1, 2024

@rsimha We will spend some time looking into this. In the interim, are builds with javascript disabled still rendering the images correctly for you?

from percy-capybara.

danielrozenberg avatar danielrozenberg commented on June 1, 2024

I think we might be using the API in an unexpected way. I used a Selenium driver to load the page on a local server, then I send the snapshot with enable_javascript=True. What I think is happening is that it takes the DOM snapshot, then on your server side since js is enable it re-does all the loading behaviours of AMP, which screw up things in many ways.

I tried a different approach right now where I skip the local server and Selenium driver, and directly send the raw HTML of each tested page with js enabled. This seems to produce the expected results for me (but I'm still investigating whether this is the approach we want to take)

from percy-capybara.

fotinakis avatar fotinakis commented on June 1, 2024

@rsimha that is an odd one, we can help you look into this. Digging through the code briefly, we recommend removing enable_javascript: true in the snapshot call because the JS is already being executed locally when you're running through in Chrome headless and generating the DOM snapshot. — ie. you shouldn't mix Capybara with javascript enabled and Percy with javascript enabled, it should be either or.

What content is missing from the pages when you don't have javascript enabled? If you run the tests without --headless or use capybara's save_and_open_screenshot locally (https://github.com/teamcapybara/capybara#debugging), do you see the content there?

from percy-capybara.

rsimha avatar rsimha commented on June 1, 2024

@fotinakis thanks for pointing out how enabling JS for both Capybara and Percy isn't the right thing to do. That part now makes sense to me.

Re: missing content, first off, I'm not using --headless to generate DOM snapshots (I see a real Chrome window). Yet, we're missing these items:

  • Certain kinds of content like ads render fine on the local Chrome window, but not when the page is rendered by Percy
  • Other AMP components like amp-access just don't work on Percy. The article is supposed to be collapsed, and say "Login to read more", like in the first screenshot in #51 (comment). Instead, we're seeing this with "Oops, something broke".
  • We're seeing blank content in the test pages for several of our AMP components. For example, this snapshot is supposed to have a GitHub gist in the blank frame. (It does have it when rendered locally.)

from percy-capybara.

rsimha avatar rsimha commented on June 1, 2024

In the interim, are builds with javascript disabled still rendering the images correctly for you?

@timhaines builds with JS disabled are rendering images in the correct size, but they're missing all kinds of other content.

For example, see the build at https://percy.io/ampproject/amphtml/builds/539721 (Original: JS enabled on Percy, New: JS disabled on Percy)

  • Ads are missing (link)
  • Static video controls are missing (link)
  • Embedded content is missing (link)
  • Github gists show up as blank (link)
  • etc...

from percy-capybara.

timhaines avatar timhaines commented on June 1, 2024

@rsimha @fotinakis I have a theory about why image sizes are rendered at double height when JS is enabled. Let me know what you think.

You're running your tests in an environment that has denser 2x displays, or at least the JS running on your client thinks so, and as a result, it's switching your 1x images to 2x. The same DOM (mostly) as before is being uploaded, but the image paths have been switched to the 2x images.

Our rendering environment is 1x, and you don't have any height constraints on the img tags, so it's rendering the images at full height of the 2x image. However, the images are constrained by width, which is why we're seeing them squished.

Does that sound like a plausible explanation for what we're seeing?

One way to test this would be to get a non-retina device, open one of the example pages, and switch the img source for the 2x version. I think we'd see the same result as what's being rendered in Percy.

@rsimha Do you have a mechanism for making sure 1x images are selected instead of 2x?

from percy-capybara.

timhaines avatar timhaines commented on June 1, 2024

@danielrozenberg @cramforce cc'ing you both on that last comment ^ because I think @rsimha may have gone on vacation, and it sounded like it was somewhat urgent to resolve.

from percy-capybara.

danielrozenberg avatar danielrozenberg commented on June 1, 2024

@timhaines, I believe @rsimha temporarily worked around this issue by merging ampproject/amphtml#13589. He'll be back on Monday and can continue the conversation then. Thanks for taking care of this!

from percy-capybara.

rsimha avatar rsimha commented on June 1, 2024

@timhaines Thanks for the analysis. I've attempted to force Chrome to render locally at a 1x pixel ratio while creating the DOM snapshot in ampproject/amphtml#13694. This didn't seem to work when I initiated the Percy build from my retina macbook. I'm keeping an eye on whether anything changes when the build is initiated from Travis CI.

Meanwhile let me know if you think there's anything wrong with how I'm forcing 1x rendering in ampproject/amphtml#13694.

from percy-capybara.

rsimha avatar rsimha commented on June 1, 2024

@timhaines I just confirmed that I am correctly forcing the pixel ratio to 1x in ampproject/amphtml#13694, and that Chrome is indeed rendering the page locally with the 1x image.

Yet, the Percy renders contain images that are double the height. See https://percy.io/ampproject/amphtml/builds/549815

Not sure what else I can try here.

from percy-capybara.

timhaines avatar timhaines commented on June 1, 2024

Hi @rsimha,

I've looked at the DOM of the uploaded snapshot too, and they specify the 1x image in the source. This is very odd.

Will look deeper into what's happening here to come up with some new ideas.

I don't think this will solve it, but could you try updating that PR you made to not enable javascript on Percy's servers please? I'd be curious to see if that has any impact.

from percy-capybara.

rsimha avatar rsimha commented on June 1, 2024

@timhaines Sounds good, thanks!

The impact of not enabling JS was that several AMP features did not work. See #51 (comment) and #51 (comment) for a partial list of things that are broken.

Edit: I changed my local branch to not enable JS while enforcing 1x rendering, and the AMP features continue to remain broken in the Percy renders. For example, see the "oops something broke" message in https://percy.io/ampproject/amphtml/builds/550166?snapshot=26016836.

from percy-capybara.

timhaines avatar timhaines commented on June 1, 2024

@rsimha Was this build done with javascript off on the client and server? I see the images are normal height: https://percy.io/ampproject/amphtml/builds/550403

from percy-capybara.

rsimha avatar rsimha commented on June 1, 2024

@timhaines Yes, https://percy.io/ampproject/amphtml/builds/550403 was done with JS off. (I confirmed by looking at the message from the head commit in the build info.)

from percy-capybara.

timhaines avatar timhaines commented on June 1, 2024

@rsimha I think I'm getting closer to understanding what's going on here. This is the DOM we're receiving for the snapshot that renders the image with the double height: https://gist.github.com/timhaines/d0206c39450a312c0082d0327fc7b658#file-amp-double-height-html

If you look towards the end of line 283, and at line 284, you'll see it already has a i-amphtml-sizer and img inserted, inside the amp-img element.

If you save this html, and open it in Google Chrome (mirroring what our server is doing), you'll see that a second i-amphtml-sizer and img get inserted in the amp-img element, and the browser allocates twice as much height for the image, due to the two i-amphtml-sizers I think.

However, if I clone your repo, run gulp, and look at the example page, the amp-img doesn't contain either i-amphtml-sizer or an img.

Does this help you understand what's going on, and maybe present you with a solution?

Also, I'm wondering if you've tried disabling javascript execution in your local tests, but having it enabled in Percy snapshot command you run? I'm hoping that might send up the amp-img element without it having been prehydrated?

from percy-capybara.

timhaines avatar timhaines commented on June 1, 2024

@rsimha @danielrozenberg further, when you run gulp and look at the examples locally, if you insert a second i-amphtml-sizer in the amp-img tag, mimic'ing what's happening on Percy's servers, you will see the double height images in your local environment.

from percy-capybara.

rsimha avatar rsimha commented on June 1, 2024

@timhaines Thanks for the detailed analysis. I'll investigate the double i-amphtml-sizer behavior you pointed out and follow up once I know more.

@danielrozenberg too brought up the idea of disabling JS for local rendering, while enabling it on the Percy side. However, we build and serve the AMP runtime locally, and so I'd imagine disabling JS locally will prevent the locally built runtime from being used, which might defeat the purpose of the tests. In any case, I'll try this and let you know what I find out. Thanks again.

from percy-capybara.

rsimha avatar rsimha commented on June 1, 2024

@timhaines I just looked at the raw DOM snapshot you linked to in #51 (comment), and noticed this line, which suggests that the page is pulling the AMP runtime from https://cdn.ampproject.org/v0.js. If this is true, I fear that we're not properly testing the locally built AMP runtime, either with JS disabled (since content is missing), or with JS enabled (since the page will start pulling the production runtime when Percy is rendering it).

Is this founded in reality, or am I not correctly understanding how Percy works?

from percy-capybara.

timhaines avatar timhaines commented on June 1, 2024

@rsimha That script tag is present in the DOM you sent us for that snapshot. If you have javascript enabled on the Percy side, that script will get loaded.

How would you expect the locally built AMP runtime to be injected into the page? Would something be swapping it out?

from percy-capybara.

rsimha avatar rsimha commented on June 1, 2024

Yeah, the locally built AMP runtime gets swapped in by the localhost server when the page is loaded and rendered on the machine that's running the build (either a developer's computer or a Travis CI VM). If one were to take a screenshot at this time, the page would look exactly as desired. We want to compare this with how the page was rendered during past builds with previous versions of the AMP runtime (from master ). Could it be that we're using the wrong Percy library?

from percy-capybara.

timhaines avatar timhaines commented on June 1, 2024

@rsimha @danielrozenberg I've tried reproducing the result I was getting here, and I haven't been able to (on master branch, locally). Today gulp visual-diff appears to be replacing https://cdn.ampproject.org/v0.js as expected.

I've inspected the source/DOM that Percy received running this locally, and it does include /dist/amp.js rather than https://cdn.ampproject.org/v0.js. Soooo. I wonder what the conditions/cause are for the replacement to sometimes not happen.

BTW, we released a new feature last week, that allows you to download the DOM that was processed for any snapshot in Percy. It's in the snapshot dropdown next to the width selector.

image

from percy-capybara.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.