feat(tests): Browser test helper to get workspace svg root (#8166)

* feat: Add helper to get the svg root of workspace to be clicked on

* feat: Add helper to get the mutator svg root to be clicked on

* fix: fix style format issue
This commit is contained in:
Sampada Bhujel
2024-05-23 20:37:00 +05:45
committed by GitHub
parent d7d5b9af6c
commit 260bc6f678
2 changed files with 33 additions and 4 deletions

View File

@@ -14,7 +14,7 @@ const {
testFileLocations,
dragBlockTypeFromFlyout,
screenDirection,
PAUSE_TIME,
clickWorkspace,
} = require('./test_setup');
const {Key} = require('webdriverio');
@@ -48,9 +48,7 @@ async function testFieldEdits(browser, direction) {
await browser.keys(['1093']);
// Click on the workspace to exit the field editor
const workspace = await browser.$('#blocklyDiv > div > svg.blocklySvg > g');
await workspace.click();
await browser.pause(PAUSE_TIME);
await clickWorkspace(browser);
const fieldValue = await browser.execute((id) => {
return Blockly.getMainWorkspace()

View File

@@ -198,6 +198,35 @@ async function clickBlock(browser, block, clickOptions) {
}, findableId);
}
/**
* Clicks on the svg root of the main workspace.
* @param browser The active WebdriverIO Browser object.
* @return A Promise that resolves when the actions are completed.
*/
async function clickWorkspace(browser) {
const workspace = await browser.$('#blocklyDiv > div > svg.blocklySvg > g');
await workspace.click();
await browser.pause(PAUSE_TIME);
}
/**
* Clicks on the svg root of the first mutator workspace found.
* @param browser The active WebdriverIO Browser object.
* @return A Promise that resolves when the actions are completed.
* @throws If the mutator workspace cannot be found.
*/
async function clickMutatorWorkspace(browser) {
const hasMutator = await browser.$('.blocklyMutatorBackground');
if (!hasMutator) {
throw new Error('No mutator workspace found');
}
const workspace = await browser
.$('.blocklyMutatorBackground')
.closest('g.blocklyWorkspace');
await workspace.click();
await browser.pause(PAUSE_TIME);
}
/**
* @param browser The active WebdriverIO Browser object.
* @param categoryName The name of the toolbox category to find.
@@ -549,6 +578,8 @@ module.exports = {
getSelectedBlockId,
getBlockElementById,
clickBlock,
clickWorkspace,
clickMutatorWorkspace,
getCategory,
getNthBlockOfCategory,
getBlockTypeFromCategory,