feat(test): add helper functions for getting selected block and block… (#7254)

* feat(test): add helper functions for getting selected block and block by ID

* chore: format test files

* chore: fix lint
This commit is contained in:
Rachel Fenichel
2023-07-06 10:30:53 -07:00
committed by GitHub
parent a677355f73
commit f1e0e11312
2 changed files with 38 additions and 11 deletions

View File

@@ -73,4 +73,32 @@ const testFileLocations = {
playground: 2,
};
module.exports = {testSetup, testFileLocations};
/**
* @param {Browser} browser The active WebdriverIO Browser object.
* @return {WebElement} The selected block's root SVG element, as an interactable
* browser element.
*/
async function getSelectedBlockElement(browser) {
const result = await browser.execute(() => {
// Note: selected is an ICopyable and I am assuming that it is a BlockSvg.
return Blockly.common.getSelected()?.id;
});
return await browser.$(`[data-id="${result}"]`);
}
/**
* @param {Browser} browser The active WebdriverIO Browser object.
* @param {string} id The ID of the Blockly block to search for.
* @return {WebElement} The root SVG element of the block with the given ID, as an
* interactable browser element.
*/
async function getBlockElementById(browser, id) {
return await browser.$(`[data-id="${id}"]`);
}
module.exports = {
testSetup,
testFileLocations,
getSelectedBlockElement,
getBlockElementById,
};