As a followup to #3029816: Convert screenshot automation to WebDriverTestBase, in this issue I need to:

Set up for running tests on the DrupalCI test bot. I will need to figure out how to tell the test bot to download MAYO and Admin Toolbar. Plus there are still two core patches that have to be applied to get nice screenshots. All of this is possible -- there is help at
https://www.drupal.org/drupalorg/docs/drupal-ci/customizing-drupalci-tes...

As a note, I think that patches to the testing YAML file don't actually come through and affect tests on DrupalCI, because it's a catch 22 -- that file is used to set up the environment. So, I think I'll need to commit changes to that YAML file rather than using patch testing.

Current status as of comment #21:
- The tests are not running because the screenshots are coming up blank. See comment #18 for a discussion of that.
- If I am able to get the tests running, I need to check on whether the Drupal Core, Mayo theme, and Admin toolbar versions are showing up correctly in screenshots. If not, may need to run a shell command to fix some info.yml files.
- If I am able to get the tests running, I should update the README.txt at the top level of this project and explain where to find the backups and screenshots in the test output.
- Also if I am able to get the tests running, I should update the backups -- see #3035960: Export new database and file backups for all languages

CommentFileSizeAuthor
#2 2905295-work-around.patch523 bytesjhodgdon
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jhodgdon created an issue. See original summary.

jhodgdon’s picture

FileSize
523 bytes

As part of this setup, we will need to apply a patch that gets around issue #2905295: Configuration language being overwritten during module install. Here is the necessary patch (see also the README.txt file in the auto_screenshots directory, which explains this patch).

  • jhodgdon committed 89dcb73 on 8.x-6.x
    Issue #3035963 by jhodgdon: Update testing docs
    

  • jhodgdon committed 3cdbed7 on 8.x-6.x
    Issue #3035963 by jhodgdon: Set up to run tests on DrupalCI
    

  • jhodgdon committed 0895b4f on 8.x-6.x
    Issue #3035963 by jhodgdon: Set up to run tests on DrupalCI
    

  • jhodgdon committed 4920268 on 8.x-6.x
    Issue #3035963 by jhodgdon, Mixologic: Set up to run tests on DrupalCI
    

jhodgdon’s picture

  • jhodgdon committed 00fe94c on 8.x-6.x
    Issue #3035963 by jhodgdon: Set up to run tests on DrupalCI
    

  • jhodgdon committed 40756ee on 8.x-6.x
    Issue #3035963 by jhodgdon: Set up to run tests on DrupalCI
    

  • jhodgdon committed 1145c4a on 8.x-6.x
    Issue #3035963 by jhodgdon: Set up to run tests on DrupalCI
    
jhodgdon’s picture

It looks like what I actually need to do here is move the tests and auto screenshots code to a separate project. DrupalCI seems to have a problem dealing with the User Guide repo, because it is VERY large (with all the images for all the languages). So... I'll be setting that up shortly, and then once that is done, deleting this part of the code from the existing User Guide project and adding a note to the README and to the project page about the separate project just for testing.

jhodgdon’s picture

Project: User Guide » User Guide Tests
Component: Tests » Code

Moving to the new project...

  • jhodgdon committed 5e43a93 on 8.x-6.x
    Issue #3035963 by jhodgdon: Set up to run tests on DrupalCI
    

  • jhodgdon committed ab1cb42 on 8.x-6.x
    Issue #3035963 by jhodgdon: Set up to run tests on DrupalCI
    

  • jhodgdon committed e469d51 on 8.x-6.x
    Issue #3035963 by jhodgdon: Set up to run tests on DrupalCI
    

  • jhodgdon committed d35ed35 on 8.x-6.x
    Issue #3035963 by jhodgdon: Set up to run tests on DrupalCI (reverse...
jhodgdon’s picture

Well, I finally got the environment set up on DrupalCI. But the tests are failing the first time they come to a screenshot. It looks like the image from the chromedriver browser is empty, because when I try to auto-crop it down with
http://us1.php.net/manual/en/function.imagecropauto.php
the return value is a Boolean (false I would assume).

It looks like this is because Chrome is being set up to run in "headless" mode (no UI). And it looks like when it's in headless mode, screenshot images come up blank:
https://stackoverflow.com/questions/52416069/how-to-get-screenshots-from...
https://serverfault.com/questions/856748/selenium-chromedriver-makes-bla...
https://bugs.chromium.org/p/chromium/issues/detail?id=714058

It seems to be a bug in Chrome and/or Chromedriver, because it is supposed to work. And it looks like the bug has been fixed in the dev versions of Chromium, but the fix may not be in the version of Chrome/Chromium that DrupalCI is running.

Someone posted a work-around to unset the "TZ" environment variable before running Chrome, via unset TZ, so I am going to try adding that in.

  • jhodgdon committed 9302f79 on 8.x-6.x
    Issue #3035963 by jhodgdon: Set up to run tests on DrupalCI
    
jhodgdon’s picture

That TZ setting didn't help. I'll have to talk to infra next week.

  • jhodgdon committed 19cbb59 on 8.x-6.x
    Issue #3035963 by jhodgdon: Set up to run tests on DrupalCI (reverse...
jhodgdon’s picture

Updating summary with remaining To Dos if I get the tests running.

jhodgdon’s picture

I created (temporarily) a Drupal Core test to verify that screenshots were not all blank on this related issue. The test passed. So, I am trying to recreate the problem in a new test file in this project...

  • jhodgdon committed 0506573 on 8.x-6.x
    Issue #3035963 by jhodgdon: Set up to run tests on DrupalCI
    
tacituseu’s picture

Tried testing with the same environment that passed on 8.7.x core ? maybe the problem is specific to PHP 7.1 environment ?

jhodgdon’s picture

Good point, I will check on that shortly! Adding a bit to a new test here too... It looks like it is specifically the cropping that is failing. When I test pixels, that works in this environment.

  • jhodgdon committed 4942560 on 8.x-6.x
    Issue #3035963 by jhodgdon: Set up to run tests on DrupalCI
    
jhodgdon’s picture

To clarify:

The test I patched in the drupal core issue took a screenshot and verified it had at least 2 colors in it.

The test I am trying here (in commits on this issue) goes one step further and uses the imagecropauto GD function to crop it down, which is what is currently failing in my (much larger) tests (the ones that work on my home system but not on DrupalCI).

The fail I am seeing here in my latest tests on drupal CI is in the crop step. The part that verifies the colors is working. So, I have added some to the test so that it will also save the uncropped image so I can look at it manually.

jhodgdon’s picture

I should check on PHP 7.2 though, that's a good point. My home system where the tests were working is running PHP 7.2.15.

  • jhodgdon committed a3951e0 on 8.x-6.x
    Issue #3035963 by jhodgdon: Set up to run tests on DrupalCI
    
jhodgdon’s picture

Sigh. I really don't know what is going on.

In my latest test, I saved the image to a file before it was cropped. The image looks fine:
https://dispatcher.drupalci.org/job/drupal_contrib/339932/artifact/jenki...

Then just after saving that image, I do in my test

    $cropped = imagecropauto($image, IMG_CROP_SIDES);
    $this->assertTrue($cropped !== FALSE, 'Image crop succeeded');

That fails. However, I tried these commands at home in php -- interactive:

$image = imagecreatefrompng('test-screenshot-before-crop.png');
$cropped = imagecropauto($image, IMG_CROP_SIDES);
if ($cropped !== FALSE) { print "full image"; } else { print "empty image"; }
print imagesx($cropped);

This prints out "full image" and a 650 pixels width. So, imagecropauto is working fine on my local system, at least after importing the saved image file, but it is failing on the bot.

I have now also tested this in both PHP 7.1 and 7.2, and it behaves the same.

tacituseu’s picture

imagecropauto bug then ? Tried this suggestion ?
Edit: Environments are a bit stale (PHP 7.2.8), checking changelog.

tacituseu’s picture

Possibly:
- https://bugs.php.net/77198 auto cropping has insufficient precision
- https://bugs.php.net/77200 imagecropauto(…, GD_CROP_SIDES) crops left but not right
the PHP 7.2.x-dev & MySQL 5.5 environment looks fresh (PHP 7.2.17-dev (cli) (built: Mar 2 2019 18:17:12) ( NTS )), maybe worth giving it a try ?

jhodgdon’s picture

I am trying to do IMAGE_CROP_SIDES, and that is failing in my pared-down test... although I could try the THRESHOLD function and just crop white, which is probably what I need in 99% of the images anyway.

In the cases in #33, the problem there is that not enough of the image is cropped, not that the whole thing is cropped.

But yeah I'll try the threshold crop and see if that works. Good idea!

  • jhodgdon committed 93ce116 on 8.x-6.x
    Issue #3035963 by jhodgdon: Set up to run tests on DrupalCI
    
jhodgdon’s picture

I played around with the threshold cropping on my local PHP install, and it looks like this line works the closest to the (working for me) IMG_CROP_SIDES:

    $cropped = imagecropauto($image, IMG_CROP_THRESHOLD, 5, 0xFFFFFF);

So that last commit tries that in my DrupalScreenshotTest. Should have a result in a little while...

Thanks for the suggestions @tacituseu

  • jhodgdon committed 5b861fa on 8.x-6.x
    Issue #3035963 by jhodgdon: Update instructions for finding test output
    

  • jhodgdon committed a69b45a on 8.x-6.x
    Issue #3035963 by jhodgdon: Remove non-working cropping so the tests...
jhodgdon’s picture

Sigh. The IMG_CROP_THRESHOLD change did not fix the problem either. The cropping still fails on DrupalCI.

So, I think I just have to not do the cropping. It's not terrible -- I can crop the images at the command line afterwards with a simple shell script.

  • jhodgdon committed b41ea42 on 8.x-6.x
    Issue #3035963 by jhodgdon: Refactor not cropping to a member variable
    
tacituseu’s picture

I tried it on old 7.0.22 I had around on the exact same .png and it failed too (returned false after the imagecropauto), then on 7.0.33 and it worked, try PHP 7.2.x-dev environment if it's available for projects as the other ones are old.
The bugs show that the function has been reworked recently, so even if the bug reports weren't exactly about this issue, it might have been fixed by the changes too.

Edit: used this snippet:

$image = imagecreatefrompng('https://dispatcher.drupalci.org/job/drupal_contrib/339932/artifact/jenkins-drupal_contrib-339932/artifacts/run_tests.js/simpletest_html/test-screenshot-before-crop.png');
$xsize = imagesx($image);
$ysize = imagesy($image);
var_dump($image);
var_dump($xsize);
var_dump($ysize);
$cropped = imagecropauto($image, IMG_CROP_SIDES);
var_dump($cropped);
$xsize = imagesx($cropped);
$ysize = imagesy($cropped);
var_dump($xsize);
var_dump($ysize);

  • jhodgdon committed 87d2af8 on 8.x-6.x
    Issue #3035963 by jhodgdon: Turn on cropping for DrupalScreenshotTest
    
  • jhodgdon committed bcfb802 on 8.x-6.x
    Issue #3035963 by jhodgdon: Fix test fails
    

  • jhodgdon committed 7bdbd2a on 8.x-6.x
    Issue #3035963 by jhodgdon: Turn cropping back off for...
jhodgdon’s picture

I just turned on cropping again in my short test, and it even failed on PHP 7.3.x-dev. So, I think it is just too problematic.

  • jhodgdon committed d447b74 on 8.x-6.x
    Issue #3035963 by jhodgdon: Try to fix test fails
    

  • jhodgdon committed 9b01dfd on 8.x-6.x
    Issue #3035963 by jhodgdon: Try to fix test fails
    
jhodgdon’s picture

OK, now that I am not trying to crop images, I have a new problem with some of the tests. Again, this works locally but not on DrupalCI.

The test is attempting, at several points, to submit an image file to an image file field on a node/add page.

Earlier in the test, I have verified that the file exists and is readable -- at least, it is readable by the web server user:

    $this->assetsDirectory = drupal_get_path('module', 'user_guide_tests') . '/assets/';
    $this->assertTrue(is_readable(DRUPAL_ROOT . '/' . $this->assetsDirectory . 'farm.jpg'), 'Farm asset file exists and is readable');

But the test is failing on this line later on, when trying to upload that exact same file:

    $this->drupalPostForm(NULL, [
        'title[0][value]' => $this->demoInput['vendor_1_title'],
        'files[field_' . $main_image . '_0]' => DRUPAL_ROOT . '/' . $this->assetsDirectory . 'farm.jpg',
        'path[0][alias]' => $this->demoInput['vendor_1_path'],
        'field_' . $vendor_url . '[0][uri]' => $this->demoInput['vendor_1_url'],
      ], $this->callT('Save'));

with this message and call stack:

Exception: invalid argument: File not found : /var/www/html/modules/contrib/user_guide_tests/assets/farm.jpg

/var/www/html/vendor/instaclick/php-webdriver/lib/WebDriver/Exception.php:144
/var/www/html/vendor/instaclick/php-webdriver/lib/WebDriver/AbstractWebDriver.php:157
/var/www/html/vendor/instaclick/php-webdriver/lib/WebDriver/AbstractWebDriver.php:218
/var/www/html/vendor/instaclick/php-webdriver/lib/WebDriver/Container.php:224
/var/www/html/vendor/behat/mink-selenium2-driver/src/Selenium2Driver.php:670
/var/www/html/vendor/behat/mink/src/Element/NodeElement.php:105
/var/www/html/core/tests/Drupal/Tests/UiHelperTrait.php:95
/var/www/html/core/tests/Drupal/Tests/UiHelperTrait.php:209
/var/www/html/modules/contrib/user_guide_tests/tests/src/FunctionalJavascript/UserGuideDemoTestBase.php:3643
/var/www/html/modules/contrib/user_guide_tests/tests/src/FunctionalJavascript/UserGuideDemoTestBase.php:1127
/var/www/html/modules/contrib/user_guide_tests/tests/src/FunctionalJavascript/UserGuideDemoTestBase.php:316

So, apparently the file or directory is not readable by the chromedriver.

  • jhodgdon committed c880944 on 8.x-6.x
    Issue #3035963 by jhodgdon, lendude: Try to fix test fails - file upload...

jhodgdon credited Lendude.

jhodgdon’s picture

@lendude helped me out in Slack with this. Apparently in WebDriverTestBase, when running on DrupalCI, you cannot post forms with images. You need to use attachFileToField() instead. So... a new commit for that.

tacituseu’s picture

Not sure if known, but while trying to figure out what's with the cropping, noticed those in test.apache.error.log:

[Mon Mar 04 18:13:33.236507 2019] [php7:notice] [pid 18] [client 172.18.0.2:49252] Uncaught PHP Exception Drupal\\Core\\Extension\\Exception\\UnknownExtensionException: "The module screenshot_alters does not exist." at /var/www/html/core/lib/Drupal/Core/Extension/ExtensionList.php line 522, referer: http://php-apache-jenkins-drupal-contrib-340409/subdirectory/admin/modules

  • jhodgdon committed 1991e35 on 8.x-6.x
    Issue #3035963 by jhodgdon, lendude: Try to fix test fails - file upload...

  • jhodgdon committed 0d24097 on 8.x-6.x
    Issue #3035963 by jhodgdon, tacituseu -- fix screenshot_alters reference...
jhodgdon’s picture

Thanks! I doubt that is the problem but I have just fixed it. That was left over from when this test had a different directory structure.

  • jhodgdon committed 6b87764 on 8.x-6.x
    Issue #3035963 by jhodgdon: Try to fix test fails - ajax on view wizard...

  • jhodgdon committed ba3f0e3 on 8.x-6.x
    Issue #3035963 by jhodgdon: update the cropping script
    
jhodgdon’s picture

Making progress! The next problem I've encountered is that in one part of the test, we go to the Available Updates page to see what updates are available. When running the tests in person, the environment set up (pre-using-composer) had you download a not-quite-current version of a contrib module and a contrib theme, so that there would be something on this page.

The current setup is using Composer to download these by putting explicit versions in the composer.json file, but they are not showing up on Available Updates. Having run the same composer commands on my local system, I can see that the correct versions are being downloaded from Git anyway. Also, you can see it in the build artifacts for the test run:

Package operations: 3 installs, 0 updates, 0 removals
  - Installing drupal/admin_toolbar (1.25.0): Cloning 8.x-1.25
> Drupal\Core\Composer\Composer::vendorTestCodeCleanup
  - Installing drupal/mayo (1.2.0): Cloning 8.x-1.2

However, I can see on my local system that the info.yml files for Mayo and Admin Toolbar don't have the versions in them (they would be in there if you downloaded the tar file but not via Git), and I can see from the screenshots in the test output that the Mayo theme is showing up on the Appearance page as being version 8.6.10 (the same as the version of Core I am using). It looks like when Drupal parses .info files, it will put in whatever is in core/lib/Drupal.php in the VERSION constant as a default (which is the core version).

So I think I just need to add two lines to my build to put the versions into the info.yml files for Mayo and Admin Toolbar. Should be easy enough...

  • jhodgdon committed 47dfe99 on 8.x-6.x
    Issue #3035963 by jhodgdon: Try to fix test fails - add versions to...

  • jhodgdon committed 2298026 on 8.x-6.x
    Issue #3035963 by jhodgdon: Try to fix test fails - fix syntax
    
jhodgdon’s picture

There has been a problem in some languages early in the test with the node/add/page testing. This turned out to be a Core bug:
#3037729: Duplicate filter format weights (turns off CKEditor by default in some languages)
which I patched, so adding this patch to the drupalci.yml file.

Also there is still a problem in the updates report that I cannot reproduce locally. Trying a work-around...

  • jhodgdon committed 588f725 on 8.x-6.x
    Issue #3035963 by jhodgdon: Try to fix test fails - updates page and...

  • jhodgdon committed eb5be80 on 8.x-6.x
    Issue #3035963 by jhodgdon: Try to fix test fails
    

  • jhodgdon committed f9b40de on 8.x-6.x
    Issue #3035963 by jhodgdon: Try to fix test fails
    

  • jhodgdon committed d8aa7ac on 8.x-6.x
    Issue #3035963 by jhodgdon: Try to fix test fails
    

  • jhodgdon committed 208c12b on 8.x-6.x
    Issue #3035963 by jhodgdon: Try to fix test fails about update status
    
jhodgdon’s picture

Status: Active » Fixed

Woot! The tests finally all passed! I fixed the problem with the update report by adding to the info.yml files for the contrib theme/module, so they look like what you get when you download a tar.gz file of a release (i.e, added the project, version, and timestamp lines) -- this allowed the Update module to get correct update information.

So, I'm now going over to #3035960: Export new database and file backups for all languages to update the screenshots (as needed) and backups.

Thanks again to @tacituseu, @Mixologic, and @Lendude for all of your help, on this issue and in Slack!

tacituseu’s picture

jhodgdon’s picture

Yeah, I've filed an issue in Mayo about a config problem as well -- could be a duplicate?
#2790873: Missing schema
Oh, both are by me. :)

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.