Test sulle immagini
Giorgio Sironi
Collaudare!
We need it, to "be Agile". But if you don't know how to write a certain category of tests, you're out of luck. You will avoid those tests.
Also, the kind of tests gives you no feedback on the quality of your design. This it not for TDD.
Fotografare
Selenium 2 JSON Wire Protocol
GET /session/:sessionId/screenshot
(PNG blob encoded in base64)
Selenium 2 allows you to use a REST-like API to startup browsers and using them not only to navigate but also to take screenshots.
Su browser multipli
array(
'browserName' => 'internet explorer',
'host' => SAUCE_HOST,
'port' => 4444,
'desiredCapabilities' => array(
'platform' => 'Windows 2008',
'version' => '9'
),
),
SauceLabs runs the infrastructure: provides a set of virtual machines for each operating system, browser and version.
Il riferimento
STORE_SCREENSHOTS=1 phpunit \
> spec/crossbrowser/PaymentPageDesktopTest.php
Running the tests with a special environment variable triggers the Storage Strategy instead of the Analysis one.
Confronto
$ phpunit spec/crossbrowser/PaymentPageDesktopTest.php
// under the covers:
$ convert screenshot.png screenshot.pnm
$ imgcmp -f reference.pnm -F screenshot.png -m mae \
> | paste -sd+ | bc
1.025523
// threshold can be as low as 0.0001
$ compare reference.png screenshot.png difference.png
Running the tests without any configuration generates a screenshot and compares it with the reference via Mean Average Error
(Android color rendering is an example of how the comparison cannot be exact. Byte contents in the PNG such as image metadata too
Risultati
Riferimento, generato, differenza dopo il fallimento
Conclusioni
Un test, tanti browser
Open source rende questo possibile
Test robusti richiedono lavoro
Thanks
Che assert() sia con voi