mirror of
https://github.com/google/blockly.git
synced 2026-01-07 00:50:27 +01:00
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:
@@ -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()
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user