Commit 53bdc833 authored by Jérome Perrin's avatar Jérome Perrin

ui_test_core: replace form to update reference snapshot by a download link

In case of snapshot test failure, we generated a form in a data:test/html
link. This was working on chrome at the time, but it no longer work these
days, probably because we switched to Same-Site cookie for authentication.
Anyway, this also had the problem that it's not so convenient to use
when updating the reference from the actual screenshot took from the
test running on test node.

These change this to generate a simple download link, and the workflow to
update reference snapshot becomes to click this link to get the new image,
upload it to development zope instance and re-export the business template.
parent 9a5ed805
Pipeline #20779 failed with stage
in 0 seconds
from StringIO import StringIO
portal = context.getPortalObject()
image_file = StringIO(image_data.replace('data:image/png;base64,', '').decode('base64'))
image_path = [p for p in image_path.split('/') if p]
existing = portal.restrictedTraverse(image_path, None)
if existing is None:
container = portal.restrictedTraverse(image_path[:-1])
container.manage_addProduct['OFSP'].manage_addImage(
image_path[-1],
image_file,
'')
else:
existing.manage_upload(image_file)
return "reference image at {} updated".format('/'.join(image_path))
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>image_data, image_path</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Zuite_updateReferenceImage</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -209,74 +209,6 @@ function generateElement(tagName, childList, attributeDict, textContent) {
return element;
}
/**
* Generate an HTML form to update the reference snapshot
*
* @param {string} referenceImageURL relative URL of the reference image
* @param {string} newImageData the new image data, base64 encoded
* @return {Promise<string>} the base64 encoded html form
*/
function generateUpdateForm(referenceImageURL, newImageData) {
return new Promise((resolve, reject) => {
var fr = new FileReader();
fr.onerror = reject;
fr.onload = () => resolve(fr.result);
fr.readAsDataURL(
new Blob(
[
generateElement('html', [
generateElement('body', [
generateElement('p', [
document.createTextNode('Replacing this old snapshot:'),
generateElement('br'),
generateElement('img', [], {
src: location.origin + referenceImageURL,
alt: 'reference image'
}),
generateElement('br'),
document.createTextNode('with this new snapshot:'),
generateElement('br'),
generateElement('img', [], {
src: newImageData,
alt: 'new image'
})
]),
generateElement(
'form',
[
generateElement('input', [], {
type: 'hidden',
name: 'image_data',
value: newImageData
}),
generateElement('input', [], {
type: 'hidden',
name: 'image_path',
value: referenceImageURL
}),
generateElement('input', [], {
type: 'submit',
value: 'Update Reference Snapshot'
})
],
{
action:
location.origin +
'/' +
referenceImageURL.split('/')[1] + // ERP5 portal
'/Zuite_updateReferenceImage',
method: 'POST'
}
)
])
]).innerHTML
],
{ type: 'text/html' }
)
);
});
}
/**
* verify that the rendering of the element `locator` matches the previously saved reference.
*
......@@ -360,8 +292,6 @@ Selenium.prototype.doVerifyImageMatchSnapshot = (
})
.then(diff => {
if (diff.rawMisMatchPercentage > misMatchToleranceFloat) {
return generateUpdateForm(referenceImageURL, actual).then(
updateReferenceImageForm => {
htmlTestRunner.currentTest.currentRow.trElement
.querySelector('td')
.appendChild(
......@@ -374,22 +304,22 @@ Selenium.prototype.doVerifyImageMatchSnapshot = (
}),
generateElement('br'),
document.createTextNode('Click '),
generateElement(
'a',
[document.createTextNode('here')],
{
href: updateReferenceImageForm
}
),
document.createTextNode(
' to update reference snapshot.'
generateElement('a', [document.createTextNode('here')], {
href: actual,
download: referenceImageURL.split('/').pop(),
}),
document.createTextNode(' to download actual image for '),
generateElement('code', [
generateElement('a', [
document.createTextNode(referenceImageURL),
],
{ href: referenceImageURL + '/manage_main' }
)
])
])
);
throw new Error('Images are ' + diff.misMatchPercentage + '% different');
}
);
}
});
}));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment