mirror of
https://github.com/google/blockly.git
synced 2026-01-04 15:40:08 +01:00
Work on fixing more browser tests
This commit is contained in:
@@ -194,7 +194,8 @@ suite('Delete blocks', function (done) {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Redo block deletion', async function () {
|
// TODO(#9029) enable this test once deleting a block doesn't lose focus
|
||||||
|
test.skip('Redo block deletion', async function () {
|
||||||
const before = (await getAllBlocks(this.browser)).length;
|
const before = (await getAllBlocks(this.browser)).length;
|
||||||
// Get first print block, click to select it, and delete it using backspace key.
|
// Get first print block, click to select it, and delete it using backspace key.
|
||||||
await clickBlock(this.browser, this.firstBlock.id, {button: 1});
|
await clickBlock(this.browser, this.firstBlock.id, {button: 1});
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import * as chai from 'chai';
|
|||||||
import {
|
import {
|
||||||
connect,
|
connect,
|
||||||
getBlockTypeFromCategory,
|
getBlockTypeFromCategory,
|
||||||
|
getDraggableBlockElementByType,
|
||||||
getNthBlockOfCategory,
|
getNthBlockOfCategory,
|
||||||
getSelectedBlockElement,
|
getSelectedBlockElement,
|
||||||
PAUSE_TIME,
|
PAUSE_TIME,
|
||||||
@@ -31,9 +32,10 @@ suite('Testing Connecting Blocks', function (done) {
|
|||||||
this.browser.on('dialog', (dialog) => {});
|
this.browser.on('dialog', (dialog) => {});
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Testing Procedure', async function () {
|
test.only('Testing Procedure', async function () {
|
||||||
|
|
||||||
// Drag out first function
|
// Drag out first function
|
||||||
let proceduresDefReturn = await getBlockTypeFromCategory(
|
let proceduresDefReturn = await getDraggableBlockElementByType(
|
||||||
this.browser,
|
this.browser,
|
||||||
'Functions',
|
'Functions',
|
||||||
'procedures_defreturn',
|
'procedures_defreturn',
|
||||||
@@ -42,12 +44,12 @@ suite('Testing Connecting Blocks', function (done) {
|
|||||||
const doSomething = await getSelectedBlockElement(this.browser);
|
const doSomething = await getSelectedBlockElement(this.browser);
|
||||||
|
|
||||||
// Drag out second function.
|
// Drag out second function.
|
||||||
proceduresDefReturn = await getBlockTypeFromCategory(
|
proceduresDefReturn = await getDraggableBlockElementByType(
|
||||||
this.browser,
|
this.browser,
|
||||||
'Functions',
|
'Functions',
|
||||||
'procedures_defreturn',
|
'procedures_defreturn',
|
||||||
);
|
);
|
||||||
await proceduresDefReturn.dragAndDrop({x: 300, y: 200});
|
await proceduresDefReturn.dragAndDrop({x: 50, y: 20});
|
||||||
const doSomething2 = await getSelectedBlockElement(this.browser);
|
const doSomething2 = await getSelectedBlockElement(this.browser);
|
||||||
|
|
||||||
// Drag out numeric
|
// Drag out numeric
|
||||||
@@ -86,7 +88,7 @@ suite('Testing Connecting Blocks', function (done) {
|
|||||||
'Text',
|
'Text',
|
||||||
'text_print',
|
'text_print',
|
||||||
);
|
);
|
||||||
await printFlyout.dragAndDrop({x: 50, y: 20});
|
await printFlyout.dragAndDrop({x: 50, y: 0});
|
||||||
const print = await getSelectedBlockElement(this.browser);
|
const print = await getSelectedBlockElement(this.browser);
|
||||||
|
|
||||||
// Drag out doSomething2 caller from flyout.
|
// Drag out doSomething2 caller from flyout.
|
||||||
@@ -95,7 +97,7 @@ suite('Testing Connecting Blocks', function (done) {
|
|||||||
'Functions',
|
'Functions',
|
||||||
4,
|
4,
|
||||||
);
|
);
|
||||||
await doSomething2Flyout.dragAndDrop({x: 130, y: 20});
|
await doSomething2Flyout.dragAndDrop({x: 50, y: 20});
|
||||||
const doSomething2Caller = await getSelectedBlockElement(this.browser);
|
const doSomething2Caller = await getSelectedBlockElement(this.browser);
|
||||||
|
|
||||||
// Connect doSomething2 caller with print.
|
// Connect doSomething2 caller with print.
|
||||||
|
|||||||
@@ -286,6 +286,7 @@ export async function getBlockTypeFromCategory(
|
|||||||
await category.click();
|
await category.click();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await browser.pause(PAUSE_TIME);
|
||||||
const id = await browser.execute((blockType) => {
|
const id = await browser.execute((blockType) => {
|
||||||
return Blockly.getMainWorkspace()
|
return Blockly.getMainWorkspace()
|
||||||
.getFlyout()
|
.getFlyout()
|
||||||
@@ -295,6 +296,55 @@ export async function getBlockTypeFromCategory(
|
|||||||
return getBlockElementById(browser, id);
|
return getBlockElementById(browser, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param browser The active WebdriverIO Browser object.
|
||||||
|
* @param categoryName The name of the toolbox category to search.
|
||||||
|
* Null if the toolbox has no categories (simple).
|
||||||
|
* @param blockType The type of the block to search for.
|
||||||
|
* @return A Promise that resolves to a reasonable drag target element of the
|
||||||
|
* first block with the given type in the given category.
|
||||||
|
*/
|
||||||
|
export async function getDraggableBlockElementByType(
|
||||||
|
browser,
|
||||||
|
categoryName,
|
||||||
|
blockType,
|
||||||
|
) {
|
||||||
|
if (categoryName) {
|
||||||
|
const category = await getCategory(browser, categoryName);
|
||||||
|
await category.click();
|
||||||
|
}
|
||||||
|
|
||||||
|
const findableId = 'dragTargetElement';
|
||||||
|
// In the browser context, find the element that we want and give it a findable ID.
|
||||||
|
await browser.execute(
|
||||||
|
(blockType, newElemId) => {
|
||||||
|
const block = Blockly.getMainWorkspace()
|
||||||
|
.getFlyout()
|
||||||
|
.getWorkspace()
|
||||||
|
.getBlocksByType(blockType)[0];
|
||||||
|
if (!block.isCollapsed()) {
|
||||||
|
for (const input of block.inputList) {
|
||||||
|
for (const field of input.fieldRow) {
|
||||||
|
if (field instanceof Blockly.FieldLabel) {
|
||||||
|
const svgRoot = field.getSvgRoot();
|
||||||
|
if (svgRoot) {
|
||||||
|
svgRoot.id = newElemId;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// No label field found. Fall back to the block's SVG root.
|
||||||
|
block.getSvgRoot().id = newElemId;
|
||||||
|
},
|
||||||
|
blockType,
|
||||||
|
findableId,
|
||||||
|
);
|
||||||
|
// In the test context, get the Webdriverio Element that we've identified.
|
||||||
|
return await browser.$(`#${findableId}`);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param browser The active WebdriverIO Browser object.
|
* @param browser The active WebdriverIO Browser object.
|
||||||
* @param blockType The type of the block to search for in the workspace.
|
* @param blockType The type of the block to search for in the workspace.
|
||||||
|
|||||||
Reference in New Issue
Block a user