Problem/Motivation
#2232861: Create BrowserTestBase for web-testing on top of Mink introduced BrowserTestBase.
It does not yet have feature parity with WebTestBase.
Notable omission is the verbose output. In WebTestBase terms verbose means 2 things - verbose test assertion message printing and the ability to see the output generated for the simpletest browser.
Proposed resolution
Add the ability to store generated HTML to BrowserTestBase. Don't call it verbose to avoid confusion with run-tests and phpunit's verbose flags.
If you set a BROWSERTEST_OUTPUT_DIRECTORY
environmental variable before running tests any HTML generated during a BrowserTestBase test (including the new JavascriptTestBase) will be stored and displayed to the user as a link they can visit when the test is complete.
Remaining tasks
User interface changes
None
API changes
HTML generated during test is available
Comment | File | Size | Author |
---|---|---|---|
#65 | 55-65-interdiff.txt | 816 bytes | alexpott |
#65 | 2469721-2-65.patch | 62.3 KB | alexpott |
#55 | 51-55-interdiff.txt | 9.52 KB | alexpott |
#55 | 2469721-2-55.patch | 62.48 KB | alexpott |
#51 | 2469721-verbose.51.patch | 61.7 KB | larowlan |
Comments
Comment #1
larowlanComment #2
grom358 CreditAttribution: grom358 commentedWhat about the use of logging API as replacement?
Comment #3
larowlanTime to pick this up again
Comment #4
larowlanMade some progress here, but a hard-blocker might be the run in separate process, as we can't reach into that process to track output - those tests deliberately don't output anything (no results printer) in the separate process because rely on serialize/unserialize to get results in and out.
Comment #5
dawehner#2664150: Expand BrowserTestBase with error handling support implements this in the meantime
Comment #6
larowlanDifferent use case, this one is about dumping
$this->getSession()->getPage()->getHtml();
to .html files.Comment #7
dawehnerOh nevermind, I cannot read.
Comment #9
larowlanHere's a first crack
Output looks like so:
Files pretty much same as existing simpletest with the next/prev links.
Comment #10
larowlanFun fact: my first core patch since Dec 18.
Comment #11
dawehnerI think the following small bit would be neat for some people (see interdiff.txt).
As for now we don't have any support for CSS, because well, we link to files in a temporary directy and not some files directory form within Drupal.
Do you think there is any chance we could do that? I mean at that point we certainly have some form of installed Drupal, this is what BrowserTestBase is doing, right?
Just some brainstorming: What would we do in a future world where we might want to leverage parallel test running?
Do you plan to implement support for HTTP headers as well? IMHO we should print them simply all the time. They could be often helpful.
Comment #12
alexpottThis is a test-only change it can go when it is ready.
Comment #13
dawehnerSo I'm still wondering whether we could write files to sites/default ... for browser tests at least we certainly have the actual site URL as environment variable available.
Comment #14
larowlanYes the test does, but the result printer does not.
Comment #15
dawehnerI'm confused, environment variables should be available always, as they are defined in the environment, so even outside of the PHP process.
Comment #16
larowlanWe have the site URL, but we don't have the public:// stream wrapper.
We can assume that the files need to go in
DRUPAL_ROOT . '/sites/default/files/simpletest/verbose'
and document that if you use something other thansites/default/files
for your public files dir, that verbose logging will just ignore it. I can live with that if you can.The result printer is active for all unit-tests, not just for BTB, so we certainly shouldn't couple it to the settings singleton and the container's site path detection stuff just to get the public stream wrapper absolute path.
Comment #17
dawehnerI'm totally happy with coupling that, but we could introduce another ENV variable, if we really care.
Comment #18
larowlanSure, and without it we could just disable verbose output.
Kind of like the --verbose flag we had for simpletest.
Will work on that front.
Comment #19
dawehner@larowlan++
Comment #20
larowlanAs promised
Before setting the env variable
After
Comment #23
larowlanOh, those bits were in 11, removed
Comment #24
larowlanComment #25
dawehnerThis is lovely!!!!!!!!!!!!
Comment #26
dawehnerTried out the test a bit more:
* It doesn't support phpstorm, sadly. You see
and no URLs appeared. Sadly I have no idea why, but it seems to be
\IDE_Base_PHPUnit_TextUI_Command::handleArguments
is never called.This already is a great step forward so I would say +1 when we agree with the limitations for now and maybe iterate on them later.
Comment #27
larowlanPhpstorm has its own result printer - so I don't think we can have two result printers (ours and theirs)
Comment #28
dawehnerWell, they kinda try to wrap existing ones, but yeah I fear we cannot deal with it.
Comment #29
dawehnerFor now this is a huge improvement, IMHO.
Comment #30
alexpottShouldn't the test id be part of the verbose directory?
Comment #31
dawehnerWhat is the concept of a test ID when you execute stuff via phpunit?
Comment #32
xjmWe discussed this issue today with @alexpott, @effulgentsia, @Cottser, and myself, but didn't come to a clear decision on its status.
So per https://www.drupal.org/core/d8-bc-policy:
In general, I'd consider
BrowserTestBase
to be part of the testing framework, so that would make this an 8.2.x issue at this point since 8.1.x is frozen now and about to be in RC.@alexpott suggested that we should consider BrowserTestBase "experimental", so I suggested it would need to be marked
@internal
or something if that is the case until it is considered stable. That's worth its own issue. I would suggest committing this to 8.2.x though since it is ready (aside from @alexpott's outstanding question in #30 and @dawehner's response in #31).Comment #33
xjmEr, didn't mean to actually tag it for RC target triage at this point.
Comment #34
dawehnerWell, let's ensure that we don't adapt BrowserTestBase from here on.
Comment #35
alexpottI've created #2700975: Remove semver promise from testing API to discuss removing the semver promise from the entire testing API.
Comment #36
xjm@dawehner, "in the minor development branch right now" is very different from "never".
Comment #37
alexpottI've tested this with multiple browser test base tests and it works. I've also opened the outputted html and it works create - it's nice to be able to see the output. Fantastic work.
This is only part that gives me pause. In the 8 dev cycle we had problems with the double meaning of this in WebTestBase. In WebTestBase / run-tests.sh verbose stands before for saving the browser output and also printing verbose result information. I don't think we should repeat that mistake here. I'm not entirely sure of the name we should use but maybe something like
SIMPLETEST_BROWSER_OUTPUT_DIRECTORY
?Comment #38
dawehnerIf we want to bikeshed the name I would argue for not putting SIMPLETEST into it:
BROWSERTEST_OUTPUT_DIRECTORY
. This is indeed a bit more generic and could be useful for other things.Comment #39
alexpott@dawehner I don't want to bikeshed. Verbose is not the right name - this caused problems whilst developing Drupal 8 and I'd like to avoid the same mistakes. Your suggestion makes sense to me.
Comment #40
dawehnerBtw. for me this issue is not that much fundamentally different to #2664150: Expand BrowserTestBase with error handling support
Comment #41
larowlanI agree that
BROWSERTEST_OUTPUT_DIRECTORY
is the best choice.Also, I discovered that locally you can copy phpunit.xml.dist to phpunit.xml and add these variables using the
tag. And then you don't need to remember to define them again.
Discussed making this non BC breaking with xjm. Will record discussion here shortly.
Comment #42
xjmOkay, I discussed this with @larowlan more and I am convinced that this is worth being an RC target, since it is strategically valuable and very low-risk. If it doesn't land before 8.1.0, my earlier concerns still stand. But if possible let's try to get it in now, since this is actually one of our priorities for 8.1.0 as well. Sorry for sidetracking the issue.
Comment #43
larowlanMoves new functionality to DebugBrowserTestBase to maintain BC (no new protected methods) as per discussion with @xjm.
Changes the env variable to be
BROWSERTEST_OUTPUT_DIRECTORY
Includes the test suffix in the file names.
Comment #44
dawehnerMy suggestion would be:
Add
BrowserTestBase
inside\Drupal\Tests
Mark
\Drupal\simpletest\BrowserTestBase
deprecated in favour of the new one.Yeah people don't realize that dist files are meant to be copied :)
Just a process suggestion, swap around the process of #32 and #42.
Comment #45
alexpottLet's also stop using the word verbose in the class - that'll also help with any confusion with run-test.sh --verbose option and and also phpunit's --verbose option.
Also @dawehner's plan is way better than DebugBrowserTestBase.
Comment #46
larowlanDiscussed with @xjm and @alexpott again - now this is rc target we can just modify the existing class, no need for the new one.
So taking patch at #23 and applying #45 and #41
Comment #47
larowlanFixes #23, #45, #41, #30 and #44
Opened #2702281: Move Drupal\simpletest\RandomGeneratorTrait, Drupal\simpletest\WebAssert and Drupal\simpletest\SessionTestTrait into Drupal\Tests namespace for some follow up moves of supporting classes in to Drupal\Tests namespace.
Should be pretty close now
Comment #49
larowlanRe-roll
Comment #50
jibrandocs missing.
We should add this to phpunit.xml.dist
Comment #51
larowlanThank you jibran!
Comment #52
jibranThank you Lee. This is ready imo.
Comment #53
alexpottThis does not work with the phantomjs driver.
$headers here is not an array of arrays.
The above works as expected.
I think we're doing too much here. Firstly deleting stuff if super dangerous. I think we should just check that it is a directory and is writeable - if not then disable browser output and tell the user the directory is not writable. Secondly we should just check for the existence of a .htaccess and if it does not exist then we should write it. Thirdly, however making a sub directory using the test id so tidying up yourself is easy.
Comment #54
alexpottIn fact I'm wondering why we're bothering with a defining a directory and not just making the thing a flag since in order to run these tests you need to be able to install Drupal. We could do the same as WebTestBase and write to a directory inside "/simpletest" maybe "/simpletest/browser_output" or something. That way a user won't make the mistake I made of configuring this outside of web root. It needs to be in webroot so the CSS and JS asset links work. I also think we should output URLs instead of files at the end to make this simple.
Comment #55
alexpottSo now you can type something like
open http://drupal8alt.dev/sites/simpletest/browser_output/Drupal_Tests_simpletest_Functional_BrowserTestBaseTest-40-114002.html
and you'll be able to see the output :)Patch attached:
Comment #56
alexpottUpdated IS for current solution.
Comment #57
larowlanChanges look good to me - thanks @alexpott
Comment #58
jibranCan we at least update
simpletest_script_cleanup
to clean this directory?Comment #59
alexpott@jibran that doesn't clean up sites/default/files/simpletest/verbose so I don't get why it should clean up this.
Comment #60
jibran@alexpott so why not move it to simply change it to
sites/default/files/simpletest/verbose
and remove the constant altogether?Comment #61
larowlan@jibran because we allow public files folder to be configurable.
Yes the default is sites/default/files, but we support alternate locations.
Comment #62
alexpottAlso WebTestBase shouldn't save it's browser output in sites/default/files - that adds an unnecessary dependency on having a installed site. Adding it to sites/simpletest means that all the test files are in the same place. sites/simpletest is where all the test sites are created.
Comment #63
jibranMaybe change that and this to
sites/simpletest/files
Comment #64
alexpottWhat is wrong with calling it what it is? And not making it use a word that means something else elsewhere.
Comment #65
alexpottRerolled for @file changes.
Comment #66
dawehnerSo
sites/simpletest/files/html
would do it for all of you?Comment #67
alexpottI don't think we should create a directory called files in the simpletest directory. Because a files directory in a sites/* directory is very different to this one.
Comment #68
dawehnerOkay so would sites/tests work for you? Just try to figure out what kinda works. In general I agree with not using "simpletest" as much as possible now.
Comment #69
pfrenssensites/tests
sounds great to me. Butsites/simpletest
is OK for me too. We're gradually moving away from the concept of "Simpletest tests", but it is still the "Simpletest module" that provides our test base classes, so in that regard simpletest is not wrong.Comment #70
alexpottAnd the sites are actually installed in sites/simpletest/TEST_ID
I'm all for changing this - but not here.
Comment #71
dawehnerI give a damn about the concrete name.
Comment #74
catchFine with the directory name in the patch.
Committed/pushed to 8.2.x and cherry-picked to 8.1.x. Thanks!
Comment #75
benjy CreditAttribution: benjy at PreviousNext commentedThis broke the output when running tests in phpstorm for me.
EDIT: This was running: MigrateActionConfigsTest
Comment #76
catchRe-opening. If we can fix or diagnose it in the next few hours I'll commit a follow-up, otherwise will roll back especially if there's more reports.
Bumping status so it doesn't get forgotten.
Comment #77
benjy CreditAttribution: benjy at PreviousNext commentedHere's the command PHPStorm executes.
/usr/local/opt/php70/bin/php /private/var/folders/dk/f9s3wd2n04s8z4bd0pflm7yr0000gn/T/ide-phpunit.php --color=always --configuration /Users/benjy/Sites/d8/app/core/phpunit.xml.dist Drupal\Tests\action\Kernel\Migrate\d6\MigrateActionConfigsTest /Users/benjy/Sites/d8/app/core/modules/action/tests/src/Kernel/Migrate/d6/MigrateActionConfigsTest.php
Comment #78
benjy CreditAttribution: benjy at PreviousNext commentedPHPStorm doesn't call the binary directly but generates the ide-phpunit.php file in a temporary space which handles overriding the result printer for PHPStorm. You can't have two result printers so the solution right now is to remove
printerClass="\Drupal\Tests\Listeners\HtmlOutputPrinter"
from your phpunit.xml.dist file.Comment #79
dawehnerWell, there is some code in ide-phpunit.php which tries to wrap an existing printer.
Comment #80
dawehnerDebugged the problem a bit, first I thought the problem is somewhere in phpunit itself, but its IMHO a bug in phpstorm, see https://github.com/sebastianbergmann/phpunit/issues/2141 / https://youtrack.jetbrains.com/issue/WI-24808
One thing I stumbled upon is the concept of listeners. Sadly implementing what we implemented isn't that easy within a listener as the print classes on phpunit are not in its own component, so writing stuff out would not be nice and pretty.
Comment #81
alexpottThis is a PHPStorm bug.
At this point $printer has a value of
\Drupal\Tests\Listeners\HtmlOutputPrinter
so I guess something has changed in PHPUnit since this code was written. Or maybe the latest version of PHPunit do it differently.Regardless - fixing this bug would seem to not be our responsibility. I'll look on phpstorm's bugtracker to see if someone has reported it. Also, at least for me, running BrowserTestBase tests inside PHPStorm is never going to work because my webserver is running as a different user.
Personally I think we should not revert this patch.
Comment #82
alexpottxpost with @dawehner. So yeah there is an existing bug report on PHPStorm and @dawehner has created a patch for them.
I don;t think that running BrowserTestBase tests inside PHPStorm should be our testing target anyway. PHPunit from the command line / run-tests.sh is. Therefore moving this issue back to fixed and resetting the issue metadata.
Comment #83
alexpottAdditionally whilst PHPStorm reports the error it does not actually stop the test from running and any assertions that fail are correctly displayed.
Comment #84
benjy CreditAttribution: benjy at PreviousNext commentedThe output is broken for unit and kernel tests as well though.
Comment #85
alexpottLet's compromise and do #2706113: Disable Drupal\Tests\Listeners\HtmlOutputPrinter by default because PHPStorm is broken and then maybe we can come out with a solution that doesn't break PHPStorm and have it on all the time. But this at least gives people the choice.
Comment #86
nevergone CreditAttribution: nevergone commented#2702661: Make it simple to take screenshots whilst using JavascriptTestBase is resolvable?
Comment #87
alexpott@nevergone yeah that is actually different to this issue - that can take screenshots of the current browser - so you can see exactly what has happened even with javascript.