Closed (fixed)
Project:
Drupal core
Version:
8.1.x-dev
Component:
other
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
8 Apr 2016 at 13:02 UTC
Updated:
17 Aug 2016 at 00:04 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
alexpottHere's a patch at it's simplest. It took me a while working out how to do this and not just see an image with a black background...
Without setting the background
With setting the background
Comment #3
dawehnerIMHO we should leverage the verbose directory and generate a file automatically, write a line to the output, so we don't have to deal with defining a filename.
You don't say ... but why
Comment #4
alexpott@dawehner #3.1 yeah but we don't have that yet... and also we need to list them somehow which will make it dependent on the result printer.
Re #3.2 see screenshots - but yes comment can be improved...
Comment #5
dawehnerDo you really think this is a problem?
Comment #6
nevergonePlease don't hardcode background color. Thanks!
Comment #7
dawehner@nevergone
Can you elaborate why?
Comment #8
nevergonechangeable background color
Comment #9
dawehnerLet's document the parameter.
Still would like to know why you think its needed.
Comment #10
sam152 commentedCan we implement this as verbose output that can be opened like the simpletest HTML pages every time a request happens? If enabled, it would be nice to click through a test and see what was going on at every step.
Comment #11
alexpott@Sam152 maybe but it is tricky as some javascript animations take time.
Comment #12
sam152 commentedI've been working with this for a contrib module. This might be a seperate issue, but we should create a method which writes screenshots to the same browser_output folder that BTB writes to. I think it would be a good idea to use the htmlOutputCounter and store them as similar file names. That way the verbose HTML output and the screenshots taken can form a linear history of the test run that is easy to view and debug.
I've already got a local testing trait that does this and organises the verbose output file into clickable links. Seems to be working nicely.
Comment #13
jibranFixed minor docs and used session methods instead of driver.
Comment #14
larowlanLets do this
Comment #16
dawehnerComment #18
goz commentedPatch apply locally with an up to date 8.1.x branch. relaunch test
Comment #19
goz commentedRe-rolled
Comment #20
dawehnerThank you for the reroll!
Comment #21
nevergoneParameter documentation.
Comment #23
goz commentedI update to last 8.1.x and tests don't fail for me. Strange thing, tests fails on something completely different from patch, and for a simpletest test although we are patching phpunit JavascriptTestBase tests.
I re-launch test in case something was wrong during tests
Comment #24
goz commentedComment #25
dawehnerYeah no worries, we have quite some random test failures atm.
Comment #26
hgoto commentedNice work! I'm looking forward to using this function in my test actually.
I applied and tested the patch #21 on my local environment. And passed parameter
$background_colordoesn't work.This
!empty($background)was left when changing the variable name$backgroundand should be changed to!empty($background_color), I believe. Is my understanding right?Comment #27
alexpott@hgoto you are right... nice spot
Comment #28
goz commentednice @hgoto. I checked it twice and missed it...
Comment #29
hgoto commentedThank you for your reaction. The patch #28 looks good to me! But I'd like someone else to review this for RTBC.
Comment #30
dawehnerGood spot
Comment #33
alexpottDrupal git hiccup.
Comment #35
alexpottAnd now https://www.drupal.org/node/2749955
Comment #36
webchickShould we not add a short test here to ensure that a screenshot is actually taken?
Comment #38
alexpottSure why not. Leaving at RTBC because this is very simple.
Comment #39
dawehnerNice. I doubt we can test the actual output of the screenshot though :P
Comment #40
claudiu.cristeaIt would be nice if this method is able to output a message in the console with the URL/path of the created file, like in the case of HTML output. That is very useful because you can click the link/path and see instantly the output.
Also I would make the filename optional, then I would default to a built filename (from test no + some variance) and I would use the same location as for HTML pages. What about that?
Comment #41
alexpott@claudiu.cristea imo that is all followup - atm this is a simple debugging tool - plugging in to \Drupal\Tests\Listeners\HtmlOutputPrinter - which is where we'd have to do - this can be done later.
Comment #42
dawehnerI think @alexpott makes a fair point. The general verbose feature needs some additional work.
Comment #43
xjmSo I discussed this with @alexpott... this is technically a potential vector for JS injection.
E.g., suppose someone writes a UI to allow you to set the background color of your test screenshots. Drupal as a rule filters on output, not input, so that UI could be legit in passing minimally validated user input here.
I don't actually think this is a plausible exploit -- this is a test runner after all -- more concerned about the precedent of
$this->executeScript($variable).I mentioned this to @alexpott and he is thinking about it.
Comment #44
alexpott@xjm nice catch.
We can use Zend's escaper for this. I think this is worth doing because people learn by looking at code - so whilst I don't think there is a security issue per se - I think we should set a good example of how to add variables to Javascript in code.
Comment #45
dawehnerNice!
I thought for a while whether we could leverage twig, turns out that would be a bit of a huzzle, as
twig_escape_filter()is not necessarily easy to use.Comment #47
xjmThanks @alexpott and @dawehner; I think this addresses the potential problem.
Technically this is an API addition to a public API (the testing framework is considered public even though tests themselves are not), but we sort of have the idea that JTB is experimentalish, and I think the value of this method for debugging 8.1.x vastly outweighs any risk of disruption from a method name collision. @alexpott is updating https://www.drupal.org/node/2716803 just in case.
@Sam152 and @claudiu.cristea, I think both your suggestions are worth followup issues.
Committed e42f6c5 and pushed to 8.2.x. Thanks!
Comment #49
droplet commentedOh! Just doing local test but got committed.
won't it encoded (escaped) #hex color?
Similiar regex would work I think but limited to hex code and color name only, no RGBa,HSL..etc
Comment #50
alexpottho hum...
Comment #53
xjmThanks @droplet and @alexpott, I reverted. I guess this is why we should actually not leave issues at RTBC. :)
@alexpott and I agreed to remove the background color customization for now and create a followup for that, so that we can add the debugging now without getting blocked on the right way to implement it.
Comment #54
xjmComment #55
alexpottHere's a patch that does exactly that. It seemed like a nice feature to have a changeable background colour - introduced in #6 but the 99% use case is just to get a good looking screenshot which this now does. If you want different background colours you can always set the background colour outside of this method and call the screenshotting method too. This is just a convenience method to make things quick and simple for debugging - because I spent a few hours crying over black screenshots and didn't want anyone else to have to go through what I did. If we add changeable colours in the future so be it.
Comment #56
nevergoneregular expression added
Comment #57
xjmThanks @nevergone. Per #53 and #54 let's address that in a followup.
Setting back to NR for #55.
Comment #58
droplet commentedUsually, frontender apply bg color to BODY. We could consider applying the bgColor to HTML (document.bgColor) if that worked for phantomjs bug also
Or
Comment #59
wim leersEhm… isn't #55 ready? What am I missing? AFAICT #56 is an accidental mistake?
Comment #60
dawehnerIMHO we should document why we have this regex here
Comment #61
alexpott@nevergone can we do the customisable background colour in a follow-up as suggested by @xjm. It's not necessary for the usual use-case and it's just preventing this issue going in since the custom regex in #56 needs testing.
Uploading #55 so the correct patch to review is last.
Comment #62
dawehnerGood idea.
Thank you alex!
Comment #64
xjmCommitted c4cb804 and pushed to 8.2.x. Thanks!
I've also backported this to 8.1.x, as explained above. This is in spite of semver and the risk of method name collisions, because this is very useful for debugging and I consider JSTB "experimental-ish". #2773087: [policy, maybe patch] Clarify backport policy for testing framework changes, including new BTB tests is the place to discuss further whether or not that makes sense.
We still could use that followup for the background color configurability -- @nevergone and @droplet's feedback should be included in that issue.
Thanks everyone!
Comment #66
xjmComment #67
wim leersHigh fives all around!