felvieira
6/12/2018 - 7:56 PM

Script para Chromy mockando keyboardEvent no BackstopJS

Fazer o textarea pegar o keyup ao mockar um keyboardEvent

module.exports = function (chromy, scenario, vp) {
	var dropdownSelector = scenario.dropdownSelector;
	var dropdownSelectorClick = scenario.dropdownSelectorClick;
	var stillDoubtsButton = scenario.stillDoubtsButton;
	var textarea = scenario.textarea;

	chromy
		.wait(500)
		.click(dropdownSelector)
		.wait(dropdownSelectorClick)
		.click(dropdownSelectorClick)
		.wait(stillDoubtsButton)
		.click(stillDoubtsButton)
		.wait(500)
		.type(textarea, "a")
		.evaluate(() => {
			let KeyboardEvent = window.KeyboardEvent;
			let textareas = document.querySelector("textarea#enviar-email-description");
			var e = new KeyboardEvent("keyup", {
				bubbles: true,
				cancelable: true,
				char: "Q",
				key: "q",
				shiftKey: true,
				keyCode: 81
			});
			textareas.dispatchEvent(e);
		})
		.wait(500)
};
{
			"label": "Enviar e-mail - Warning Validação",
			"url": "http://localhost:3001/email-central-atendimento",
			"delay": 500,
			"selectors": [
				"document"
			],
			"dropdownSelector": ".dropdown-filter__text",
			"dropdownSelectorClick": ".dropdown-filter__item",
			"stillDoubtsButton": "a#button-doubts",
			"textarea": "textarea#enviar-email-description",
			"selectorExpansion": true,
			"misMatchThreshold": 0.1,
			"onReadyScript": "chromy/enviarEmailWarning.js",
			"requireSameDimensions": true
		}