Skip to content

Commit

Permalink
fix: webView findWebElement returning undefined (#1485)
Browse files Browse the repository at this point in the history
Signed-off-by: Dominik Jelinek <[email protected]>
  • Loading branch information
djelinek authored Aug 19, 2024
1 parent f366c33 commit ebc50cc
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 9 deletions.
26 changes: 26 additions & 0 deletions packages/locators/lib/1.90.0.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License", destination); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { By, LocatorDiff } from '@redhat-developer/page-objects';

export const diff: LocatorDiff = {
locators: {
WebviewView: {
iframe: By.xpath(`//div[not(@data-parent-flow-to-element-id)]/iframe[@class='webview ready']`),
},
},
};
9 changes: 8 additions & 1 deletion tests/test-project/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export function activate(context: vscode.ExtensionContext) {
}),
);
context.subscriptions.push(vscode.window.registerWebviewViewProvider('myPanelView', new MyPanelView()));
context.subscriptions.push(vscode.window.registerWebviewViewProvider('mySidePanelView', new MyPanelView()));
context.subscriptions.push(vscode.window.registerWebviewViewProvider('mySidePanelView', new MySidePanelView()));

vscode.commands.registerCommand('extension.treeItemAction', async () => {});
}
Expand Down Expand Up @@ -171,3 +171,10 @@ class MyPanelView implements vscode.WebviewViewProvider {
'<!DOCTYPE html><html><head><title>My Panel View</title></head><body><div><h1>Shopping List</h1><ul><li>Apple</li><li>Banana</li></ul></div></body></html>';
}
}

class MySidePanelView implements vscode.WebviewViewProvider {
resolveWebviewView(webviewView: vscode.WebviewView): void | Thenable<void> {
webviewView.webview.html =
'<!DOCTYPE html><html><head><title>My Side Panel View</title></head><body><div><h1>Shopping Side List</h1><ul><li>Side Apple</li><li>Side Banana</li></ul></div></body></html>';
}
}
4 changes: 0 additions & 4 deletions tests/test-project/src/test/webview/webView.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,6 @@ describe('WebViews', function () {
tabs = await new EditorView().getOpenEditorTitles();
});

after(async function () {
await new EditorView().closeAllEditors();
});

describe('First WebView', function () {
before(async function () {
await new EditorView().openEditor(tabs[0]);
Expand Down
18 changes: 14 additions & 4 deletions tests/test-project/src/test/webview/webviewView.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/

import { expect } from 'chai';
import { BottomBarPanel, By, CustomTreeSection, SideBarView, VSBrowser, WebviewView, Workbench } from 'vscode-extension-tester';
import { BottomBarPanel, By, CustomTreeSection, EditorView, SideBarView, VSBrowser, WebviewView, Workbench } from 'vscode-extension-tester';

describe('WebviewViews', function () {
const params = [
Expand All @@ -25,15 +25,25 @@ describe('WebviewViews', function () {
command: 'My Panel: Focus on My Panel View View',
closePanel: true,
closeSection: false,
h1: 'Shopping List',
li0: 'Apple',
li1: 'Banana',
},
{
title: 'SideBar',
command: 'Explorer: Focus on My Side Panel View View',
closePanel: false,
closeSection: true,
h1: 'Shopping Side List',
li0: 'Side Apple',
li1: 'Side Banana',
},
];

after(async function () {
await new EditorView().closeAllEditors();
});

params.forEach(function (param) {
describe(`${param.title} WebviewViews`, function () {
let webviewView: InstanceType<typeof WebviewView>;
Expand Down Expand Up @@ -76,7 +86,7 @@ describe('WebviewViews', function () {

it('findWebElement works', async function () {
const element = await webviewView.findWebElement(By.css('h1'));
expect(await element.getText()).has.string('Shopping List');
expect(await element.getText()).has.string(param.h1);
});

it('findWebElements works', async function () {
Expand All @@ -93,8 +103,8 @@ describe('WebviewViews', function () {
}),
);
expect(listContent).to.have.length(2);
expect(listContent).to.contain('Apple');
expect(listContent).to.contain('Banana');
expect(listContent).to.contain(param.li0);
expect(listContent).to.contain(param.li1);
});
});
});
Expand Down

0 comments on commit ebc50cc

Please sign in to comment.